ecto
profile.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 #pragma once
30 #include <stdint.h>//int64_t
31 
32 #include <Python.h>
33 #include <ecto/forward.hpp>
34 #include <ecto/util.hpp>
35 #include <ecto/log.hpp>
36 
37 #include <boost/date_time/posix_time/posix_time.hpp>
38 
39 namespace ecto {
40 namespace profile {
41 
42 unsigned long read_tsc();
43 
45 {
47  boost::posix_time::time_duration cumulative_time;
48  uint64_t cumulative_ticks;
49 
50  std::string as_string(graph::graph_t& g) const;
51 };
52 
54 {
56  const boost::posix_time::ptime start_time;
57  const unsigned long start_tick;
59  : gs_(gs)
60  , start_time(boost::posix_time::microsec_clock::universal_time())
61  , start_tick(profile::read_tsc())
62  {
63  }
64 
66  {
67  const unsigned long stop_tick = profile::read_tsc();
68  const boost::posix_time::ptime stop_time =
70  gs_.cumulative_time += stop_time - start_time;
71  gs_.cumulative_ticks += stop_tick - start_tick;
72  }
73 };
74 
76 {
77  stats_type();
78  unsigned ncalls;
79  uint64_t total_ticks;
80  bool on;
81 
82  double elapsed_time();
83  double frequency();
84 };
85 
87 {
88  const unsigned long start;
90  const std::string& instancename;
91 
92  stats_collector(const std::string& n, stats_type& stats)
93  : start(read_tsc()), stats(stats), instancename(n)
94  {
95  ++stats.ncalls;
96  stats.on = true;
97  //ECTO_LOG_PROCESS(instancename, start, stats.ncalls, 1);
98  }
99 
101  const unsigned long tsc = read_tsc();
102  //ECTO_LOG_PROCESS(instancename, tsc, stats.ncalls, 0);
103  stats.total_ticks += (tsc - start);
104  stats.on = false;
105  }
106 };
107 
108 } // End of namespace profile.
109 } // End of namespace ecto.
graphstats_collector(graph_stats_type &gs)
Definition: profile.hpp:58
unsigned long read_tsc()
Definition: std_map_indexing_suite.hpp:20
graph_stats_type & gs_
Definition: profile.hpp:55
#define ECTO_EXPORT
Definition: util.hpp:49
Definition: parameters.hpp:11
Definition: profile.hpp:86
graph_stats_type()
Definition: profile.hpp:46
Definition: profile.hpp:53
boost::posix_time::time_duration cumulative_time
Definition: profile.hpp:47
Definition: profile.hpp:75
uint64_t total_ticks
Definition: profile.hpp:79
const unsigned long start_tick
Definition: profile.hpp:57
~stats_collector()
Definition: profile.hpp:100
ptime_t universal_time()
stats_collector(const std::string &n, stats_type &stats)
Definition: profile.hpp:92
std::string as_string(graph::graph_t &g) const
const boost::posix_time::ptime start_time
Definition: profile.hpp:56
const unsigned long start
Definition: profile.hpp:88
~graphstats_collector()
Definition: profile.hpp:65
Definition: profile.hpp:44
unsigned ncalls
Definition: profile.hpp:78
Definition: types.hpp:46
uint64_t cumulative_ticks
Definition: profile.hpp:48
bool on
Definition: profile.hpp:80
stats_type & stats
Definition: profile.hpp:89
const std::string & instancename
Definition: profile.hpp:90