v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
profile-data-reader.h
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_BUILTINS_PROFILE_DATA_READER_H_
6#define V8_BUILTINS_PROFILE_DATA_READER_H_
7
8#include <cstddef>
9#include <cstdint>
10#include <map>
11#include <vector>
12
13#include "src/common/globals.h"
14
15namespace v8 {
16namespace internal {
17
19 public:
20 // A hash of the function's Graph before scheduling. Allows us to avoid using
21 // profiling data if the function has been changed.
22 int hash() const { return hash_; }
23
24 // Returns the hint for a pair of blocks with the given IDs.
25 BranchHint GetHint(size_t true_block_id, size_t false_block_id) const {
26 auto it =
27 block_hints_by_id.find(std::make_pair(true_block_id, false_block_id));
28 if (it != block_hints_by_id.end()) {
29 return it->second ? BranchHint::kTrue : BranchHint::kFalse;
30 }
31 return BranchHint::kNone;
32 }
33
34#ifdef LOG_BUILTIN_BLOCK_COUNT
35 uint64_t GetExecutedCount(size_t block_id) const {
36 if (executed_count_.count(block_id) == 0) return 0;
37 return executed_count_.at(block_id);
38 }
39#endif
40
41 // Load basic block profiling data for the builtin with the given name, if
42 // such data exists. The returned vector is indexed by block ID, and its
43 // values are the number of times each block was executed while profiling.
44 static const ProfileDataFromFile* TryRead(const char* name);
45
46 protected:
47 int hash_ = 0;
48
49 // Branch hints, indicated by true or false to reflect the hinted result of
50 // the branch condition. The vector is indexed by the basic block ids of
51 // the two destinations of the branch.
52 std::map<std::pair<size_t, size_t>, bool> block_hints_by_id;
53
54#ifdef LOG_BUILTIN_BLOCK_COUNT
55 std::unordered_map<size_t, uint64_t> executed_count_;
56#endif
57};
58
59// The following strings can't be static members of ProfileDataFromFile until
60// C++ 17; see https://stackoverflow.com/q/8016780/839379 . So for now we use a
61// namespace.
62namespace ProfileDataFromFileConstants {
63
64// Any line in a v8.log beginning with this string represents a basic block
65// counter.
66static constexpr char kBlockCounterMarker[] = "block";
67
68// Any line in the profile beginning with this string represents a basic block
69// branch hint.
70static constexpr char kBlockHintMarker[] = "block_hint";
71
72// Any line in a v8.log beginning with this string represents the hash of the
73// function Graph for a builtin.
74static constexpr char kBuiltinHashMarker[] = "builtin_hash";
75
76} // namespace ProfileDataFromFileConstants
77
78} // namespace internal
79} // namespace v8
80
81#endif // V8_BUILTINS_PROFILE_DATA_READER_H_
static const ProfileDataFromFile * TryRead(const char *name)
BranchHint GetHint(size_t true_block_id, size_t false_block_id) const
std::map< std::pair< size_t, size_t >, bool > block_hints_by_id