Timer.h revision 4ba3999e714c73ef52a21b0d59f705c0cad98810
1//===-- Timer.h -------------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_Timer_h_
11#define liblldb_Timer_h_
12#if defined(__cplusplus)
13
14#include <memory>
15#include <stdio.h>
16#include "lldb/lldb-private.h"
17#include "lldb/Host/TimeValue.h"
18
19namespace lldb_private {
20
21//----------------------------------------------------------------------
22/// @class Timer Timer.h "lldb/Core/Timer.h"
23/// @brief A timer class that simplifies common timing metrics.
24///
25/// A scoped timer class that allows a variety of pthread mutex
26/// objects to have a mutex locked when a Timer::Locker
27/// object is created, and unlocked when it goes out of scope or
28/// when the Timer::Locker::Reset(pthread_mutex_t *)
29/// is called. This provides an exception safe way to lock a mutex
30/// in a scope.
31//----------------------------------------------------------------------
32
33class Timer
34{
35public:
36    static void
37    Initialize ();
38
39    //--------------------------------------------------------------
40    /// Default constructor.
41    //--------------------------------------------------------------
42    Timer(const char *category, const char *format, ...);
43
44    //--------------------------------------------------------------
45    /// Desstructor
46    //--------------------------------------------------------------
47    ~Timer();
48
49    void
50    Dump ();
51
52    static void
53    SetDisplayDepth (uint32_t depth);
54
55    static void
56    SetQuiet (bool value);
57
58    static void
59    DumpCategoryTimes (Stream *s);
60
61    static void
62    ResetCategoryTimes ();
63
64protected:
65
66    void
67    ChildStarted (const TimeValue& time);
68
69    void
70    ChildStopped (const TimeValue& time);
71
72    uint64_t
73    GetTotalElapsedNanoSeconds();
74
75    uint64_t
76    GetTimerElapsedNanoSeconds();
77
78    //--------------------------------------------------------------
79    /// Member variables
80    //--------------------------------------------------------------
81    const char *m_category;
82    TimeValue m_total_start;
83    TimeValue m_timer_start;
84    uint64_t m_total_ticks; // Total running time for this timer including when other timers below this are running
85    uint64_t m_timer_ticks; // Ticks for this timer that do not include when other timers below this one are running
86    static uint32_t g_depth;
87    static uint32_t g_display_depth;
88    static FILE * g_file;
89private:
90    Timer();
91    DISALLOW_COPY_AND_ASSIGN (Timer);
92};
93
94} // namespace lldb_private
95
96#endif  // #if defined(__cplusplus)
97#endif // #ifndef liblldb_Timer_h_
98