/usr/include/hphp/util/trace.h is in hhvm-dev 3.11.1+dfsg-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | /*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2015 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_TRACE_H_
#define incl_HPHP_TRACE_H_
#include <string>
#include <vector>
#include <stdarg.h>
#include <folly/Format.h>
#include "hphp/util/assertions.h"
#include "hphp/util/portability.h"
#include "hphp/util/text-color.h"
/*
* Runtime-selectable trace facility. A trace statement has both a module and a
* level associated with it; Enable tracing a module by setting the TRACE
* environment variable to a comma-separated list of module:level pairs. E.g.:
*
* env TRACE=mcg:1,bcinterp:3,tmp0:1 ./hhvm/hhvm ...
*
* In a source file, select the compilation unit's module by calling the
* TRACE_SET_MOD macro. E.g.,
*
* TRACE_SET_MOD(mcg);
*
* ...
* TRACE(0, "See this for any trace-enabled build: %d\n", foo);
* TRACE(1, "Trace-level must be 1 or higher for this one\n");
*
* While the levels are arbitrary integers, code so far is following a
* rough convention of 1-5, where 1 is minimal and 5 is quite verbose.
*
* Normally trace information is printed to /tmp/hphp.log. You can
* override the environment variable HPHP_TRACE_FILE to change
* this. (Note you can set it to something like /dev/stderr or
* /dev/stdout if you want the logs printed to your terminal).
*
* When printing to the terminal, some traces will know how to use
* colorization. You can set HPHP_TRACE_TTY to tell the tracing
* facility to assume it should colorize even if the output file isn't
* obviously a tty.
*/
/*
* Trace levels can be bumped on a per-module, per-scope basis. This
* lets you run code that has a set of trace levels in a mode as if
* they were all higher.
*
* Example:
*
* {
* Trace::Bump bumper{Trace::mcg, 2};
* FTRACE(1, "asd\n"); // only fires at level >= 3
* }
* FTRACE(1, "asd\n"); // back to normal
*
*
* There is also support for conditionally bumping in the bumper:
*
* {
* Trace::Bump bumper{Trace::mcg, 2, somePredicate(foo)};
* // Only bumped if somePredicate(foo) returned true.
* }
*
* Note however that if you use that form, `somePredicate' will be
* evaluated even if tracing is off.
*/
namespace HPHP {
namespace Trace {
#define TRACE_MODULES \
TM(tprefix) /* Meta: prefix with string */ \
TM(traceAsync) /* Meta: lazy writes to disk */ \
TM(asmx64) \
TM(atomicvector) \
TM(bcinterp) \
TM(bisector) \
TM(class_load) \
TM(datablock) \
TM(decreftype) \
TM(debugger) \
TM(debuggerflow) \
TM(debuginfo) \
TM(dispatchBB) \
TM(emitter) \
TM(fixup) \
TM(fr) \
TM(gc) \
TM(heap) \
TM(heapreport) \
TM(hhas) \
TM(hhbbc) \
TM(hhbbc_dce) \
TM(hhbbc_dump) \
TM(hhbbc_emit) \
TM(hhbbc_index) \
TM(hhbbc_time) \
TM(hhbbc_iface) \
TM(hhbc) \
TM(vasm) \
TM(vasm_copy) \
TM(vasm_phi) \
TM(hhir) \
TM(hhirTracelets) \
TM(hhir_cfg) \
TM(hhir_checkhoist) \
TM(hhir_dce) \
TM(hhir_store) \
TM(hhir_alias) \
TM(hhir_loop) \
TM(hhir_load) \
TM(hhir_refineTmps) \
TM(hhir_gvn) \
TM(hhir_refcount) \
TM(hhir_licm) \
TM(hhir_phi) \
TM(layout) \
TM(llvm) \
TM(llvm_count) \
TM(inlining) \
TM(instancebits) \
TM(intercept) \
TM(interpOne) \
TM(jittime) \
TM(libxml) \
TM(mcg) \
TM(mcgstats) \
TM(minstr) \
TM(pgo) \
TM(printir) \
TM(rat) \
TM(refcount) \
TM(regalloc) \
TM(region) \
TM(reusetc) \
TM(ringbuffer) \
TM(runtime) \
TM(servicereq) \
TM(simplify) \
TM(mm) \
TM(stat) \
TM(statgroups) \
TM(stats) \
TM(targetcache) \
TM(tcspace) \
TM(trans) \
TM(treadmill) \
TM(txdeps) \
TM(txlease) \
TM(typeProfile) \
TM(unwind) \
TM(ustubs) \
TM(xenon) \
TM(objprof) \
TM(heapgraph) \
TM(xls) \
/* Stress categories, to exercise rare paths */ \
TM(stress_txInterpPct) \
TM(stress_txInterpSeed) \
/* Jit bisection interval */ \
TM(txOpBisectLow) \
TM(txOpBisectHigh) \
/* Temporary categories, to save compilation time */ \
TM(tmp0) TM(tmp1) TM(tmp2) TM(tmp3) \
TM(tmp4) TM(tmp5) TM(tmp6) TM(tmp7) \
TM(tmp8) TM(tmp9) TM(tmp10) TM(tmp11) \
TM(tmp12) TM(tmp13) TM(tmp14) TM(tmp15)
enum Module {
#define TM(x) \
x,
TRACE_MODULES
#undef TM
NumModules
};
//////////////////////////////////////////////////////////////////////
/*
* S-expression style structured pretty-printing. Implement
* std::string pretty() const { }, with the convention that
* nested structures are notated as lisp-style trees:
*
* (<typename> field0 field1)
*
* E.g.:
* (Location Stack 1)
*
* The repetitve prettyNode() templates are intended to aid
* implementing pretty().
*/
template<typename P1>
std::string prettyNode(const char* name, const std::vector<P1>& vec) {
using std::string;
std::string retval = string("(") + string(name) + string(" ");
for(size_t i = 0; i < vec.size(); i++) {
retval += vec[i].pretty();
if (i != vec.size() - 1) {
retval += string(" ");
}
}
return retval + string(")");
}
template<typename P1>
std::string prettyNode(const char* name, const P1& p1) {
using std::string;
return string("(") + string(name) + string(" ") +
p1.pretty() +
string(")");
}
template<> std::string prettyNode(const char* name, const std::string& s);
template<typename P1, typename P2>
std::string prettyNode(const char* name, const P1& p1, const P2& p2) {
using std::string;
return string("(") + string(name) + string(" ") +
p1.pretty() + string(" ") + p2.pretty() +
string(")");
}
void traceRelease(ATTRIBUTE_PRINTF_STRING const char*, ...)
ATTRIBUTE_PRINTF(1,2);
void traceRelease(const std::string& s);
template<typename... Args>
void ftraceRelease(Args&&... args) {
traceRelease("%s", folly::format(std::forward<Args>(args)...).str().c_str());
}
// Trace to the global ring buffer and the normal TRACE destination.
#define TRACE_RB(n, ...) \
ONTRACE(n, HPHP::Trace::traceRingBufferRelease(__VA_ARGS__)); \
TRACE(n, __VA_ARGS__);
void traceRingBufferRelease(ATTRIBUTE_PRINTF_STRING const char* fmt, ...)
ATTRIBUTE_PRINTF(1,2);
extern int levels[NumModules];
extern __thread int tl_levels[NumModules];
const char* moduleName(Module mod);
inline bool moduleEnabledRelease(Module tm, int level = 1) {
return levels[tm] + tl_levels[tm] >= level;
}
// Trace::Bump that is on for release tracing.
struct BumpRelease {
BumpRelease(Module mod, int adjust, bool condition = true)
: m_live(condition)
, m_mod(mod)
, m_adjust(adjust)
{
if (m_live) tl_levels[m_mod] -= m_adjust;
}
BumpRelease(BumpRelease&& o) noexcept
: m_live(o.m_live)
, m_mod(o.m_mod)
, m_adjust(o.m_adjust)
{
o.m_live = false;
}
~BumpRelease() {
if (m_live) tl_levels[m_mod] += m_adjust;
}
BumpRelease(const BumpRelease&) = delete;
BumpRelease& operator=(const BumpRelease&) = delete;
private:
bool m_live;
Module m_mod;
int m_adjust;
};
//////////////////////////////////////////////////////////////////////
#if (defined(DEBUG) || defined(USE_TRACE)) /* { */
# ifndef USE_TRACE
# define USE_TRACE 1
# endif
//////////////////////////////////////////////////////////////////////
/*
* Implementation of for when tracing is enabled.
*/
inline bool moduleEnabled(Module tm, int level = 1) {
return moduleEnabledRelease(tm, level);
}
inline int moduleLevel(Module tm) { return levels[tm]; }
#define HPHP_TRACE
const bool enabled = true;
#define ONTRACE_MOD(module, n, x) do { \
if (HPHP::Trace::moduleEnabled(module, n)) { \
x; \
} } while(0)
#define ONTRACE(n, x) ONTRACE_MOD(TRACEMOD, n, x)
#define TRACE(n, ...) ONTRACE(n, HPHP::Trace::trace(__VA_ARGS__))
#define FTRACE(n, ...) \
ONTRACE(n, HPHP::Trace::trace("%s", \
folly::format(__VA_ARGS__).str().c_str()))
#define TRACE_MOD(mod, level, ...) \
ONTRACE_MOD(mod, level, HPHP::Trace::trace(__VA_ARGS__))
#define FTRACE_MOD(mod, level, ...) \
ONTRACE_MOD(mod, level, HPHP::Trace::trace("%s", \
folly::format(__VA_ARGS__).str().c_str()))
#define TRACE_SET_MOD(name) \
UNUSED static const HPHP::Trace::Module TRACEMOD = HPHP::Trace::name;
/*
* The Indent struct and ITRACE are used for tracing with nested
* indentation. Create an Indent object on the stack to increase the nesting
* level, then use ITRACE just as you would use FTRACE.
*/
extern __thread int indentDepth;
struct Indent {
explicit Indent(int n = 2) : n(n) { indentDepth += n; }
~Indent() { indentDepth -= n; }
int n;
};
// See doc comment above for usage.
using Bump = BumpRelease;
inline std::string indent() {
return std::string(indentDepth, ' ');
}
template<typename... Args>
inline void itraceImpl(const char* fmtRaw, Args&&... args) {
auto const fmt = indent() + fmtRaw;
Trace::ftraceRelease(fmt, std::forward<Args>(args)...);
}
#define ITRACE(level, ...) ONTRACE((level), Trace::itraceImpl(__VA_ARGS__));
#define ITRACE_MOD(mod, level, ...) \
ONTRACE_MOD(mod, level, Trace::itraceImpl(__VA_ARGS__));
void trace(ATTRIBUTE_PRINTF_STRING const char *, ...) ATTRIBUTE_PRINTF(1,2);
void trace(const std::string&);
template<typename Pretty>
inline void trace(Pretty p) { trace(p.pretty() + std::string("\n")); }
void vtrace(ATTRIBUTE_PRINTF_STRING const char *fmt, va_list args)
ATTRIBUTE_PRINTF(1,0);
void dumpRingbuffer();
//////////////////////////////////////////////////////////////////////
#else /* } (defined(DEBUG) || defined(USE_TRACE)) { */
//////////////////////////////////////////////////////////////////////
/*
* Implementation for when tracing is disabled.
*/
#define ONTRACE(...) do { } while (0)
#define TRACE(...) do { } while (0)
#define FTRACE(...) do { } while (0)
#define TRACE_MOD(...) do { } while (0)
#define FTRACE_MOD(...) do { } while (0)
#define TRACE_SET_MOD(name) \
DEBUG_ONLY static const HPHP::Trace::Module TRACEMOD = HPHP::Trace::name;
#define ITRACE(...) do { } while (0)
#define ITRACE_MOD(...) do { } while (0)
struct Indent {
Indent() {
always_assert(true && "If this struct is completely empty we get unused "
"variable warnings in code that uses it.");
}
};
inline std::string indent() { return std::string(); }
struct Bump {
Bump(Module mod, int adjust, bool condition = true) {
always_assert(true && "If this struct is completely empty we get unused "
"variable warnings in code that uses it.");
}
};
const bool enabled = false;
inline void trace(const char*, ...) { }
inline void trace(const std::string&) { }
inline void vtrace(const char*, va_list) { }
inline bool moduleEnabled(Module t, int level = 1) { return false; }
inline int moduleLevel(Module tm) { return 0; }
//////////////////////////////////////////////////////////////////////
#endif /* } (defined(DEBUG) || defined(USE_TRACE)) */
} // Trace
// Optional color utility for trace dumps; when output is a tty or
// when we've been told to assume it is.
inline const char* color(const char* color) {
static auto const shouldColorize = []() -> bool {
auto const traceEnv = getenv("HPHP_TRACE_FILE");
auto const assumeTTY = getenv("HPHP_TRACE_TTY");
if (assumeTTY) return true;
if (!traceEnv) return false;
return
!strcmp(traceEnv, "/dev/stdout") ? isatty(1) :
!strcmp(traceEnv, "/dev/stderr") ? isatty(2) :
false;
}();
return shouldColorize ? color : "";
}
inline std::string color(const char* fg, const char* bg) {
auto const s = add_bgcolor(fg, bg);
return color(s.c_str());
}
//////////////////////////////////////////////////////////////////////
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(has_toString, toString);
} // HPHP
namespace folly {
template<typename Val>
struct FormatValue<Val,
typename std::enable_if<
HPHP::has_toString<Val, std::string() const>::value &&
// This is here because MSVC decides that StringPiece matches
// both this overload as well as the FormatValue overload for
// string-y types in folly itself.
!std::is_same<Val, StringPiece>::value,
void
>::type> {
explicit FormatValue(const Val& val) : m_val(val) {}
template<typename Callback> void format(FormatArg& arg, Callback& cb) const {
format_value::formatString(m_val.toString(), arg, cb);
}
private:
const Val& m_val;
};
}
#endif /* incl_HPHP_TRACE_H_ */
|