2 +----------------------------------------------------------------------+
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 +----------------------------------------------------------------------+
21 #include <boost/variant.hpp>
24 #include "hphp/util/compact-vector.h"
25 #include "hphp/util/low-ptr.h"
26 #include "hphp/util/match.h"
27 #include "hphp/util/trace.h"
34 namespace HPHP
{ namespace HHBBC
{
36 //////////////////////////////////////////////////////////////////////
39 * String that must be a static string, and Array that must be a
42 using SString
= const StringData
*;
43 using LSString
= LowPtr
<const StringData
>;
44 using SArray
= const ArrayData
*;
47 using BytecodeVec
= CompactVector
<Bytecode
>;
50 * HHBC evaluation stack flavors.
52 enum class Flavor
{ C
, U
, CU
};
55 * Types of parameter preparation (or unknown).
57 enum class PrepKind
{ InOut
, Val
, Unknown
};
59 using LocalId
= uint32_t;
60 constexpr const LocalId NoLocalId
= -1;
62 * Special value used by StackElem::equivLoc to indicate that
63 * this element is a dup of the one below.
65 constexpr const LocalId StackDupId
= -2;
66 constexpr const LocalId StackThisId
= -3;
67 constexpr const LocalId MaxLocalId
= StackThisId
- 1;
69 using IterId
= uint32_t;
70 using BlockId
= uint32_t;
71 constexpr const BlockId NoBlockId
= -1;
72 using ExnNodeId
= uint32_t;
73 constexpr const ExnNodeId NoExnNodeId
= -1;
75 //////////////////////////////////////////////////////////////////////
78 * Many places in the code want to bump tracing levels by some amount
79 * for systemlib-related processing. This is the amount they all bump
82 constexpr int kSystemLibBump
= 10;
85 * Functions listed in the --trace functions list get trace level bumped by
88 constexpr int kTraceFuncBump
= -10;
91 * We may run the interpreter collecting stats and when trace is on
92 * the amount of noise is unbearable. This is to keep tracing out
93 * of stats collection.
95 constexpr int kStatsBump
= 50;
97 //////////////////////////////////////////////////////////////////////
99 void profile_memory(const char* what
, const char* when
, const std::string
&);
100 void summarize_memory();
103 using clock
= std::chrono::system_clock
;
104 using time_point
= clock::time_point
;
106 explicit trace_time(const char* what
,
107 const std::string
& extra
= std::string
{})
109 , start(clock::now())
112 profile_memory(what
, "start", extra
);
113 if (Trace::moduleEnabledRelease(Trace::hhbbc_time
, 1)) {
120 !extra
.empty() ? folly::format(" ({})", extra
).str() : extra
127 namespace C
= std::chrono
;
128 auto const end
= clock::now();
129 auto const elapsed
= C::duration_cast
<C::milliseconds
>(
132 profile_memory(what
, "end", extra
);
133 if (Trace::moduleEnabledRelease(Trace::hhbbc_time
, 1)) {
137 "{}: {}: {}ms elapsed\n",
138 ts(end
), what
, elapsed
.count())
144 trace_time(const trace_time
&) = delete;
145 trace_time
& operator=(const trace_time
&) = delete;
148 std::string
ts(time_point t
) {
150 auto tm
= std::chrono::system_clock::to_time_t(t
);
152 // Eliminate trailing newline from ctime_r.
161 //////////////////////////////////////////////////////////////////////