Argus Camera Sample Argus Camera Sample

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PerfTracker.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016-2022, 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 #ifndef PERFTRACKER_H
30 #define PERFTRACKER_H
31
32 #include <stddef.h>
33
34 #include "Util.h" // for TimeValue
35 #include "Ordered.h"
36 #include "UniquePointer.h"
37
38 namespace Argus { class CaptureSession; }
39
40 namespace ArgusSamples
41 {
42
43 class EventThread;
44
45 /**
46 * Global events
47 */
48 enum GlobalEvent
49 {
50 GLOBAL_EVENT_APP_START,
51 GLOBAL_EVENT_APP_INITIALIZED,
52 GLOBAL_EVENT_DISPLAY
53 };
54
55 /**
56 * Used to track global performance events.
57 */
58 class PerfTracker
59 {
60 public:
61 /**
62 * Get the window instance.
63 */
64 static PerfTracker &getInstance();
65
66 /**
67 * Trigger a global event.
68 *
69 * @param type [in] event type
70 */
71 bool onEvent(GlobalEvent event);
72
73 /**
74 * @returns the point in time when the app had been started
75 */
76 const TimeValue& appStartTime() const
77 {
78 return m_appStartTime;
79 }
80
81 /**
82 * @returns the point in time when app initialization finished
83 */
84 const TimeValue& appInitializedTime() const
85 {
86 return m_appInitializedTime;
87 }
88
89 /**
90 * @returns a new session Id
91 */
92 uint32_t getNewSessionID()
93 {
94 return ++m_sessionId;
95 }
96
97 private:
98 PerfTracker();
99 ~PerfTracker();
100
101 // this is a singleton, hide copy constructor etc.
102 PerfTracker(const PerfTracker&);
103 PerfTracker& operator=(const PerfTracker&);
104
105 bool initialize();
106
107 // global performance values
108 TimeValue m_appStartTime;
109 TimeValue m_appInitializedTime;
110
111 TimeValue m_firstDisplayTime; //< time at which the first display event had been received
112 uint64_t m_displayCount; //< display events since first display time
113
114 Ordered<uint32_t> m_sessionId;
115 };
116
117 /**
118 * Session events
119 */
120 enum SessionEvent
121 {
122 SESSION_EVENT_TASK_START,
123 SESSION_EVENT_ISSUE_CAPTURE,
124 SESSION_EVENT_REQUEST_RECEIVED,
125 SESSION_EVENT_REQUEST_LATENCY,
126 SESSION_EVENT_FRAME_PERIOD,
127 SESSION_EVENT_FRAME_COUNT,
128 SESSION_EVENT_CLOSE_REQUESTED,
129 SESSION_EVENT_FLUSH_DONE,
130 SESSION_EVENT_CLOSE_DONE
131 };
132
133 /**
134 * Used to track session performance events.
135 */
136 class SessionPerfTracker
137 {
138 public:
139 SessionPerfTracker();
140 ~SessionPerfTracker();
141
142 /**
143 * Shutdown the session performance tracker.
144 */
145 bool shutdown();
146
147 /**
148 * Set the capture session to track. If not set the internal dispatcher session is tracked.
149 *
150 * @param session [in] capture session
151 */
152 bool setSession(Argus::CaptureSession *session);
153
154 /**
155 * Trigger a session event.
156 *
157 * @param type [in] event type
158 * @param type [in] event type
159 */
160 bool onEvent(SessionEvent event, uint64_t value = 0);
161
162 private:
163 uint32_t m_id;
164
165 Argus::CaptureSession *m_session;
166 UniquePointer<EventThread> m_eventThread;
167
168 TimeValue m_taskStartTime;
169 TimeValue m_issueCaptureTime;
170 TimeValue m_requestReceivedTime;
171
172 TimeValue m_firstRequestReceivedTime;
173 uint64_t m_numberframesReceived;
174
175 TimeValue m_closeRequestedTime;
176 TimeValue m_flushDoneTime;
177 TimeValue m_closeDoneTime;
178
179 uint64_t m_lastFrameCount;
180 int64_t m_totalFrameDrop;
181
182 uint64_t m_minLatency;
183 uint64_t m_maxLatency;
184 uint64_t m_sumLatency;
185 uint64_t m_countLatency;
186
187 uint64_t m_previousSensorTime;
188 uint64_t m_minFramePeriod;
189 uint64_t m_maxFramePeriod;
190 uint64_t m_sumFramePeriod;
191 int64_t m_countFramePeriod;
192
193 uint64_t m_statsMinLatency;
194 uint64_t m_statsMaxLatency;
195 uint64_t m_statsSumLatency;
196 uint64_t m_statsCountLatency;
197 uint64_t m_statsMinFramePeriod;
198 uint64_t m_statsMaxFramePeriod;
199 uint64_t m_statsSumFramePeriod;
200 uint64_t m_statsCountFramePeriod;
201 uint32_t m_statsFrameDropCount;
202 uint32_t m_statsOutOfOrderCount;
203
204 bool m_previousKpi;
205 };
206
207
208 }; // namespace ArgusSamples
209
210 #endif //PERFTRACKER_H
211