123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- #ifndef __NV_PROFILER_H__
- #define __NV_PROFILER_H__
- #include <iostream>
- #include <pthread.h>
- #include <stdint.h>
- #include <sys/time.h>
- #include <time.h>
- class NvApplicationProfiler
- {
- public:
-
- typedef struct
- {
-
- struct timeval total_time;
-
- float peak_cpu_usage;
-
- float avg_cpu_usage;
-
- uint32_t num_cpu_cores;
-
- uint32_t cpu_freq_mhz;
- } NvAppProfilerData;
- static const uint64_t DefaultSamplingInterval = 100;
-
- static NvApplicationProfiler& getProfilerInstance();
-
- void start(uint32_t sampling_interval_ms);
-
- void stop();
-
- void printProfilerData(std::ostream &outstream = std::cout);
-
- void getProfilerData(NvAppProfilerData &data);
- private:
-
- static void * ProfilerThread(void *);
- bool running;
- uint32_t sampling_interval;
- pthread_mutex_t thread_lock;
- pthread_t profiling_thread;
- uint32_t num_cpu_cores;
- uint32_t cpu_freq;
- bool check_cpu_usage;
-
- struct ProfilerDataInternal
- {
-
- struct timeval start_time;
-
- struct timeval stop_time;
-
- struct timespec start_proc_cpu_clock_time;
-
- struct timespec start_cpu_clock_time;
-
- struct timespec stop_proc_cpu_clock_time;
-
- struct timespec stop_cpu_clock_time;
-
- float max_cpu_usage;
-
- float min_cpu_usage;
-
- float avg_cpu_usage;
-
- uint64_t num_readings;
- } data;
-
- void profile();
-
- NvApplicationProfiler();
-
- NvApplicationProfiler(const NvApplicationProfiler& that);
-
- void operator=(NvApplicationProfiler const&);
- };
- #endif
|