Add sub-controls for Hack array compat runtime checks
[hiphop-php.git] / hphp / runtime / base / datatype-profiler.cpp
blobeaf36239139951dffc6c890667d75e975e5dac30
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 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/datatype-profiler.h"
19 namespace HPHP {
21 DataTypeProfiler::DataTypeProfiler(std::string name)
22 : m_name(name)
23 , m_uninit(name + "=KindOfUninit")
24 , m_null(name + "=KindOfNull")
25 , m_boolean(name + "=KindOfBoolean")
26 , m_int(name + "=KindOfInt64")
27 , m_double(name + "=KindOfDouble")
28 , m_persistent_string(name + "=KindOfPersistentString")
29 , m_string(name + "=KindOfString")
30 , m_persistent_array(name + "=KindOfPersistentArray")
31 , m_array(name + "=KindOfArray")
32 , m_persistent_vec(name + "=KindOfPersistentVec")
33 , m_vec(name + "=KindOfVec")
34 , m_persistent_dict(name + "=KindOfPersistentDict")
35 , m_dict(name + "=KindOfDict")
36 , m_persistent_keyset(name + "=KindOfPersistentKeyset")
37 , m_keyset(name + "=KindOfKeyset")
38 , m_object(name + "=KindOfObject")
39 , m_resource(name + "=KindOfResource")
40 , m_ref(name + "=KindOfRef")
43 DataType DataTypeProfiler::operator()(DataType type) {
44 switch (type) {
45 case KindOfUninit: m_uninit.count(); break;
46 case KindOfNull: m_null.count(); break;
47 case KindOfBoolean: m_boolean.count(); break;
48 case KindOfInt64: m_int.count(); break;
49 case KindOfDouble: m_double.count(); break;
50 case KindOfPersistentString: m_persistent_string.count(); break;
51 case KindOfString: m_string.count(); break;
52 case KindOfPersistentVec: m_persistent_vec.count(); break;
53 case KindOfVec: m_vec.count(); break;
54 case KindOfPersistentDict: m_persistent_dict.count(); break;
55 case KindOfDict: m_dict.count(); break;
56 case KindOfPersistentKeyset: m_persistent_keyset.count(); break;
57 case KindOfKeyset: m_keyset.count(); break;
58 case KindOfPersistentArray: m_persistent_array.count(); break;
59 case KindOfArray: m_array.count(); break;
60 case KindOfObject: m_object.count(); break;
61 case KindOfResource: m_resource.count(); break;
62 case KindOfRef: m_ref.count(); break;
64 return type;
67 DataTypeProfiler::~DataTypeProfiler() {
68 if (!enable_stacktrace_profiler) return;
69 auto total = m_uninit.hits() +
70 m_null.hits() +
71 m_boolean.hits() +
72 m_int.hits() +
73 m_double.hits() +
74 m_persistent_string.hits() +
75 m_string.hits() +
76 m_persistent_vec.hits() +
77 m_vec.hits() +
78 m_persistent_dict.hits() +
79 m_dict.hits() +
80 m_persistent_keyset.hits() +
81 m_keyset.hits() +
82 m_persistent_array.hits() +
83 m_array.hits() +
84 m_object.hits() +
85 m_resource.hits() +
86 m_ref.hits();
87 if (!total) return;
88 fprintf(stderr, "%s: total=%zu KindOfUninit=%.1f%% "
89 "KindOfNull=%.1f%% "
90 "KindOfBoolean=%.1f%% "
91 "KindOfInt64=%.1f%% "
92 "KindOfDouble=%.1f%% "
93 "KindOfPersistentString=%.1f%% "
94 "KindOfString=%.1f%% "
95 "KindOfPersistentArray=%.1f%% "
96 "KindOfArray=%.1f%% "
97 "KindOfPersistentVec=%.1f%% "
98 "KindOfVec=%.1f%% "
99 "KindOfPersistentDict=%.1f%% "
100 "KindOfDict=%.1f%% "
101 "KindOfPersistentKeyset=%.1f%% "
102 "KindOfKeyset=%.1f%% "
103 "KindOfObject=%.1f%% "
104 "KindOfResource=%.1f%% "
105 "KindOfRef=%.1f%%\n",
106 m_name.c_str(), total,
107 100.0 * m_uninit.hits() / total,
108 100.0 * m_null.hits() / total,
109 100.0 * m_boolean.hits() / total,
110 100.0 * m_int.hits() / total,
111 100.0 * m_double.hits() / total,
112 100.0 * m_persistent_string.hits() / total,
113 100.0 * m_string.hits() / total,
114 100.0 * m_persistent_array.hits() / total,
115 100.0 * m_array.hits() / total,
116 100.0 * m_persistent_vec.hits() / total,
117 100.0 * m_vec.hits() / total,
118 100.0 * m_persistent_dict.hits() / total,
119 100.0 * m_dict.hits() / total,
120 100.0 * m_persistent_keyset.hits() / total,
121 100.0 * m_keyset.hits() / total,
122 100.0 * m_object.hits() / total,
123 100.0 * m_resource.hits() / total,
124 100.0 * m_ref.hits() / total);