Argus Camera Sample
Argus Camera Sample
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PerfTracker.cpp
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 #include <stdio.h>
30 #define __STDC_FORMAT_MACROS
31 #include <inttypes.h>
32 
33 #include "PerfTracker.h"
34 #include "Dispatcher.h"
35 
36 namespace ArgusSamples
37 {
38 
39 int PerfTracker::s_count = 0;
42 
44  : m_id(s_count)
45  , m_numberframesReceived(0)
46  , m_lastFrameCount(0)
47  , m_totalFrameDrop(0)
48 {
49  s_count++;
50 }
51 
52 void PerfTracker::onAppEvent(PerfEventType type, uint64_t value)
53 {
54  switch(type)
55  {
56  case APP_START:
58  break;
59  case APP_INITIALIZED:
61  break;
62  default:
63  printf("unexpected type in perfTracker\n");
64  break;
65  }
66  return;
67 }
68 
69 void PerfTracker::onEvent(PerfEventType type, uint64_t value)
70 {
71  if (!Dispatcher::getInstance().m_kpi)
72  return;
73 
74  switch(type)
75  {
76  case TASK_START:
78  printf("PerfTracker: app initial %" PRIu64 " ms\n",
80  printf("PerfTracker %d: app intialized to task start %" PRIu64 " ms\n", m_id,
82  break;
83  case ISSUE_CAPTURE:
85  printf("PerfTracker %d: task start to issue capture %" PRIu64 " ms\n", m_id,
86  (m_issueCaptureTime - m_taskStartTime).toMSec());
87  break;
88  case REQUEST_RECEIVED:
90  if (m_numberframesReceived == 0)
91  {
93  printf("PerfTracker %d: first request %" PRIu64 " ms\n", m_id,
95  printf("PerfTracker %d: total launch time %" PRIu64 " ms\n", m_id,
97  }
98 
100  if ((m_numberframesReceived % 30) == 2)
101  {
102  float frameRate =
103  static_cast<float>(m_numberframesReceived - 1) *
105  printf("PerfTracker %d: frameRate %.2f frames per second\n", m_id, frameRate);
106  }
107  break;
108  case REQUEST_LATENCY:
109  // can do some stats
110  printf("PerfTracker %d: latency %" PRIu64 " ms\n", m_id, value);
111  break;
112  case FRAME_COUNT:
113  {
114  uint64_t currentFrameCount = 0;
115  uint64_t currentFrameDrop = 0;
116  currentFrameCount = value;
117  // start frame drop count from 2nd frame
118  if (m_lastFrameCount > 0)
119  {
120  currentFrameDrop = currentFrameCount - m_lastFrameCount - 1;
121  m_totalFrameDrop += currentFrameDrop;
122  }
123  printf("perfTracker %d: framedrop current request %" PRIu64 ", total %" PRIu64 "\n",
124  m_id, currentFrameDrop, m_totalFrameDrop);
125  m_lastFrameCount = currentFrameCount;
126  break;
127  }
128  case CLOSE_REQUESTED:
130  break;
131  case FLUSH_DONE:
133  printf("PerfTracker %d: flush takes %" PRIu64 " ms\n", m_id,
135  break;
136  case CLOSE_DONE:
138  printf("PerfTracker %d: device close takes %" PRIu64 " ms\n", m_id,
139  (m_closeDoneTime - m_flushDoneTime).toMSec());
140  printf("PerfTracker %d: total close takes %" PRIu64 " ms\n", m_id,
142  break;
143 
144  default:
145  printf("unexpected type in perfTracker\n");
146  break;
147  }
148  return;
149 }
150 
151 }; // namespace ArgusSamples