ban traits that defines properties inherited via multiple paths if <<__SupportTraitDi...
[hiphop-php.git] / hphp / util / timer.h
blob977811cf1f0479241b039dc1b11166a8efba3e7b
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 #pragma once
19 #include <cstdint>
20 #include <string>
22 #include <folly/portability/SysResource.h>
23 #include <folly/portability/SysTime.h>
25 #include "hphp/util/compatibility.h"
27 namespace HPHP {
28 ///////////////////////////////////////////////////////////////////////////////
31 * Timing execution of block of codes.
33 struct Timer {
34 enum Type {
35 WallTime,
36 SystemCPU,
37 UserCPU,
38 TotalCPU,
40 enum ReportType {
41 Log,
42 Stderr,
43 Trace,
45 enum Who {
46 Self = RUSAGE_SELF,
47 Children = RUSAGE_CHILDREN,
48 #ifdef RUSAGE_THREAD
49 Thread = RUSAGE_THREAD,
50 #endif
53 public:
54 explicit Timer(Type type, const char *name = nullptr, ReportType r = Log);
55 ~Timer();
57 static void GetRealtimeTime(timespec &sp);
58 static void GetMonotonicTime(timespec &sp);
59 static int64_t GetCurrentTimeMicros();
60 static int64_t GetRusageMicros(Type t, Who who);
61 static int64_t GetThreadCPUTimeNanos();
62 const char *getName() const;
63 int64_t getMicroSeconds() const;
64 void report() const;
66 private:
67 Type m_type;
68 ReportType m_report;
69 std::string m_name;
70 int64_t m_start;
72 int64_t measure() const;
75 ///////////////////////////////////////////////////////////////////////////////
77 struct SlowTimer {
78 SlowTimer(int64_t msThreshold, const char *location, const char *info);
79 ~SlowTimer();
81 int64_t getTime() const;
83 private:
84 Timer m_timer;
85 int64_t m_msThreshold;
86 std::string m_location;
87 std::string m_info;
90 ///////////////////////////////////////////////////////////////////////////////
92 extern __thread int64_t s_extra_request_nanoseconds;
94 int gettime(clockid_t, struct timespec*);
95 int64_t gettime_ns(clockid_t);
98 * Computes the difference between two timespec objects in microseconds.
100 int64_t gettime_diff_us(const timespec&, const timespec&);
102 ///////////////////////////////////////////////////////////////////////////////