Fix semdiff syntactic output
[hiphop-php.git] / hphp / util / bisector.h
blob625a4a6f75b2be6f7d63a3d7f915b02cf0185ff6
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 #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"
22 namespace HPHP {
25 Use this class to help bisect issues with optimizations.
27 Declare a bisector via:
29 BISECTOR(name);
31 Then guard each optimization by
33 if (name.go(<optional msg>)) {
34 // do the optimization
37 Then run via eg
39 env TRACE=bisector:1 name2=1000000 <program>
41 and look in the trace output to see how many times the optimization happened.
42 eg:
44 name : 0
45 name : 1
46 name : 2
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
55 later results.
58 struct BisectorHelper {
59 TRACE_SET_MOD(bisector)
61 explicit BisectorHelper(const char* e) : env(e) {
62 if (debug) {
63 auto const p1 = getenv((env + std::string("1")).c_str());
64 auto const p2 = getenv((env + std::string("2")).c_str());
65 if (p2) {
66 low = p1 ? atoi(p1) : 0;
67 high = atoi(p2);
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 : "");
76 return true;
78 return false;
80 private:
81 const char *env;
82 uint32_t low = 0u;
83 uint32_t high = 0u;
84 uint32_t count = 0u;
87 #define BISECTOR(name) static BisectorHelper name(#name);
91 #endif