blob: 37f5568a125c15fb5591f05a5b16a66292ddce78 [file] [log] [blame]
Angus Kong0ae28bd2013-02-13 14:56:04 -08001// Ceres Solver - A fast non-linear least squares minimizer
2// Copyright 2012 Google Inc. All rights reserved.
3// http://code.google.com/p/ceres-solver/
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 notice,
9// this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13// * Neither the name of Google Inc. nor the names of its contributors may be
14// used to endorse or promote products derived from this software without
15// 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// Author: strandmark@google.com (Petter Strandmark)
30
31#ifndef CERES_INTERNAL_WALL_TIME_H_
32#define CERES_INTERNAL_WALL_TIME_H_
33
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070034#include <map>
35#include <string>
36#include "ceres/internal/port.h"
37#include "ceres/stringprintf.h"
38#include "glog/logging.h"
39
Angus Kong0ae28bd2013-02-13 14:56:04 -080040namespace ceres {
41namespace internal {
42
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070043// Returns time, in seconds, from some arbitrary starting point. If
44// OpenMP is available then the high precision openmp_get_wtime()
45// function is used. Otherwise on unixes, gettimeofday is used. The
46// granularity is in seconds on windows systems.
Angus Kong0ae28bd2013-02-13 14:56:04 -080047double WallTimeInSeconds();
48
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070049// Log a series of events, recording for each event the time elapsed
50// since the last event and since the creation of the object.
51//
52// The information is output to VLOG(3) upon destruction. A
53// name::Total event is added as the final event right before
54// destruction.
55//
56// Example usage:
57//
58// void Foo() {
59// EventLogger event_logger("Foo");
60// Bar1();
61// event_logger.AddEvent("Bar1")
62// Bar2();
63// event_logger.AddEvent("Bar2")
64// Bar3();
65// }
66//
67// Will produce output that looks like
68//
69// Foo
70// Bar1: time1 time1
71// Bar2: time2 time1 + time2;
72// Total: time3 time1 + time2 + time3;
73class EventLogger {
74 public:
75 explicit EventLogger(const string& logger_name);
76 ~EventLogger();
77 void AddEvent(const string& event_name);
78
79 private:
80 const double start_time_;
81 double last_event_time_;
82 string events_;
83};
84
Angus Kong0ae28bd2013-02-13 14:56:04 -080085} // namespace internal
86} // namespace ceres
87
88#endif // CERES_INTERNAL_WALL_TIME_H_