JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Profiler.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 <vector>
24 
25 namespace jevois
26 {
27  //! Simple profiler class
28  /*! This class reports the time spent between start() and each of the checkpoint() calls, separately computed for each
29  checkpoint string, at specified intervals. Because JeVois modules typically work at video rates, this class only
30  reports the average time after some number of iterations through the start(), checkpoint(), and stop(). Thus, even
31  if the time between two checkpoints is only a few microseconds, by reporting it only every 100 frames one will not
32  slow down the overall framerate too much. See Timer for a lighter class with only start() and stop().
33  \ingroup debugging */
34  class Profiler
35  {
36  public:
37  //! Constructor
38  Profiler(char const * prefix, size_t interval = 100, int loglevel = LOG_INFO);
39 
40  //! Start a time measurement period
41  void start();
42 
43  //! Note the time for a particular event
44  /*! The delta time between this event and the previous one (or start() for the first checkpoint) will be
45  reported. Note that we create a new unique entry in our tables for each description value, so you should keep
46  the number of unique descriptions passed small (do not include a frame number or some parameter value). The
47  description is passed as a raw C string to encourage you to just use a string literal for it. */
48  void checkpoint(char const * description);
49 
50  //! End a time measurement period, report time spent for each checkpoint if reporting interval is reached
51  /*! The time reported is from start to each checkpoint. */
52  void stop();
53 
54  private:
55  std::string const itsPrefix;
56  size_t const itsInterval;
57  int const itsLogLevel;
58 
59  std::chrono::time_point<std::chrono::steady_clock> itsStartTime;
60 
61  struct data
62  {
63  std::string desc;
64  size_t count;
65  double secs;
66  double minsecs;
67  double maxsecs;
68  std::chrono::time_point<std::chrono::steady_clock> lasttime;
69  };
70 
71  data itsData; // for the stop() checkpoint
72  std::vector<data> itsCheckpointData; // one entry per checkpoint string
73  };
74 }
75 
76 
jevois::Profiler::checkpoint
void checkpoint(char const *description)
Note the time for a particular event.
Definition: Profiler.C:39
jevois
Definition: Concepts.dox:1
jevois::Profiler
Simple profiler class.
Definition: Profiler.H:34
jevois::Profiler::start
void start()
Start a time measurement period.
Definition: Profiler.C:33
jevois::Profiler::stop
void stop()
End a time measurement period, report time spent for each checkpoint if reporting interval is reached...
Definition: Profiler.C:74
jevois::Profiler::Profiler
Profiler(char const *prefix, size_t interval=100, int loglevel=LOG_INFO)
Constructor.
Definition: Profiler.C:24