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));
55 std::string frameJson()
const override {
57 auto* timer = eve::cap::query<eve::service::IGpuTimer>();
58 const bool gpuKnown = timer !=
nullptr && timer->gpuTimingAvailable();
62 static const std::vector<eve::prof::ZoneSample> kNoZones;
64 double cpuFrameMs = 0.0;
65 for (
const auto& zone : zones) {
66 if (zone.minDepth == 0) cpuFrameMs += zone.selfMs;
69 std::string out =
"{\"schema\":\"eve.profiler.frame\",\"version\":1,\"enabled\":";
70 out +=
enabled() ?
"true" :
"false";
71 out +=
",\"hasFrame\":";
72 out += hasFrame ?
"true" :
"false";
73 out +=
",\"cpuFrameMs\":";
74 appendNumber(out, cpuFrameMs);
76 appendNumber(out, gpuKnown ?
static_cast<double>(timer->gpuFrameMs()) : 0.0);
77 out +=
",\"gpuTimingAvailable\":";
78 out += gpuKnown ?
"true" :
"false";
79 out +=
",\"zoneCount\":" + std::to_string(zones.size()) +
",\"zones\":[";
82 if (
index) out +=
',';
83 out +=
"{\"module\":";
84 appendString(out, zone.module);
86 appendString(out, zone.
name);
87 out +=
",\"thread\":";
88 appendString(out, zone.
thread);
89 out +=
",\"selfMs\":";
90 appendNumber(out, zone.
selfMs);
91 out +=
",\"totalMs\":";
92 appendNumber(out, zone.
totalMs);
93 out +=
",\"count\":" + std::to_string(zone.
count) +
",\"depth\":" + std::to_string(zone.
minDepth) +
"}";
99 std::string textReport()
const override {
101 auto* timer = eve::cap::query<eve::service::IGpuTimer>();
102 if (timer && timer->gpuTimingAvailable()) {
104 std::snprintf(
buffer,
sizeof(
buffer),
" GPU frame: %.2f ms\n", timer->gpuFrameMs());
114 static ProfilerQueryImpl
impl;
115 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 bool hasFrame()
True once at least one frame has been aggregated.
static bool enabled()
True when collection is active.
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