JeVois  1.3
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
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 
26 namespace 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. */
46  std::string const & stop();
47 
48  private:
49  std::string const itsPrefix;
50  size_t const itsInterval;
51  int const itsLogLevel;
52 
53  size_t itsCount;
54  std::chrono::time_point<std::chrono::high_resolution_clock> itsStartTime;
55  double itsSecs, itsMinSecs, itsMaxSecs;
56  std::string itsStr;
57 
58  rusage itsStartRusage;
59  std::chrono::time_point<std::chrono::high_resolution_clock> itsStartTimeForCpu;
60  };
61 }
62 
63 
void start()
Start a time measurement period.
Definition: Timer.C:50
Simple timer class.
Definition: Timer.H:34
Timer(char const *prefix, size_t interval=100, int loglevel=LOG_INFO)
Constructor.
Definition: Timer.C:39
std::string const & stop()
End a time measurement period, report time spent if reporting interval is reached.
Definition: Timer.C:57