JeVois  1.21
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
Timer.H
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18#pragma once
19
20#include <chrono>
21#include <sys/syslog.h>
22#include <string>
23#include <sys/time.h>
24#include <sys/resource.h>
25
26namespace jevois
27{
28 //! Simple timer class
29 /*! This class reports the time spent between start() and stop(), at specified intervals. Because JeVois modules
30 typically work at video rates, this class only reports the average time after some number of iterations through
31 start() and stop(). Thus, even if the time of an operation between start() and stop() is only a few microseconds,
32 by reporting it only every 100 frames one will not slow down the overall framerate too much. See Profiler for a
33 class that provides additional checkpoints between start() and stop(). \ingroup debugging */
34 class Timer
35 {
36 public:
37 //! Constructor
38 Timer(char const * prefix, size_t interval = 100, int loglevel = LOG_INFO);
39
40 //! Start a time measurement period
41 void start();
42
43 //! End a time measurement period, report time spent if reporting interval is reached
44 /*! The fps and cpu load are returned, in case users want to show this info, eg, in an overlay display. Note that
45 the values are only updated when the reporting interval is reached, and remain the same in between. If seconds
46 is not null, it will be set to the instantaneous number of seconds between start() and stop(). */
47 std::string const & stop(double * seconds);
48
49 //! Same as the other signature of stop() except does not provide seconds, for python bindings
50 std::string const & stop();
51
52 private:
53 std::string const itsPrefix;
54 size_t const itsInterval;
55 int const itsLogLevel;
56
57 size_t itsCount;
58 std::chrono::time_point<std::chrono::steady_clock> itsStartTime;
59 double itsSecs, itsMinSecs, itsMaxSecs;
60 std::string itsStr;
61
62 rusage itsStartRusage;
63 std::chrono::time_point<std::chrono::steady_clock> itsStartTimeForCpu;
64 };
65
66 //! Simple one-shot timer class
67 /*! This class reports the time spent between start() and stop(). Typically, this may be useful to report processing
68 time of a neural network, by rendering the string returned by stop() into the video output. \ingroup debugging */
70 {
71 public:
72 //! Constructor
73 TimerOne(char const * prefix);
74
75 //! Start a time measurement period
76 void start();
77
78 //! End a time measurement period, report time spent as: 'prefix: %ms (%fps)' where % is replaced by values
79 /*! If seconds is not null, it will be set to the instantaneous number of seconds between start() and stop(). */
80 std::string stop(double * seconds);
81
82 //! Same as the other signature of stop() except does not provide seconds, for python bindings
83 std::string stop();
84
85 private:
86 std::string const itsPrefix;
87 std::chrono::time_point<std::chrono::steady_clock> itsStartTime;
88 };
89}
Simple one-shot timer class.
Definition Timer.H:70
void start()
Start a time measurement period.
Definition Timer.C:150
std::string stop()
Same as the other signature of stop() except does not provide seconds, for python bindings.
Definition Timer.C:170
Simple timer class.
Definition Timer.H:35
std::string const & stop()
Same as the other signature of stop() except does not provide seconds, for python bindings.
Definition Timer.C:140
void start()
Start a time measurement period.
Definition Timer.C:40
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2