15void appendNumber(std::string&
out,
double value) {
21void appendString(std::string&
out,
const std::string&
value) {
25 case '"':
out +=
"\\\"";
break;
26 case '\\':
out +=
"\\\\";
break;
27 case '\n':
out +=
"\\n";
break;
28 case '\r':
out +=
"\\r";
break;
29 case '\t':
out +=
"\\t";
break;
31 if (
static_cast<unsigned char>(
c) < 0x20) {
33 std::snprintf(escape,
sizeof(escape),
"\\u%04x",
static_cast<unsigned>(
c));
52 out +=
"{\"module\":";
53 appendString(
out, zone.module);
56 out +=
",\"thread\":";
58 out +=
",\"selfMs\":";
60 out +=
",\"totalMs\":";
62 out +=
",\"count\":" + std::to_string(zone.
count) +
",\"depth\":" + std::to_string(zone.
minDepth) +
"}";
69 std::string frameJson()
const override {
71 auto* timer = eve::cap::query<eve::service::IGpuTimer>();
72 const bool gpuKnown = timer !=
nullptr && timer->gpuTimingAvailable();
76 static const std::vector<eve::prof::ZoneSample> kNoZones;
79 double cpuFrameMs = 0.0;
80 for (
const auto& zone : zones) {
81 if (zone.minDepth == 0) cpuFrameMs += zone.selfMs;
84 std::string
out =
"{\"schema\":\"eve.profiler.frame\",\"version\":2,\"enabled\":";
86 out +=
",\"hasFrame\":";
87 out += hasFrame ?
"true" :
"false";
88 out +=
",\"cpuFrameMs\":";
89 appendNumber(
out, cpuFrameMs);
91 appendNumber(
out, gpuKnown ?
static_cast<double>(timer->gpuFrameMs()) : 0.0);
92 out +=
",\"gpuTimingAvailable\":";
93 out += gpuKnown ?
"true" :
"false";
94 out +=
",\"zoneCount\":" + std::to_string(zones.size()) +
",\"hotspots\":[";
99 out +=
"],\"zones\":[";
108 std::string hotspotsJson(std::size_t
limit,
double minSelfMs)
const override {
111 std::string
out =
"{\"schema\":\"eve.profiler.hotspots\",\"version\":1,\"hasFrame\":";
112 out += hasFrame ?
"true" :
"false";
113 out +=
",\"limit\":" + std::to_string(
limit) +
",\"minSelfMs\":";
114 appendNumber(
out, minSelfMs);
115 out +=
",\"count\":" + std::to_string(zones.size()) +
",\"zones\":[";
124 std::string textReport()
const override {
126 auto* timer = eve::cap::query<eve::service::IGpuTimer>();
127 if (timer && timer->gpuTimingAvailable()) {
129 std::snprintf(
buffer,
sizeof(
buffer),
" GPU frame: %.2f ms\n", timer->gpuFrameMs());
139 static ProfilerQueryImpl
impl;
140 eve::cap::provide<eve::IProfilerQuery>(&
impl);
std::unique_ptr< gpgpu::GpuBuffer > buffer
Runtime profiler read surface (provided by the profiler module).
static std::string textReport()
Human-readable report of the last frame.
static const std::vector< ZoneSample > & lastFrame()
Per-module/per-zone samples of the last frame, sorted by self time.
static std::vector< ZoneSample > hotspots(std::size_t limit, double minSelfMs)
Copy the hottest zones from the last completed frame.
static bool hasFrame()
True once at least one frame has been aggregated.
static bool enabled()
True when collection is active.
EVENGINE_API_FOUNDATION void registerProfilerCapabilities()
Publish the read-only profiler capability (eve::IProfilerQuery).
Per-module/per-zone aggregate of the last completed frame.
std::string std::string name