FILENAME 3/4 - delete the old get_fun_path etc.
[hiphop-php.git] / hphp / util / bisector.h
blobb7d9a8236b7f7ff354759f56c32d53c52c9ee7d4
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 +----------------------------------------------------------------------+
16 #pragma once
18 #include "hphp/util/compilation-flags.h"
19 #include "hphp/util/trace.h"
21 namespace HPHP {
24 Use this class to help bisect issues with optimizations.
26 Declare a bisector via:
28 BISECTOR(name);
30 Then guard each optimization by
32 if (name.go(<optional msg>)) {
33 // do the optimization
36 Then run via eg
38 env TRACE=bisector:1 name2=1000000 <program>
40 and look in the trace output to see how many times the optimization happened.
41 eg:
43 name : 0
44 name : 1
45 name : 2
47 Now you can bisect down to the optimization thats causing issues by setting
48 name1 and name2 (name1 will default to 0 if not set). If name1 < name2 it
49 will run the optimizations in the interval [name1, name2). If name1 > name2
50 it will skip the optimizations in the interval [name2, name1).
52 Note that its usually best to at least start by bisecting with name2 only,
53 since (for some optimizations) skipping earlier optimizations can change
54 later results.
57 struct BisectorHelper {
58 TRACE_SET_MOD(bisector)
60 explicit BisectorHelper(const char* e) : env(e) {
61 if (debug) {
62 auto const p1 = getenv((env + std::string("1")).c_str());
63 auto const p2 = getenv((env + std::string("2")).c_str());
64 if (p2) {
65 low = p1 ? atoi(p1) : 0;
66 high = atoi(p2);
70 bool go(const char* msg = nullptr) {
71 if (!debug || (!high && !low)) return true;
72 if ((count++ - low) < (high - low)) {
73 FTRACE(1, "{} : {} {}\n",
74 env, count - 1, msg ? msg : "");
75 return true;
77 return false;
79 private:
80 const char *env;
81 uint32_t low = 0u;
82 uint32_t high = 0u;
83 uint32_t count = 0u;
86 #define BISECTOR(name) static BisectorHelper name(#name);