JeVois  1.22
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 /*! If loglevel is -1 then nothing will be logged and stop() will return the average/min/max time instead of
39 frames/s and CPU usage. */
40 Timer(char const * prefix, size_t interval = 100, int loglevel = LOG_INFO);
41
42 //! Start a time measurement period
43 void start();
44
45 //! End a time measurement period, report time spent if reporting interval is reached
46 /*! The fps and cpu load are returned, in case users want to show this info, eg, in an overlay display. Note that
47 the values are only updated when the reporting interval is reached, and remain the same in between. If seconds
48 is not null, it will be set to the instantaneous number of seconds between start() and stop(). */
49 std::string const & stop(double * seconds);
50
51 //! Same as the other signature of stop() except does not provide seconds, for python bindings
52 std::string const & stop();
53
54 private:
55 std::string const itsPrefix;
56 size_t const itsInterval;
57 int const itsLogLevel;
58
59 size_t itsCount;
60 std::chrono::time_point<std::chrono::steady_clock> itsStartTime;
61 double itsSecs, itsMinSecs, itsMaxSecs;
62 std::string itsStr;
63
64 rusage itsStartRusage;
65 std::chrono::time_point<std::chrono::steady_clock> itsStartTimeForCpu;
66 };
67
68 //! Simple one-shot timer class
69 /*! This class reports the time spent between start() and stop(). Typically, this may be useful to report processing
70 time of a neural network, by rendering the string returned by stop() into the video output. \ingroup debugging */
72 {
73 public:
74 //! Constructor
75 TimerOne(char const * prefix);
76
77 //! Start a time measurement period
78 void start();
79
80 //! End a time measurement period, report time spent as: 'prefix: %ms (%fps)' where % is replaced by values
81 /*! If seconds is not null, it will be set to the instantaneous number of seconds between start() and stop(). */
82 std::string stop(double * seconds);
83
84 //! Same as the other signature of stop() except does not provide seconds, for python bindings
85 std::string stop();
86
87 private:
88 std::string const itsPrefix;
89 std::chrono::time_point<std::chrono::steady_clock> itsStartTime;
90 };
91}
Simple one-shot timer class.
Definition Timer.H:72
void start()
Start a time measurement period.
Definition Timer.C:156
std::string stop()
Same as the other signature of stop() except does not provide seconds, for python bindings.
Definition Timer.C:176
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:146
void start()
Start a time measurement period.
Definition Timer.C:40
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2