forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincref-profile.h
More file actions
110 lines (96 loc) · 3.74 KB
/
Copy pathincref-profile.h
File metadata and controls
110 lines (96 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#pragma once
#include <folly/dynamic.h>
#include <folly/Format.h>
#include "hphp/runtime/vm/jit/target-profile.h"
namespace HPHP { namespace jit {
///////////////////////////////////////////////////////////////////////////////
/*
* Profile the frequency of the 3 possible different behaviors for an IncRef
* instruction. Each execution must fall into exactly one of these categories:
*
* 1) Uncounted:
* the type was uncounted
* 2) Persistent:
* the type was refcounted and the value was persistent (so no inc happened)
* 3) Incremented:
* the count for the value was incremented.
*
*/
struct IncRefProfile {
uint32_t uncounted() const {
return total - refcounted;
}
uint32_t persistent() const {
return refcounted - incremented;
}
float percent(uint32_t value) const {
return total ? 100.0 * value / total : 0.0;
}
std::string toString() const {
return folly::sformat(
"total: {:4}\n uncounted: {:4} ({:.1f}%),\n persistent: {:4} ({:.1f}%),\n"
" incremented: {:4} ({:.1f}%)",
total,
uncounted(), percent(uncounted()),
persistent(), percent(persistent()),
incremented, percent(incremented)
);
}
folly::dynamic toDynamic() const {
return folly::dynamic::object("total", total)
("uncounted", uncounted())
("percentUncounted", percent(uncounted()))
("persistent", persistent())
("percentPersistent", percent(persistent()))
("incremented", incremented)
("percentIncremented", percent(incremented))
("profileType", "IncRefProfile");
}
// overflow handling isn't statistically correct; but its better
// than overflowing.
static void reduce(IncRefProfile& a, const IncRefProfile& b) {
auto const total = static_cast<uint64_t>(a.total + b.total);
auto constexpr limit = std::numeric_limits<decltype(a.total)>::max();
if (total > limit) {
auto scale = [&] (uint32_t& x, uint64_t y) {
x = ((x + y) * limit + total - 1) / total;
};
a.total = limit;
scale(a.refcounted, b.refcounted);
scale(a.incremented, b.incremented);
} else {
a.total += b.total;
a.refcounted += b.refcounted;
a.incremented += b.incremented;
}
}
/*
* The total number of times this IncRef was executed.
*/
uint32_t total;
/*
* The number of times this IncRef made it past the refcounted check.
*/
uint32_t refcounted;
/*
* The number of times this IncRef actually incremented the refcount.
*/
uint32_t incremented;
};
///////////////////////////////////////////////////////////////////////////////
} }