Argus Camera Sample
Argus Camera Sample
 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-2017, 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  */
49 {
53 };
54 
55 /**
56  * Used to track global performance events.
57  */
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  */
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&);
104 
105  bool initialize();
106 
107  // global performance values
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  */
121 {
130 };
131 
132 /**
133  * Used to track session performance events.
134  */
136 {
137 public:
140 
141  /**
142  * Shutdown the session performance tracker.
143  */
144  bool shutdown();
145 
146  /**
147  * Set the capture session to track. If not set the internal dispatcher session is tracked.
148  *
149  * @param session [in] capture session
150  */
151  bool setSession(Argus::CaptureSession *session);
152 
153  /**
154  * Trigger a session event.
155  *
156  * @param type [in] event type
157  * @param type [in] event type
158  */
159  bool onEvent(SessionEvent event, uint64_t value = 0);
160 
161 private:
162  uint32_t m_id;
163 
164  Argus::CaptureSession *m_session;
165  UniquePointer<EventThread> m_eventThread;
166 
170 
173 
177 
180 
181  uint64_t m_minLatency;
182  uint64_t m_maxLatency;
183  uint64_t m_sumLatency;
184  uint64_t m_countLatency;
185 };
186 
187 
188 }; // namespace ArgusSamples
189 
190 #endif //PERFTRACKER_H
191