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