forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicBlockExecutionInfo.cpp
More file actions
87 lines (73 loc) · 2.55 KB
/
BasicBlockExecutionInfo.cpp
File metadata and controls
87 lines (73 loc) · 2.55 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
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifdef HERMESVM_PROFILER_BB
#include "hermes/VM/BasicBlockExecutionInfo.h"
#include "hermes/Support/JSONEmitter.h"
#include "hermes/Support/OSCompat.h"
#include "hermes/VM/CodeBlock.h"
#include "hermes/VM/Runtime.h"
#include "llvh/ADT/DenseMap.h"
#include "llvh/Support/MD5.h"
#include <string>
const static int32_t BASIC_BLOCK_STAT_VERSION = 2;
namespace hermes {
namespace vm {
void BasicBlockExecutionInfo::resizeFuncStatMap(
FunctionStatisticMap &funcStat,
uint16_t pointIndex) {
assert(funcStat.empty());
// If entrypoint block's pointIndex is zero(index overflow) we know
// there are more than 2^16 basic blocks and overflowed blocks share
// index zero so resize to maximum block number.
// Note: in this case the stats table is inaccurate - all overflowed blocks
// share the zero-index entry.
const uint32_t kMaxBlockNumbers = 1 << 16;
funcStat.resize(pointIndex == 0 ? kMaxBlockNumbers : pointIndex + 1);
}
static llvh::MD5::MD5Result doMD5Checksum(llvh::ArrayRef<uint8_t> bytecode) {
llvh::MD5 md5;
llvh::MD5::MD5Result checksum;
md5.update(bytecode);
md5.final(checksum);
return checksum;
}
void BasicBlockExecutionInfo::dump(llvh::raw_ostream &OS) {
JSONEmitter json(OS);
json.openDict();
json.emitKeyValue("version", BASIC_BLOCK_STAT_VERSION);
json.emitKeyValue("page_size", (double)hermes::oscompat::page_size());
json.emitKey("functions");
json.openArray();
for (const auto &funcEntry : basicBlockStats_) {
json.openDict();
auto md5Result = doMD5Checksum(funcEntry.first->getOpcodeArray());
json.emitKeyValue("checksum", md5Result.digest().str());
// hbcdump will be responsible to check overflow scenario(index-zero entry
// is not empty).
const auto &funcStat = funcEntry.second;
json.emitKey("basic_blocks");
uint16_t profileIndex = 0;
json.openArray();
for (const auto &blockStat : funcStat) {
json.openDict();
// profile_index is used as the identifier for basic block.
json.emitKeyValue("profile_index", profileIndex);
json.emitKeyValue("execution_count", (double)blockStat.first);
json.emitKeyValue("order", (double)blockStat.second);
json.closeDict();
++profileIndex;
}
json.closeArray();
json.closeDict();
}
json.closeArray();
json.closeDict();
OS.flush();
}
} // namespace vm
} // namespace hermes
#endif // HERMESVM_PROFILER_BB