1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright Epic Games, Inc. All Rights Reserved.
#include "trace_cmd.h"
#include <zencore/logging.h>
#include <zenhttp/httpclient.h>
#include <zenhttp/httpcommon.h>
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(""), "<hosturl>");
m_Options.add_option("", "s", "stop", "Stop tracing", cxxopts::value(m_Stop)->default_value("false"), "<stop>");
m_Options.add_option("", "", "host", "Start tracing to host", cxxopts::value(m_TraceHost), "<hostip>");
m_Options.add_option("", "", "file", "Start tracing to file", cxxopts::value(m_TraceFile), "<filepath>");
}
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
|