Optimize struct element initialization
[hiphop-php.git] / hphp / runtime / vm / workload-stats.h
blob53820834761d32f351a1132254a22d52b9628e66
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>
21 namespace HPHP {
23 // WorkloadStats is used to track per request timing for different states
24 // of the VM. At the entrypoint to a change of vm state a WorkloadStats object
25 // should be made to guard the state change with appropriate timers and
26 // counters.
28 // The states tracked are:
29 // - In a request (this is a superset of the interpreter state)
30 // - In the interpreter through Dispatch, or DispatchBB (interpOne disregarded)
31 // - In the JIT (currently tracks time inside the translate routine)
33 // Note the time in the TC is not tracked. This is roughly:
34 // Time in request - Time in interp
36 // This gives us the relative interp time formula of:
37 // Relative interp time = Time in interp / Time in request
38 struct WorkloadStats final {
39 enum State {
40 InRequest,
41 // -> InInterp Okay (entering Dispatch loop)
42 // -> InTrans Okay (entering translate)
43 InInterp,
44 // -> InRequest Okay (leaving the dispatch loop)
45 // -> InTrans Okay (entering translate)
46 InTrans,
47 // -> InRequest Okay (leaving translate)
48 // -> InInterp Okay (leaving translate)
51 explicit WorkloadStats(State guardedState);
52 ~WorkloadStats();
54 WorkloadStats (const WorkloadStats&) = delete;
55 WorkloadStats& operator=(const WorkloadStats&) = delete;
57 static int64_t GetAndResetAvgRelativeInterp();
58 static void EnsureInit();