Changeset View
Changeset View
Standalone View
Standalone View
source/ps/Profiler2.cpp
Show All 20 Lines | |||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "Profiler2.h" | #include "Profiler2.h" | ||||
#include "lib/allocators/shared_ptr.h" | #include "lib/allocators/shared_ptr.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/ConfigDB.h" | |||||
#include "ps/CStr.h" | #include "ps/CStr.h" | ||||
#include "ps/Profiler2GPU.h" | #include "ps/Profiler2GPU.h" | ||||
#include "third_party/mongoose/mongoose.h" | #include "third_party/mongoose/mongoose.h" | ||||
#include <iomanip> | #include <iomanip> | ||||
#include <map> | #include <map> | ||||
#include <unordered_map> | #include <unordered_map> | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
ENSURE(m_Initialised); | ENSURE(m_Initialised); | ||||
LOGMESSAGERENDER("Starting profiler2 HTTP server"); | LOGMESSAGERENDER("Starting profiler2 HTTP server"); | ||||
// Ignore multiple enablings | // Ignore multiple enablings | ||||
if (m_MgContext) | if (m_MgContext) | ||||
return; | return; | ||||
const char *options[] = { | std::string listeningPort; | ||||
"listening_ports", "127.0.0.1:8000", // bind to localhost for security | std::string listeningServer; | ||||
"num_threads", "6", // enough for the browser's parallel connection limit | std::string numThreads; | ||||
NULL | CFG_GET_VAL("profiler2.server.port", listeningPort); | ||||
CFG_GET_VAL("profiler2.server", listeningServer); | |||||
CFG_GET_VAL("profiler2.server.threads", numThreads); | |||||
std::stringstream stream; | |||||
stream << listeningServer << ":" << listeningPort; | |||||
std::string listening_ports = stream.str(); | |||||
const char* options[5] = { | |||||
"listening_ports", listening_ports.c_str(), | |||||
"num_threads", numThreads.c_str(), | |||||
nullptr | |||||
}; | }; | ||||
m_MgContext = mg_start(MgCallback, this, options); | m_MgContext = mg_start(MgCallback, this, options); | ||||
vladislavbelov: Is it safe to pass local variables? | |||||
Done Inline ActionsMongoose is not *safe* There are quite a few warnings in that lib... Stan: Mongoose is not *safe* There are quite a few warnings in that lib... | |||||
Done Inline ActionsI mean will it access string pointers after mg_start call? After current scoped? vladislavbelov: I mean will it access string pointers after `mg_start` call? After current scoped? | |||||
Done Inline ActionsI'm not sure, can you help me there? What should be done instead? Stan: I'm not sure, can you help me there? What should be done instead? | |||||
ENSURE(m_MgContext); | ENSURE(m_MgContext); | ||||
} | } | ||||
void CProfiler2::EnableGPU() | void CProfiler2::EnableGPU() | ||||
{ | { | ||||
ENSURE(m_Initialised); | ENSURE(m_Initialised); | ||||
if (!m_GPU) | if (!m_GPU) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 721 Lines • ▼ Show 20 Lines | const char* CProfiler2::ConstructJSONResponse(std::ostream& stream, const std::string& thread) | ||||
stream << "null]\n]}"; | stream << "null]\n]}"; | ||||
return NULL; | return NULL; | ||||
} | } | ||||
void CProfiler2::SaveToFile() | void CProfiler2::SaveToFile() | ||||
{ | { | ||||
OsPath path = psLogDir()/"profile2.jsonp"; | OsPath path = psLogDir()/"profile2.json"; | ||||
debug_printf("Writing profile data to: %ls \n", OsString(path).c_str()); | |||||
std::ofstream stream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); | std::ofstream stream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); | ||||
ENSURE(stream.good()); | ENSURE(stream.good()); | ||||
stream << "profileDataCB({\"threads\": [\n"; | stream << "profileDataCB({\"threads\": [\n"; | ||||
bool first_time = true; | bool first_time = true; | ||||
for (std::unique_ptr<ThreadStorage>& storage : m_Threads) | for (std::unique_ptr<ThreadStorage>& storage : m_Threads) | ||||
{ | { | ||||
if (!first_time) | if (!first_time) | ||||
stream << ",\n"; | stream << ",\n"; | ||||
stream << "{\"name\":\"" << CStr(storage->GetName()).EscapeToPrintableASCII() << "\",\n"; | stream << "{\"name\":\"" << CStr(storage->GetName()).EscapeToPrintableASCII() << "\",\n"; | ||||
stream << "\"data\": "; | stream << "\"data\": "; | ||||
ConstructJSONResponse(stream, storage->GetName()); | ConstructJSONResponse(stream, storage->GetName()); | ||||
Done Inline ActionsThe value was different, wasn't it? vladislavbelov: The value was different, wasn't it? | |||||
Done Inline ActionsIt was but it makes no point does it? Stan: It was but it makes no point does it? | |||||
Done Inline ActionsI think it doesn't work, because ConstructJSONResponse does a search for GetName(), not for CStr(storage->GetName()).EscapeToPrintableASCII(). That means it won't find a thread in case of unprintable characters. vladislavbelov: I think it doesn't work, because `ConstructJSONResponse` does a search for `GetName()`, not for… | |||||
Done Inline ActionsAlright, I'll revert it. Stan: Alright, I'll revert it. | |||||
stream << "\n}"; | stream << "\n}"; | ||||
first_time = false; | first_time = false; | ||||
} | } | ||||
stream << "\n]});\n"; | stream << "\n]});\n"; | ||||
} | } | ||||
CProfile2SpikeRegion::CProfile2SpikeRegion(const char* name, double spikeLimit) : | CProfile2SpikeRegion::CProfile2SpikeRegion(const char* name, double spikeLimit) : | ||||
m_Name(name), m_Limit(spikeLimit), m_PushedHold(true) | m_Name(name), m_Limit(spikeLimit), m_PushedHold(true) | ||||
Show All 39 Lines |
Wildfire Games · Phabricator
Is it safe to pass local variables?