Jetson Linux API Reference

32.7.5 Release
NvApplicationProfiler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
36 #ifndef __NV_PROFILER_H__
37 #define __NV_PROFILER_H__
38 
39 #include <iostream>
40 #include <pthread.h>
41 #include <stdint.h>
42 #include <sys/time.h>
43 #include <time.h>
44 
68 {
69 public:
73  typedef struct
74  {
76  struct timeval total_time;
82  uint32_t num_cpu_cores;
84  uint32_t cpu_freq_mhz;
86 
87  static const uint64_t DefaultSamplingInterval = 100;
88 
95 
105  void start(uint32_t sampling_interval_ms);
106 
110  void stop();
111 
118  void printProfilerData(std::ostream &outstream = std::cout);
119 
126 
127 private:
136  static void * ProfilerThread(void *);
137 
138  bool running;
139  uint32_t sampling_interval;
142  pthread_mutex_t thread_lock;
144  pthread_t profiling_thread;
147  uint32_t num_cpu_cores;
148  uint32_t cpu_freq;
149  bool check_cpu_usage;
154  struct ProfilerDataInternal
155  {
157  struct timeval start_time;
159  struct timeval stop_time;
160 
163  struct timespec start_proc_cpu_clock_time;
165  struct timespec start_cpu_clock_time;
166 
169  struct timespec stop_proc_cpu_clock_time;
171  struct timespec stop_cpu_clock_time;
172 
174  float max_cpu_usage;
176  float min_cpu_usage;
178  float avg_cpu_usage;
179 
181  uint64_t num_readings;
182  } data;
187  void profile();
188 
193 
201  void operator=(NvApplicationProfiler const&);
202 };
203 
206 #endif
NvApplicationProfiler::getProfilerData
void getProfilerData(NvAppProfilerData &data)
Gets the profiler data.
NvApplicationProfiler::NvAppProfilerData
Holds the profiling data.
Definition: NvApplicationProfiler.h:73
NvApplicationProfiler
Definition: NvApplicationProfiler.h:67
NvApplicationProfiler::printProfilerData
void printProfilerData(std::ostream &outstream=std::cout)
Prints the profiler data to an output stream.
NvApplicationProfiler::NvAppProfilerData::num_cpu_cores
uint32_t num_cpu_cores
Number of cpu cores.
Definition: NvApplicationProfiler.h:82
NvApplicationProfiler::NvAppProfilerData::cpu_freq_mhz
uint32_t cpu_freq_mhz
Operating frequency of the cpu in MHz.
Definition: NvApplicationProfiler.h:84
NvApplicationProfiler::start
void start(uint32_t sampling_interval_ms)
Starts the profiler with the specified sampling interval.
NvApplicationProfiler::stop
void stop()
Stops the profiler.
NvApplicationProfiler::DefaultSamplingInterval
static const uint64_t DefaultSamplingInterval
Definition: NvApplicationProfiler.h:87
NvApplicationProfiler::NvAppProfilerData::avg_cpu_usage
float avg_cpu_usage
Average CPU usage over the entire profiling duration.
Definition: NvApplicationProfiler.h:80
NvApplicationProfiler::NvAppProfilerData::peak_cpu_usage
float peak_cpu_usage
Peak CPU usage during the profiling time.
Definition: NvApplicationProfiler.h:78
NvApplicationProfiler::getProfilerInstance
static NvApplicationProfiler & getProfilerInstance()
Gets a reference to the global NvApplicationProfiler instance.