Make comparison IR ops layout agnostic
[hiphop-php.git] / hphp / runtime / base / datatype-profiler.cpp
blob3df6ca1b1c0ecf18ad5e306a35f0095b2ebe98c3
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"
18 #include "hphp/runtime/base/runtime-option.h"
20 namespace HPHP {
22 DataTypeProfiler::DataTypeProfiler(std::string name)
23 : m_name(name)
24 , m_uninit(name + "=KindOfUninit")
25 , m_null(name + "=KindOfNull")
26 , m_boolean(name + "=KindOfBoolean")
27 , m_int(name + "=KindOfInt64")
28 , m_double(name + "=KindOfDouble")
29 , m_persistent_string(name + "=KindOfPersistentString")
30 , m_string(name + "=KindOfString")
31 , m_persistent_darray(name + "=KindOfPersistentDArray")
32 , m_darray(name + "=KindOfDArray")
33 , m_persistent_varray(name + "=KindOfPersistentVArray")
34 , m_varray(name + "=KindOfVArray")
35 , m_persistent_vec(name + "=KindOfPersistentVec")
36 , m_vec(name + "=KindOfVec")
37 , m_persistent_dict(name + "=KindOfPersistentDict")
38 , m_dict(name + "=KindOfDict")
39 , m_persistent_keyset(name + "=KindOfPersistentKeyset")
40 , m_keyset(name + "=KindOfKeyset")
41 , m_object(name + "=KindOfObject")
42 , m_resource(name + "=KindOfResource")
43 , m_func(name + "=KindOfFunc")
44 , m_rfunc(name + "=KindOfRFunc")
45 , m_class(name + "=KindOfClass")
46 , m_clsmeth(name + "=KindOfClsMeth")
47 , m_rclsmeth(name + "=KindOfRClsMeth")
48 , m_record(name + "=KindOfRecord")
49 , m_lclass(name + "=KindOfLazyClass")
52 DataType DataTypeProfiler::operator()(DataType type) {
53 switch (type) {
54 case KindOfUninit: m_uninit.count(); break;
55 case KindOfNull: m_null.count(); break;
56 case KindOfBoolean: m_boolean.count(); break;
57 case KindOfInt64: m_int.count(); break;
58 case KindOfDouble: m_double.count(); break;
59 case KindOfPersistentString: m_persistent_string.count(); break;
60 case KindOfString: m_string.count(); break;
61 case KindOfPersistentVec: m_persistent_vec.count(); break;
62 case KindOfVec: m_vec.count(); break;
63 case KindOfPersistentDict: m_persistent_dict.count(); break;
64 case KindOfDict: m_dict.count(); break;
65 case KindOfPersistentKeyset: m_persistent_keyset.count(); break;
66 case KindOfKeyset: m_keyset.count(); break;
67 case KindOfPersistentDArray: m_persistent_darray.count(); break;
68 case KindOfDArray: m_darray.count(); break;
69 case KindOfPersistentVArray: m_persistent_varray.count(); break;
70 case KindOfVArray: m_varray.count(); break;
71 case KindOfObject: m_object.count(); break;
72 case KindOfResource: m_resource.count(); break;
73 case KindOfRFunc: m_rfunc.count(); break;
74 case KindOfFunc: m_func.count(); break;
75 case KindOfClass: m_class.count(); break;
76 case KindOfLazyClass: m_lclass.count(); break;
77 case KindOfClsMeth: m_clsmeth.count(); break;
78 case KindOfRClsMeth: m_rclsmeth.count(); break;
79 case KindOfRecord: m_record.count(); break;
81 return type;
84 DataTypeProfiler::~DataTypeProfiler() {
85 if (!enable_stacktrace_profiler) return;
86 auto total = m_uninit.hits() +
87 m_null.hits() +
88 m_boolean.hits() +
89 m_int.hits() +
90 m_double.hits() +
91 m_persistent_string.hits() +
92 m_string.hits() +
93 m_persistent_vec.hits() +
94 m_vec.hits() +
95 m_persistent_dict.hits() +
96 m_dict.hits() +
97 m_persistent_keyset.hits() +
98 m_keyset.hits() +
99 m_persistent_darray.hits() +
100 m_darray.hits() +
101 m_persistent_varray.hits() +
102 m_varray.hits() +
103 m_object.hits() +
104 m_resource.hits() +
105 m_func.hits() +
106 m_rfunc.hits() +
107 m_class.hits() +
108 m_clsmeth.hits() +
109 m_rclsmeth.hits() +
110 m_record.hits() +
111 m_lclass.hits();
112 if (!total) return;
113 fprintf(stderr, "%s: total=%zu KindOfUninit=%.1f%% "
114 "KindOfNull=%.1f%% "
115 "KindOfBoolean=%.1f%% "
116 "KindOfInt64=%.1f%% "
117 "KindOfDouble=%.1f%% "
118 "KindOfPersistentString=%.1f%% "
119 "KindOfString=%.1f%% "
120 "KindOfPersistentDArray=%.1f%% "
121 "KindOfDArray=%.1f%% "
122 "KindOfPersistentVArray=%.1f%% "
123 "KindOfVArray=%.1f%% "
124 "KindOfPersistentVec=%.1f%% "
125 "KindOfVec=%.1f%% "
126 "KindOfPersistentDict=%.1f%% "
127 "KindOfDict=%.1f%% "
128 "KindOfPersistentKeyset=%.1f%% "
129 "KindOfKeyset=%.1f%% "
130 "KindOfObject=%.1f%% "
131 "KindOfResource=%.1f%% "
132 "KindOfFunc=%.1f%% "
133 "KindOfRFunc=%.1f%%"
134 "KindOfClass=%.1f%% "
135 "KindOfClsMeth=%.1f%% "
136 "KindOfRClsMeth=%.1f%% "
137 "KindOfRecord=%.1f%% "
138 "KindOfLazyClass=%.1f%% ",
139 m_name.c_str(), total,
140 100.0 * m_uninit.hits() / total,
141 100.0 * m_null.hits() / total,
142 100.0 * m_boolean.hits() / total,
143 100.0 * m_int.hits() / total,
144 100.0 * m_double.hits() / total,
145 100.0 * m_persistent_string.hits() / total,
146 100.0 * m_string.hits() / total,
147 100.0 * m_persistent_darray.hits() / total,
148 100.0 * m_darray.hits() / total,
149 100.0 * m_persistent_varray.hits() / total,
150 100.0 * m_varray.hits() / total,
151 100.0 * m_persistent_vec.hits() / total,
152 100.0 * m_vec.hits() / total,
153 100.0 * m_persistent_dict.hits() / total,
154 100.0 * m_dict.hits() / total,
155 100.0 * m_persistent_keyset.hits() / total,
156 100.0 * m_keyset.hits() / total,
157 100.0 * m_object.hits() / total,
158 100.0 * m_resource.hits() / total,
159 100.0 * m_func.hits() / total,
160 100.0 * m_rfunc.hits() / total,
161 100.0 * m_class.hits() / total,
162 100.0 * m_clsmeth.hits() / total,
163 100.0 * m_rclsmeth.hits() / total,
164 100.0 * m_record.hits() / total,
165 100.0 * m_lclass.hits() / total);