// Copyright Epic Games, Inc. All Rights Reserved. #include "trace_cmd.h" #include #include #include using namespace std::literals; namespace zen { TraceCommand::TraceCommand() { m_Options.add_options()("h,help", "Print help"); m_Options.add_option("", "u", "hosturl", kHostUrlHelp, cxxopts::value(m_HostName)->default_value(""), ""); m_Options.add_option("", "s", "stop", "Stop tracing", cxxopts::value(m_Stop)->default_value("false"), ""); m_Options.add_option("", "", "host", "Start tracing to host", cxxopts::value(m_TraceHost), ""); m_Options.add_option("", "", "file", "Start tracing to file", cxxopts::value(m_TraceFile), ""); } TraceCommand::~TraceCommand() = default; void TraceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) { ZEN_UNUSED(GlobalOptions); if (!ParseOptions(argc, argv)) { return; } m_HostName = ResolveTargetHostSpec(m_HostName); if (m_HostName.empty()) { throw OptionParseException("Unable to resolve server specification", m_Options.help()); } zen::HttpClient Http = CreateHttpClient(m_HostName); if (m_Stop) { if (zen::HttpClient::Response Response = Http.Post("/admin/trace/stop"sv)) { ZEN_CONSOLE("OK: {}", Response.ToText()); } else { Response.ThrowError("Trace stop failed"); } return; } std::string StartArg; if (!m_TraceHost.empty()) { StartArg = fmt::format("host={}", m_TraceHost); } else if (!m_TraceFile.empty()) { StartArg = fmt::format("file={}", m_TraceFile); } if (!StartArg.empty()) { if (zen::HttpClient::Response Response = Http.Post(fmt::format("/admin/trace/start?{}"sv, StartArg))) { ZEN_CONSOLE("OK: {}", Response.ToText()); } else { Response.ThrowError("Trace start failed"); } } else { if (zen::HttpClient::Response Response = Http.Get("/admin/trace"sv)) { ZEN_CONSOLE("OK: {}", Response.ToText()); } else { Response.ThrowError("Trace status failed"); } } } } // namespace zen