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 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/datatype-profiler.h"
18 #include "hphp/runtime/base/runtime-option.h"
22 DataTypeProfiler::DataTypeProfiler(std::string 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
) {
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;
84 DataTypeProfiler::~DataTypeProfiler() {
85 if (!enable_stacktrace_profiler
) return;
86 auto total
= m_uninit
.hits() +
91 m_persistent_string
.hits() +
93 m_persistent_vec
.hits() +
95 m_persistent_dict
.hits() +
97 m_persistent_keyset
.hits() +
99 m_persistent_darray
.hits() +
101 m_persistent_varray
.hits() +
113 fprintf(stderr
, "%s: total=%zu KindOfUninit=%.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%% "
126 "KindOfPersistentDict=%.1f%% "
128 "KindOfPersistentKeyset=%.1f%% "
129 "KindOfKeyset=%.1f%% "
130 "KindOfObject=%.1f%% "
131 "KindOfResource=%.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
);