Fix semdiff syntactic output
[hiphop-php.git] / hphp / util / timer.h
blob59565d4941fae873c81fe360fb23c3fb534335e8
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_TIMER_H_
18 #define incl_HPHP_TIMER_H_
20 #include <cstdint>
21 #include <string>
23 #include <folly/portability/SysResource.h>
24 #include <folly/portability/SysTime.h>
26 #include "hphp/util/compatibility.h"
28 namespace HPHP {
29 ///////////////////////////////////////////////////////////////////////////////
32 * Timing execution of block of codes.
34 struct Timer {
35 enum Type {
36 WallTime,
37 SystemCPU,
38 UserCPU,
39 TotalCPU,
41 enum ReportType {
42 Log,
43 Stderr,
44 Trace,
46 enum Who {
47 Self = RUSAGE_SELF,
48 Children = RUSAGE_CHILDREN,
49 #ifdef RUSAGE_THREAD
50 Thread = RUSAGE_THREAD,
51 #endif
54 public:
55 explicit Timer(Type type, const char *name = nullptr, ReportType r = Log);
56 ~Timer();
58 static void GetRealtimeTime(timespec &sp);
59 static void GetMonotonicTime(timespec &sp);
60 static int64_t GetCurrentTimeMicros();
61 static int64_t GetRusageMicros(Type t, Who who);
62 static int64_t GetThreadCPUTimeNanos();
63 const char *getName() const;
64 int64_t getMicroSeconds() const;
65 void report() const;
67 private:
68 Type m_type;
69 ReportType m_report;
70 std::string m_name;
71 int64_t m_start;
73 int64_t measure() const;
76 ///////////////////////////////////////////////////////////////////////////////
78 struct SlowTimer {
79 SlowTimer(int64_t msThreshold, const char *location, const char *info);
80 ~SlowTimer();
82 int64_t getTime() const;
84 private:
85 Timer m_timer;
86 int64_t m_msThreshold;
87 std::string m_location;
88 std::string m_info;
91 ///////////////////////////////////////////////////////////////////////////////
93 extern __thread int64_t s_extra_request_nanoseconds;
95 int gettime(clockid_t, struct timespec*);
96 int64_t gettime_ns(clockid_t);
99 * Computes the difference between two timespec objects in microseconds.
101 int64_t gettime_diff_us(const timespec&, const timespec&);
103 ///////////////////////////////////////////////////////////////////////////////
106 #endif // incl_HPHP_TIMER_H_