diff options
Diffstat (limited to 'src/zenserver')
| -rw-r--r-- | src/zenserver/admin/admin.cpp | 34 | ||||
| -rw-r--r-- | src/zenserver/config.cpp | 24 | ||||
| -rw-r--r-- | src/zenserver/config.h | 6 | ||||
| -rw-r--r-- | src/zenserver/frontend/frontend.cpp | 2 | ||||
| -rw-r--r-- | src/zenserver/main.cpp | 36 | ||||
| -rw-r--r-- | src/zenserver/objectstore/objectstore.cpp | 3 | ||||
| -rw-r--r-- | src/zenserver/stats/statsreporter.cpp | 2 | ||||
| -rw-r--r-- | src/zenserver/zenserver.cpp | 15 |
8 files changed, 73 insertions, 49 deletions
diff --git a/src/zenserver/admin/admin.cpp b/src/zenserver/admin/admin.cpp index 8c2e6d771..f6ad14422 100644 --- a/src/zenserver/admin/admin.cpp +++ b/src/zenserver/admin/admin.cpp @@ -594,31 +594,35 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, [this](HttpRouterRequest& Req) { HttpServerRequest& HttpReq = Req.ServerRequest(); const HttpServerRequest::QueryParams Params = HttpReq.GetQueryParams(); - TraceType Type = TraceType::None; - std::string HostOrPath; - if (auto Param = Params.GetValue("file"); Param.empty() == false) + TraceOptions TraceOptions; + + if (!IsTracing()) { - Type = TraceType::File; - HostOrPath = Param; + TraceInit("zenserver"); } - if (auto Param = Params.GetValue("host"); Param.empty() == false) + + if (auto Channels = Params.GetValue("channels"); Channels.empty() == false) { - Type = TraceType::Network; - HostOrPath = Param; + TraceOptions.Channels = Channels; } - if (Type == TraceType::None) + + if (auto File = Params.GetValue("file"); File.empty() == false) { - return Req.ServerRequest().WriteResponse(HttpResponseCode::BadRequest, - HttpContentType::kText, - "Invalid trace type, use `file` or `host`"sv); + TraceOptions.File = File; } - if (IsTracing()) + else if (auto Host = Params.GetValue("host"); Host.empty() == false) + { + TraceOptions.Host = Host; + } + else { return Req.ServerRequest().WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, - "Tracing is already enabled"sv); + "Invalid trace type, use `file` or `host`"sv); } - TraceStart("zenserver", HostOrPath.c_str(), Type); + + TraceConfigure(TraceOptions); + return Req.ServerRequest().WriteResponse(HttpResponseCode::OK, HttpContentType::kText, "Tracing started"); }, HttpVerb::kPost); diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp index 23bb3ad78..4049ae815 100644 --- a/src/zenserver/config.cpp +++ b/src/zenserver/config.cpp @@ -461,6 +461,8 @@ ParseConfigFile(const std::filesystem::path& Path, const cxxopts::ParseResult& CmdLineResult, std::string_view OutputConfigFile) { + ZEN_TRACE_CPU("ParseConfigFile"); + using namespace std::literals; LuaConfig::Options LuaOptions; @@ -508,8 +510,9 @@ ParseConfigFile(const std::filesystem::path& Path, #if ZEN_WITH_TRACE ////// trace - LuaOptions.AddOption("trace.host"sv, ServerOptions.TraceHost, "tracehost"sv); - LuaOptions.AddOption("trace.file"sv, ServerOptions.TraceFile, "tracefile"sv); + LuaOptions.AddOption("trace.channels"sv, ServerOptions.TraceOptions.Channels, "trace"sv); + LuaOptions.AddOption("trace.host"sv, ServerOptions.TraceOptions.Host, "tracehost"sv); + LuaOptions.AddOption("trace.file"sv, ServerOptions.TraceOptions.File, "tracefile"sv); #endif ////// stats @@ -924,25 +927,28 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) "<httpsys request logging>"); #if ZEN_WITH_TRACE + // We only have this in options for command line help purposes - we parse these argument separately earlier using + // GetTraceOptionsFromCommandline() + options.add_option("ue-trace", "", "trace", "Specify which trace channels should be enabled", - cxxopts::value<std::string>(ServerOptions.TraceChannels)->default_value(""), + cxxopts::value<std::string>(ServerOptions.TraceOptions.Channels)->default_value(""), ""); options.add_option("ue-trace", "", "tracehost", "Hostname to send the trace to", - cxxopts::value<std::string>(ServerOptions.TraceHost)->default_value(""), + cxxopts::value<std::string>(ServerOptions.TraceOptions.Host)->default_value(""), ""); options.add_option("ue-trace", "", "tracefile", "Path to write a trace to", - cxxopts::value<std::string>(ServerOptions.TraceFile)->default_value(""), + cxxopts::value<std::string>(ServerOptions.TraceOptions.File)->default_value(""), ""); #endif // ZEN_WITH_TRACE @@ -1342,6 +1348,14 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) exit(0); } + if (!ServerOptions.HasTraceCommandlineOptions) + { + // Apply any Lua settings if we don't have them set from the command line + TraceConfigure(ServerOptions.TraceOptions); + } + + ZEN_TRACE_CPU("ConfigParse"); + for (int i = 0; i < logging::level::LogLevelCount; ++i) { logging::ConfigureLogLevels(logging::level::LogLevel(i), ServerOptions.Loggers[i]); diff --git a/src/zenserver/config.h b/src/zenserver/config.h index 4a022a807..9e8787957 100644 --- a/src/zenserver/config.h +++ b/src/zenserver/config.h @@ -3,6 +3,7 @@ #pragma once #include <zencore/logbase.h> +#include <zencore/trace.h> #include <zencore/zencore.h> #include <zenhttp/httpserver.h> #include <filesystem> @@ -208,9 +209,8 @@ struct ZenServerOptions std::string Loggers[zen::logging::level::LogLevelCount]; std::string ScrubOptions; #if ZEN_WITH_TRACE - std::string TraceChannels; // Trace channels to enable - std::string TraceHost; // Host name or IP address to send trace data to - std::string TraceFile; // Path of a file to write a trace + bool HasTraceCommandlineOptions = false; + TraceOptions TraceOptions; #endif std::string MemoryOptions; // Memory allocation options std::string CommandLine; diff --git a/src/zenserver/frontend/frontend.cpp b/src/zenserver/frontend/frontend.cpp index dfa710ae0..2b157581f 100644 --- a/src/zenserver/frontend/frontend.cpp +++ b/src/zenserver/frontend/frontend.cpp @@ -8,6 +8,7 @@ #include <zencore/fmtutils.h> #include <zencore/logging.h> #include <zencore/string.h> +#include <zencore/trace.h> ZEN_THIRD_PARTY_INCLUDES_START #if ZEN_PLATFORM_WINDOWS @@ -31,6 +32,7 @@ HttpFrontendService::HttpFrontendService(std::filesystem::path Directory, HttpSt : m_Directory(Directory) , m_StatusService(StatusService) { + ZEN_TRACE_CPU("HttpFrontendService::HttpFrontendService"); std::filesystem::path SelfPath = GetRunningExecutablePath(); #if ZEN_EMBED_HTML_ZIP diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index 6d9a478be..553562473 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -393,6 +393,18 @@ main(int argc, char* argv[]) try { ZenServerOptions ServerOptions; + + { +#if ZEN_WITH_TRACE + TraceInit("zenserver"); + ServerOptions.HasTraceCommandlineOptions = GetTraceOptionsFromCommandline(ServerOptions.TraceOptions); + if (ServerOptions.HasTraceCommandlineOptions) + { + TraceConfigure(ServerOptions.TraceOptions); + } +#endif // ZEN_WITH_TRACE + } + ParseCliOptions(argc, argv, ServerOptions); if (ServerOptions.Detach) @@ -435,30 +447,6 @@ main(int argc, char* argv[]) CopyTree(ServerOptions.BaseSnapshotDir, ServerOptions.DataDir, {.EnableClone = true}); } -#if ZEN_WITH_TRACE - if (ServerOptions.TraceHost.size()) - { - TraceStart("zenserver", ServerOptions.TraceHost.c_str(), TraceType::Network); - } - else if (ServerOptions.TraceFile.size()) - { - TraceStart("zenserver", ServerOptions.TraceFile.c_str(), TraceType::File); - } - else - { - TraceInit("zenserver"); - } -#endif // ZEN_WITH_TRACE - -#if ZEN_WITH_MEMTRACK - FMalloc* TraceMalloc = MemoryTrace_Create(GMalloc); - if (TraceMalloc != GMalloc) - { - GMalloc = TraceMalloc; - MemoryTrace_Initialize(); - } -#endif - ZEN_MEMSCOPE(GetZenserverTag()); #if ZEN_PLATFORM_WINDOWS diff --git a/src/zenserver/objectstore/objectstore.cpp b/src/zenserver/objectstore/objectstore.cpp index 8faf12165..b1e73c7df 100644 --- a/src/zenserver/objectstore/objectstore.cpp +++ b/src/zenserver/objectstore/objectstore.cpp @@ -9,6 +9,7 @@ #include <zencore/fmtutils.h> #include <zencore/logging.h> #include <zencore/string.h> +#include <zencore/trace.h> #include "zencore/compactbinary.h" #include "zencore/compactbinarybuilder.h" #include "zenhttp/httpcommon.h" @@ -259,6 +260,8 @@ HttpObjectStoreService::HandleStatusRequest(HttpServerRequest& Request) void HttpObjectStoreService::Inititalize() { + ZEN_TRACE_CPU("HttpObjectStoreService::Inititalize"); + namespace fs = std::filesystem; ZEN_LOG_INFO(LogObj, "Initialzing Object Store in '{}'", m_Cfg.RootDirectory); diff --git a/src/zenserver/stats/statsreporter.cpp b/src/zenserver/stats/statsreporter.cpp index 5d5ef4bfa..a1926eba4 100644 --- a/src/zenserver/stats/statsreporter.cpp +++ b/src/zenserver/stats/statsreporter.cpp @@ -3,6 +3,7 @@ #include "statsreporter.h" #include <zencore/logging.h> +#include <zencore/trace.h> #include <zennet/statsdclient.h> namespace zen { @@ -18,6 +19,7 @@ StatsReporter::~StatsReporter() void StatsReporter::Initialize(const ZenStatsConfig& Config) { + ZEN_TRACE_CPU("StatsReporter::Initialize"); RwLock::ExclusiveLockScope _(m_Lock); if (Config.Enabled) diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index 5cab54acc..71b52817c 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -128,6 +128,8 @@ ZenServer::OnReady() int ZenServer::Initialize(const ZenServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry) { + ZEN_TRACE_CPU("ZenServer::Initialize"); + ZEN_MEMSCOPE(GetZenserverTag()); const std::string MutexName = fmt::format("zen_{}", ServerOptions.BasePort); @@ -189,6 +191,7 @@ ZenServer::Initialize(const ZenServerOptions& ServerOptions, ZenServerState::Zen // Setup authentication manager { + ZEN_TRACE_CPU("Zenserver::InitAuth"); std::string EncryptionKey = ServerOptions.EncryptionKey; if (EncryptionKey.empty()) @@ -379,6 +382,8 @@ ZenServer::Initialize(const ZenServerOptions& ServerOptions, ZenServerState::Zen void ZenServer::InitializeState(const ZenServerOptions& ServerOptions) { + ZEN_TRACE_CPU("ZenServer::InitializeState"); + EnqueueSigIntTimer(); // Check root manifest to deal with schema versioning @@ -543,6 +548,8 @@ ZenServer::InitializeState(const ZenServerOptions& ServerOptions) void ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions) { + ZEN_TRACE_CPU("ZenServer::InitializeStructuredCache"); + using namespace std::literals; ZEN_INFO("instantiating structured cache service"); @@ -815,6 +822,7 @@ ZenServer::RequestExit(int ExitCode) void ZenServer::Cleanup() { + ZEN_TRACE_CPU("ZenServer::Cleanup"); ZEN_INFO(ZEN_APP_NAME " cleaning up"); try { @@ -838,8 +846,6 @@ ZenServer::Cleanup() Flush(); - ShutdownWorkerPools(); - m_AdminService.reset(); m_VfsService.reset(); m_ObjStoreService.reset(); @@ -863,6 +869,9 @@ ZenServer::Cleanup() m_AuthService.reset(); m_AuthMgr.reset(); m_Http = {}; + + ShutdownWorkerPools(); + m_JobQueue.reset(); } catch (const std::exception& Ex) @@ -1042,6 +1051,8 @@ ZenServer::CheckOwnerPid() void ZenServer::Flush() { + ZEN_TRACE_CPU("ZenServer::Flush"); + for (auto& It : m_CidStores) { It.second->Flush(); |