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 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_UTIL_BISECTOR_H_
17 #define incl_HPHP_UTIL_BISECTOR_H_
19 #include "hphp/util/compilation-flags.h"
20 #include "hphp/util/trace.h"
25 Use this class to help bisect issues with optimizations.
27 Declare a bisector via:
31 Then guard each optimization by
33 if (name.go(<optional msg>)) {
34 // do the optimization
39 env TRACE=bisector:1 name2=1000000 <program>
41 and look in the trace output to see how many times the optimization happened.
48 Now you can bisect down to the optimization thats causing issues by setting
49 name1 and name2 (name1 will default to 0 if not set). If name1 < name2 it
50 will run the optimizations in the interval [name1, name2). If name1 > name2
51 it will skip the optimizations in the interval [name2, name1).
53 Note that its usually best to at least start by bisecting with name2 only,
54 since (for some optimizations) skipping earlier optimizations can change
58 struct BisectorHelper
{
59 TRACE_SET_MOD(bisector
)
61 explicit BisectorHelper(const char* e
) : env(e
) {
63 auto const p1
= getenv((env
+ std::string("1")).c_str());
64 auto const p2
= getenv((env
+ std::string("2")).c_str());
66 low
= p1
? atoi(p1
) : 0;
71 bool go(const char* msg
= nullptr) {
72 if (!debug
|| (!high
&& !low
)) return true;
73 if ((count
++ - low
) < (high
- low
)) {
74 FTRACE(1, "{} : {} {}\n",
75 env
, count
- 1, msg
? msg
: "");
87 #define BISECTOR(name) static BisectorHelper name(#name);