NvApplicationProfiler
is a helper class for profiling the overall application resource usage.
More...
#include <NvApplicationProfiler.h>
Classes | |
struct | NvAppProfilerData |
Holds the profiling data. More... | |
struct | ProfilerDataInternal |
Internal structure to hold resource usage readings. More... | |
Public Member Functions | |
void | start (uint32_t sampling_interval_ms) |
Start the profiler with the specified sampling interval. | |
void | stop () |
Stop the profiler. | |
void | printProfilerData (std::ostream &outstream=std::cout) |
Print the profiler data to an output stream. | |
void | getProfilerData (NvAppProfilerData &data) |
Get the profiler data. | |
Static Public Member Functions | |
static NvApplicationProfiler & | getProfilerInstance () |
Get a reference to the global NvApplicationProfiler instance. | |
Static Public Attributes | |
static const uint64_t | DefaultSamplingInterval = 100 |
Private Member Functions | |
void | profile () |
Measure resource usage parameters. | |
NvApplicationProfiler () | |
Default constructor used by getProfilerInstance. | |
NvApplicationProfiler (const NvApplicationProfiler &that) | |
Disallow copy constructor. | |
void | operator= (NvApplicationProfiler const &) |
Disallow assignment. | |
Static Private Member Functions | |
static void * | ProfilerThread (void *) |
Method which is run by the background profiling thread. | |
Private Attributes | |
bool | running |
Boolean flag indicating if profiling thread is running. | |
uint32_t | sampling_interval |
Interval between two measurements, in milliseconds. | |
pthread_mutex_t | thread_lock |
Lock for synchronized multithreaded access to data. | |
pthread_t | profiling_thread |
uint32_t | num_cpu_cores |
ID of the profiling thread running in background. | |
uint32_t | cpu_freq |
Operating frequency of CPU cores in MHz. | |
bool | check_cpu_usage |
Flag indicating if cpu usage should be checked. | |
struct NvApplicationProfiler::ProfilerDataInternal | data |
Internal structure to hold resource usage readings. |
NvApplicationProfiler
is a helper class for profiling the overall application resource usage.
NvApplicationProfiler spawns a background thread which periodically measures resource usage. This sampling interval can be configured. Smaller sampling intervals may lead to more accurate results but the background thread itself will have a higher CPU usage.
Only one instance of NvApplicationProfiler object gets created for the application. It can be accessed using getProfilerInstance().
NvApplicationProfiler currently samples CPU usage and provides peak and average CPU usage during the profiling duration. It requires that the CPU frequency be constant over the entire duration. To force this, NvApplicationProfiler will start only when the CPU governor is set to performance.
Definition at line 62 of file NvApplicationProfiler.h.
NvApplicationProfiler::NvApplicationProfiler | ( | ) | [private] |
Default constructor used by getProfilerInstance.
Definition at line 47 of file NvApplicationProfiler.cpp.
NvApplicationProfiler::NvApplicationProfiler | ( | const NvApplicationProfiler & | that | ) | [private] |
Disallow copy constructor.
void NvApplicationProfiler::getProfilerData | ( | NvAppProfilerData & | data | ) |
Get the profiler data.
[out] | data | Pointer to the ProfilerData structure to be filled. |
Definition at line 204 of file NvApplicationProfiler.cpp.
NvApplicationProfiler & NvApplicationProfiler::getProfilerInstance | ( | ) | [static] |
Get a reference to the global NvApplicationProfiler instance.
Definition at line 80 of file NvApplicationProfiler.cpp.
void NvApplicationProfiler::operator= | ( | NvApplicationProfiler const & | ) | [private] |
Disallow assignment.
void NvApplicationProfiler::printProfilerData | ( | std::ostream & | outstream = std::cout |
) |
Print the profiler data to an output stream.
[in] | outstream | A reference to an output stream of type std::ostream. std::cout if not specified. |
Definition at line 236 of file NvApplicationProfiler.cpp.
void NvApplicationProfiler::profile | ( | ) | [private] |
void * NvApplicationProfiler::ProfilerThread | ( | void * | data | ) | [static, private] |
Method which is run by the background profiling thread.
Waits on a condition till the next periodic sampling time and calls profile() for measurement.
Runs in an infinite loop till signaled to stop.
Definition at line 172 of file NvApplicationProfiler.cpp.
void NvApplicationProfiler::start | ( | uint32_t | sampling_interval_ms | ) |
Start the profiler with the specified sampling interval.
This method resets the internal profiler data measurements.
Starting an already started profiler does nothing.
[in] | sampling_interval_ms | Sampling interval in milliseconds. |
Definition at line 87 of file NvApplicationProfiler.cpp.
void NvApplicationProfiler::stop | ( | ) |
bool NvApplicationProfiler::check_cpu_usage [private] |
Flag indicating if cpu usage should be checked.
Definition at line 144 of file NvApplicationProfiler.h.
uint32_t NvApplicationProfiler::cpu_freq [private] |
struct NvApplicationProfiler::ProfilerDataInternal NvApplicationProfiler::data [private] |
Internal structure to hold resource usage readings.
Internal structure to hold intermediate measurements.
const uint64_t NvApplicationProfiler::DefaultSamplingInterval = 100 [static] |
Definition at line 82 of file NvApplicationProfiler.h.
uint32_t NvApplicationProfiler::num_cpu_cores [private] |
ID of the profiling thread running in background.
Number of CPU cores.
Definition at line 142 of file NvApplicationProfiler.h.
pthread_t NvApplicationProfiler::profiling_thread [private] |
Definition at line 139 of file NvApplicationProfiler.h.
bool NvApplicationProfiler::running [private] |
Boolean flag indicating if profiling thread is running.
Definition at line 133 of file NvApplicationProfiler.h.
uint32_t NvApplicationProfiler::sampling_interval [private] |
Interval between two measurements, in milliseconds.
Definition at line 134 of file NvApplicationProfiler.h.
pthread_mutex_t NvApplicationProfiler::thread_lock [private] |
Lock for synchronized multithreaded access to data.
Definition at line 137 of file NvApplicationProfiler.h.