Adaptagrams
timer.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libavoid - Fast, Incremental, Object-avoiding Line Router
5  *
6  * Copyright (C) 2004-2013 Monash University
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  * See the file LICENSE.LGPL distributed with the library.
13  *
14  * Licensees holding a valid commercial license may use this file in
15  * accordance with the commercial license agreement provided with the
16  * library.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * Author(s): Michael Wybrow
23 */
24 
25 
26 #ifndef AVOID_TIMER_H
27 #define AVOID_TIMER_H
28 
29 #include <ctime>
30 
31 namespace Avoid {
32 
33 //#define AVOID_PROFILE
34 
35 #ifndef AVOID_PROFILE
36 
37  #define TIMER_START(r, t) do {} while(0)
38  #define TIMER_STOP(r) do {} while(0)
39  #define TIMER_VAR_ADD(r, n, v) do {} while(0)
40  #define TIMER_VAR_MAX(r, n, v) do {} while(0)
41 
42 #else
43 
44  #define TIMER_START(r, t) r->timers.initialise(t); r->timers.start()
45  #define TIMER_STOP(r) r->timers.stop()
46  #define TIMER_VAR_ADD(r, n, v) r->timers.varIncrement(n, v);
47  #define TIMER_VAR_MAX(r, n, v) r->timers.varMax(n, v)
48 
49 typedef unsigned long long int bigclock_t;
50 
51 enum TimerIndex
52 {
53  tmAdd,
54  tmDel,
55  tmMov,
56  tmPth,
57  tmOrthogGraph,
58  tmOrthogRoute,
59  tmOrthogCentre,
60  tmOrthogNudge,
61  tmHyperedgeForest,
62  tmHyperedgeMTST,
63  tmHyperedgeImprove,
64  tmHyperedgeAlt,
65  tmCount
66 };
67 
68 static const bool timerStart = true;
69 static const bool timerDelay = false;
70 
71 static const size_t TIMER_VARIABLES_COUNT = 2;
72 
73 class Timer
74 {
75  public:
76  Timer();
77  void initialise(const TimerIndex t);
78  void start(void);
79  void stop(void);
80  void reset(void);
81  void varIncrement(size_t i, unsigned int val);
82  void varMax(size_t i, unsigned int val);
83 
84  void print(TimerIndex, FILE *fp);
85  void printAll(FILE *fp);
86  void printHyperedgePaper(FILE *fp);
87 
88  private:
89  clock_t m_start_time[tmCount];
90  bigclock_t m_total_time[tmCount];
91  int m_tally[tmCount];
92  clock_t m_max_time[tmCount];
93  unsigned int m_variables[tmCount][TIMER_VARIABLES_COUNT];
94 
95  bool m_is_running;
96  TimerIndex m_type;
97  TimerIndex m_last_type;
98 };
99 
100 #endif
101 
102 }
103 
104 #endif
libavoid: Object-avoiding orthogonal and polyline connector routing library.
Definition: actioninfo.cpp:33