ConsumeSample each frame.
Decode the record buffer and store the decoded counters into the counter data.
Inform counter data to stop iterating because all existing data has been consumed.
Reset after out.
Decode the record buffer and store the decoded counters into the counter data.
Inform counter data to stop iterating because all existing data has been consumed.
Reset after out.
233 {
235
237
238 nv::perf::sampler::GpuPeriodicSampler::GetRecordBufferStatusParams getRecordBufferStatusParams = {};
239 getRecordBufferStatusParams.queryOverflow = true;
240 getRecordBufferStatusParams.queryNumUnreadBytes = true;
241 const bool success =
sampler.GetRecordBufferStatus(getRecordBufferStatusParams);
242 if (!success)
243 {
244 return;
245 }
246 if (getRecordBufferStatusParams.overflow)
247 {
248 SPICES_CORE_ERROR("Record buffer has overflowed. Please ensure that the value of `maxNumUndecodedSamples` is sufficiently large.")
249 }
250
251 if (getRecordBufferStatusParams.numUnreadBytes == 0)
252 {
253 return;
254 }
255
259 NVPW_GPU_PeriodicSampler_DecodeStopReason decodeStopReason = NVPW_GPU_PERIODIC_SAMPLER_DECODE_STOP_REASON_OTHER;
260 size_t numSamplesMerged = 0;
261 size_t numBytesConsumed = 0;
264 getRecordBufferStatusParams.numUnreadBytes ,
265 decodeStopReason ,
266 numSamplesMerged ,
267 numBytesConsumed
268 ))
269 {
270 SPICES_CORE_WARN("Failed to decode counters.")
271 }
272
273 if (numSamplesMerged)
274 {
275 SPICES_CORE_WARN("Samples appear to be merged, this can reduce the accuracy of the collected samples. Please check for any back-to-back triggers!")
276 }
277 if (decodeStopReason != NVPW_GPU_PERIODIC_SAMPLER_DECODE_STOP_REASON_ALL_GIVEN_BYTES_READ)
278 {
279 SPICES_CORE_WARN("DecodeCounters stopped unexpectedly.")
280 }
281 if (!
sampler.AcknowledgeRecordBuffer(numBytesConsumed))
282 {
283 SPICES_CORE_WARN("Failed to acknowledge record buffer")
284 }
286 {
287 SPICES_CORE_WARN("Failed to update counter data's put pointer.")
288 }
289
290 const uint32_t numUnreadRanges =
counterData.GetNumUnreadRanges();
291 if (numUnreadRanges)
292 {
294 uint32_t numRangesConsumed = 0;
296 [&](
297 const uint8_t* pCounterDataImage ,
298 size_t counterDataImageSize ,
299 uint32_t rangeIndex ,
300 bool& stop
301 )
302 {
303 nv::perf::sampler::SampleTimestamp timestamp{};
304 if (!CounterDataGetSampleTime(pCounterDataImage, rangeIndex, timestamp))
305 {
306 return false;
307 }
308
309 if (!nv::perf::EvaluateToGpuValues(
311 pCounterDataImage,
312 counterDataImageSize,
313 rangeIndex,
316 metricValues.data()))
317 {
318 return false;
319 }
320 {
321 std::cout << std::fixed << std::setprecision(0) << timestamp.start << ", " << timestamp.end << ", " << (timestamp.end - timestamp.start);
322 for (const double& metricValue : metricValues)
323 {
324 std::cout << ", " << metricValue;
325 }
326 std::cout << "\n";
327 }
328 if (++numRangesConsumed == numUnreadRanges)
329 {
333 stop = true;
334 }
335 return true;
336 }))
337
340 {
341 SPICES_CORE_WARN("Counter data failed to update get pointer.")
342 }
343 }
344
349 }
#define NSPERF_CHECK(val)
#define SPICES_PROFILE_ZONE
std::vector< NVPW_MetricEvalRequest > metricEvalRequests
Metrics requests.
void Reset()
Reset on quit application.
nv::perf::MetricsEvaluator metricsEvaluator
MetricsEvaluator.
bool m_IsInSession
True if in session.
nv::perf::sampler::RingBufferCounterData counterData
This is used to store the counter values collected during profiling.
nv::perf::sampler::GpuPeriodicSampler sampler
the periodic sampler.