2011-09-19 18:36:47 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2015-09-28 19:34:08 +00:00
|
|
|
#ifndef V8_PROFILER_PROFILE_GENERATOR_H_
|
|
|
|
#define V8_PROFILER_PROFILE_GENERATOR_H_
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2018-07-02 22:01:24 +00:00
|
|
|
#include <atomic>
|
2018-05-11 18:02:24 +00:00
|
|
|
#include <deque>
|
2018-05-16 21:04:04 +00:00
|
|
|
#include <limits>
|
2014-11-06 09:16:34 +00:00
|
|
|
#include <map>
|
2018-05-11 18:02:24 +00:00
|
|
|
#include <memory>
|
2018-04-23 09:18:26 +00:00
|
|
|
#include <unordered_map>
|
2018-05-16 21:04:04 +00:00
|
|
|
#include <utility>
|
2017-09-07 11:58:25 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2018-02-23 13:53:22 +00:00
|
|
|
#include "include/v8-profiler.h"
|
2019-03-06 12:48:57 +00:00
|
|
|
#include "src/base/platform/time.h"
|
2019-01-20 20:26:47 +00:00
|
|
|
#include "src/builtins/builtins.h"
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/source-position.h"
|
|
|
|
#include "src/logging/code-events.h"
|
2015-10-01 18:10:58 +00:00
|
|
|
#include "src/profiler/strings-storage.h"
|
2019-05-23 13:27:57 +00:00
|
|
|
#include "src/utils/allocation.h"
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
2016-07-12 02:10:05 +00:00
|
|
|
namespace internal {
|
2016-07-06 18:37:10 +00:00
|
|
|
|
|
|
|
struct TickSample;
|
|
|
|
|
2018-04-11 13:09:15 +00:00
|
|
|
// Provides a mapping from the offsets within generated code or a bytecode array
|
[cpu-profiler] Reduce the size of inlining information
Previously we stored the source position table, which stored a mapping
of pc offsets to line numbers, and the inline_locations, which stored a
mapping of pc offsets to stacks of {CodeEntry, line_number} pairs. This
was slightly wasteful because we had two different tables which were
both keyed on the pc offset and contained some overlapping information.
This CL combines the two tables in a way. The source position table now
maps a pc offset to a pair of {line_number, inlining_id}. If the
inlining_id is valid, then it can be used to look up the inlining stack
which is stored in inline_locations, but is now keyed by inlining_id
rather than pc offset. This also has the nice effect of de-duplicating
inline stacks which we previously duplicated.
The new structure is similar to how this data is stored by the compiler,
except that we convert 'source positions' (char offset in a file) into
line numbers as we go, because we only care about attributing ticks to
a given line.
Also remove the helper RecordInliningInfo() as this is only actually
used to add inline stacks by one caller (where it is now inlined). The
other callers would always bail out or are only called from
test-cpu-profiler.
Remove AddInlineStack and replace it with SetInlineStacks which adds all
of the stacks at once. We need to do it this way because the source pos
table is passed into the constructor of CodeEntry, so we need to create
it before the CodeEntry, but the inline stacks are not (they are part of
rare_data which is not always present), so we need to add them after
construction. Given that we calculate both the source pos table and the
inline stacks before construction, it's just easier to add them all at
once.
Also add a print() method to CodeEntry to make future debugging easier
as I'm constantly rewriting this locally.
Bug: v8:8575, v8:7719, v8:7203
Change-Id: I39324d6ea13d116d5da5d0a0d243cae76a749c79
Reviewed-on: https://chromium-review.googlesource.com/c/1392195
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58554}
2019-01-04 11:57:50 +00:00
|
|
|
// to the source line and inlining id.
|
2019-03-27 11:55:41 +00:00
|
|
|
class V8_EXPORT_PRIVATE SourcePositionTable : public Malloced {
|
2014-11-06 09:16:34 +00:00
|
|
|
public:
|
2018-05-11 18:24:04 +00:00
|
|
|
SourcePositionTable() = default;
|
2014-11-06 09:16:34 +00:00
|
|
|
|
[cpu-profiler] Reduce the size of inlining information
Previously we stored the source position table, which stored a mapping
of pc offsets to line numbers, and the inline_locations, which stored a
mapping of pc offsets to stacks of {CodeEntry, line_number} pairs. This
was slightly wasteful because we had two different tables which were
both keyed on the pc offset and contained some overlapping information.
This CL combines the two tables in a way. The source position table now
maps a pc offset to a pair of {line_number, inlining_id}. If the
inlining_id is valid, then it can be used to look up the inlining stack
which is stored in inline_locations, but is now keyed by inlining_id
rather than pc offset. This also has the nice effect of de-duplicating
inline stacks which we previously duplicated.
The new structure is similar to how this data is stored by the compiler,
except that we convert 'source positions' (char offset in a file) into
line numbers as we go, because we only care about attributing ticks to
a given line.
Also remove the helper RecordInliningInfo() as this is only actually
used to add inline stacks by one caller (where it is now inlined). The
other callers would always bail out or are only called from
test-cpu-profiler.
Remove AddInlineStack and replace it with SetInlineStacks which adds all
of the stacks at once. We need to do it this way because the source pos
table is passed into the constructor of CodeEntry, so we need to create
it before the CodeEntry, but the inline stacks are not (they are part of
rare_data which is not always present), so we need to add them after
construction. Given that we calculate both the source pos table and the
inline stacks before construction, it's just easier to add them all at
once.
Also add a print() method to CodeEntry to make future debugging easier
as I'm constantly rewriting this locally.
Bug: v8:8575, v8:7719, v8:7203
Change-Id: I39324d6ea13d116d5da5d0a0d243cae76a749c79
Reviewed-on: https://chromium-review.googlesource.com/c/1392195
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58554}
2019-01-04 11:57:50 +00:00
|
|
|
void SetPosition(int pc_offset, int line, int inlining_id);
|
2014-11-06 09:16:34 +00:00
|
|
|
int GetSourceLineNumber(int pc_offset) const;
|
[cpu-profiler] Reduce the size of inlining information
Previously we stored the source position table, which stored a mapping
of pc offsets to line numbers, and the inline_locations, which stored a
mapping of pc offsets to stacks of {CodeEntry, line_number} pairs. This
was slightly wasteful because we had two different tables which were
both keyed on the pc offset and contained some overlapping information.
This CL combines the two tables in a way. The source position table now
maps a pc offset to a pair of {line_number, inlining_id}. If the
inlining_id is valid, then it can be used to look up the inlining stack
which is stored in inline_locations, but is now keyed by inlining_id
rather than pc offset. This also has the nice effect of de-duplicating
inline stacks which we previously duplicated.
The new structure is similar to how this data is stored by the compiler,
except that we convert 'source positions' (char offset in a file) into
line numbers as we go, because we only care about attributing ticks to
a given line.
Also remove the helper RecordInliningInfo() as this is only actually
used to add inline stacks by one caller (where it is now inlined). The
other callers would always bail out or are only called from
test-cpu-profiler.
Remove AddInlineStack and replace it with SetInlineStacks which adds all
of the stacks at once. We need to do it this way because the source pos
table is passed into the constructor of CodeEntry, so we need to create
it before the CodeEntry, but the inline stacks are not (they are part of
rare_data which is not always present), so we need to add them after
construction. Given that we calculate both the source pos table and the
inline stacks before construction, it's just easier to add them all at
once.
Also add a print() method to CodeEntry to make future debugging easier
as I'm constantly rewriting this locally.
Bug: v8:8575, v8:7719, v8:7203
Change-Id: I39324d6ea13d116d5da5d0a0d243cae76a749c79
Reviewed-on: https://chromium-review.googlesource.com/c/1392195
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58554}
2019-01-04 11:57:50 +00:00
|
|
|
int GetInliningId(int pc_offset) const;
|
|
|
|
|
|
|
|
void print() const;
|
2014-11-06 09:16:34 +00:00
|
|
|
|
|
|
|
private:
|
[cpu-profiler] Reduce the size of inlining information
Previously we stored the source position table, which stored a mapping
of pc offsets to line numbers, and the inline_locations, which stored a
mapping of pc offsets to stacks of {CodeEntry, line_number} pairs. This
was slightly wasteful because we had two different tables which were
both keyed on the pc offset and contained some overlapping information.
This CL combines the two tables in a way. The source position table now
maps a pc offset to a pair of {line_number, inlining_id}. If the
inlining_id is valid, then it can be used to look up the inlining stack
which is stored in inline_locations, but is now keyed by inlining_id
rather than pc offset. This also has the nice effect of de-duplicating
inline stacks which we previously duplicated.
The new structure is similar to how this data is stored by the compiler,
except that we convert 'source positions' (char offset in a file) into
line numbers as we go, because we only care about attributing ticks to
a given line.
Also remove the helper RecordInliningInfo() as this is only actually
used to add inline stacks by one caller (where it is now inlined). The
other callers would always bail out or are only called from
test-cpu-profiler.
Remove AddInlineStack and replace it with SetInlineStacks which adds all
of the stacks at once. We need to do it this way because the source pos
table is passed into the constructor of CodeEntry, so we need to create
it before the CodeEntry, but the inline stacks are not (they are part of
rare_data which is not always present), so we need to add them after
construction. Given that we calculate both the source pos table and the
inline stacks before construction, it's just easier to add them all at
once.
Also add a print() method to CodeEntry to make future debugging easier
as I'm constantly rewriting this locally.
Bug: v8:8575, v8:7719, v8:7203
Change-Id: I39324d6ea13d116d5da5d0a0d243cae76a749c79
Reviewed-on: https://chromium-review.googlesource.com/c/1392195
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58554}
2019-01-04 11:57:50 +00:00
|
|
|
struct SourcePositionTuple {
|
|
|
|
bool operator<(const SourcePositionTuple& other) const {
|
2018-05-22 09:01:48 +00:00
|
|
|
return pc_offset < other.pc_offset;
|
|
|
|
}
|
|
|
|
int pc_offset;
|
|
|
|
int line_number;
|
[cpu-profiler] Reduce the size of inlining information
Previously we stored the source position table, which stored a mapping
of pc offsets to line numbers, and the inline_locations, which stored a
mapping of pc offsets to stacks of {CodeEntry, line_number} pairs. This
was slightly wasteful because we had two different tables which were
both keyed on the pc offset and contained some overlapping information.
This CL combines the two tables in a way. The source position table now
maps a pc offset to a pair of {line_number, inlining_id}. If the
inlining_id is valid, then it can be used to look up the inlining stack
which is stored in inline_locations, but is now keyed by inlining_id
rather than pc offset. This also has the nice effect of de-duplicating
inline stacks which we previously duplicated.
The new structure is similar to how this data is stored by the compiler,
except that we convert 'source positions' (char offset in a file) into
line numbers as we go, because we only care about attributing ticks to
a given line.
Also remove the helper RecordInliningInfo() as this is only actually
used to add inline stacks by one caller (where it is now inlined). The
other callers would always bail out or are only called from
test-cpu-profiler.
Remove AddInlineStack and replace it with SetInlineStacks which adds all
of the stacks at once. We need to do it this way because the source pos
table is passed into the constructor of CodeEntry, so we need to create
it before the CodeEntry, but the inline stacks are not (they are part of
rare_data which is not always present), so we need to add them after
construction. Given that we calculate both the source pos table and the
inline stacks before construction, it's just easier to add them all at
once.
Also add a print() method to CodeEntry to make future debugging easier
as I'm constantly rewriting this locally.
Bug: v8:8575, v8:7719, v8:7203
Change-Id: I39324d6ea13d116d5da5d0a0d243cae76a749c79
Reviewed-on: https://chromium-review.googlesource.com/c/1392195
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58554}
2019-01-04 11:57:50 +00:00
|
|
|
int inlining_id;
|
2018-05-22 09:01:48 +00:00
|
|
|
};
|
[cpu-profiler] Reduce the size of inlining information
Previously we stored the source position table, which stored a mapping
of pc offsets to line numbers, and the inline_locations, which stored a
mapping of pc offsets to stacks of {CodeEntry, line_number} pairs. This
was slightly wasteful because we had two different tables which were
both keyed on the pc offset and contained some overlapping information.
This CL combines the two tables in a way. The source position table now
maps a pc offset to a pair of {line_number, inlining_id}. If the
inlining_id is valid, then it can be used to look up the inlining stack
which is stored in inline_locations, but is now keyed by inlining_id
rather than pc offset. This also has the nice effect of de-duplicating
inline stacks which we previously duplicated.
The new structure is similar to how this data is stored by the compiler,
except that we convert 'source positions' (char offset in a file) into
line numbers as we go, because we only care about attributing ticks to
a given line.
Also remove the helper RecordInliningInfo() as this is only actually
used to add inline stacks by one caller (where it is now inlined). The
other callers would always bail out or are only called from
test-cpu-profiler.
Remove AddInlineStack and replace it with SetInlineStacks which adds all
of the stacks at once. We need to do it this way because the source pos
table is passed into the constructor of CodeEntry, so we need to create
it before the CodeEntry, but the inline stacks are not (they are part of
rare_data which is not always present), so we need to add them after
construction. Given that we calculate both the source pos table and the
inline stacks before construction, it's just easier to add them all at
once.
Also add a print() method to CodeEntry to make future debugging easier
as I'm constantly rewriting this locally.
Bug: v8:8575, v8:7719, v8:7203
Change-Id: I39324d6ea13d116d5da5d0a0d243cae76a749c79
Reviewed-on: https://chromium-review.googlesource.com/c/1392195
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58554}
2019-01-04 11:57:50 +00:00
|
|
|
// This is logically a map, but we store it as a vector of tuples, sorted by
|
2018-05-22 09:01:48 +00:00
|
|
|
// the pc offset, so that we can save space and look up items using binary
|
|
|
|
// search.
|
[cpu-profiler] Reduce the size of inlining information
Previously we stored the source position table, which stored a mapping
of pc offsets to line numbers, and the inline_locations, which stored a
mapping of pc offsets to stacks of {CodeEntry, line_number} pairs. This
was slightly wasteful because we had two different tables which were
both keyed on the pc offset and contained some overlapping information.
This CL combines the two tables in a way. The source position table now
maps a pc offset to a pair of {line_number, inlining_id}. If the
inlining_id is valid, then it can be used to look up the inlining stack
which is stored in inline_locations, but is now keyed by inlining_id
rather than pc offset. This also has the nice effect of de-duplicating
inline stacks which we previously duplicated.
The new structure is similar to how this data is stored by the compiler,
except that we convert 'source positions' (char offset in a file) into
line numbers as we go, because we only care about attributing ticks to
a given line.
Also remove the helper RecordInliningInfo() as this is only actually
used to add inline stacks by one caller (where it is now inlined). The
other callers would always bail out or are only called from
test-cpu-profiler.
Remove AddInlineStack and replace it with SetInlineStacks which adds all
of the stacks at once. We need to do it this way because the source pos
table is passed into the constructor of CodeEntry, so we need to create
it before the CodeEntry, but the inline stacks are not (they are part of
rare_data which is not always present), so we need to add them after
construction. Given that we calculate both the source pos table and the
inline stacks before construction, it's just easier to add them all at
once.
Also add a print() method to CodeEntry to make future debugging easier
as I'm constantly rewriting this locally.
Bug: v8:8575, v8:7719, v8:7203
Change-Id: I39324d6ea13d116d5da5d0a0d243cae76a749c79
Reviewed-on: https://chromium-review.googlesource.com/c/1392195
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58554}
2019-01-04 11:57:50 +00:00
|
|
|
std::vector<SourcePositionTuple> pc_offsets_to_lines_;
|
2018-04-11 13:09:15 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(SourcePositionTable);
|
2014-11-06 09:16:34 +00:00
|
|
|
};
|
|
|
|
|
2019-01-08 14:16:03 +00:00
|
|
|
struct CodeEntryAndLineNumber;
|
2019-01-02 12:19:06 +00:00
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
class CodeEntry {
|
|
|
|
public:
|
2010-03-19 09:46:53 +00:00
|
|
|
// CodeEntry doesn't own name strings, just references them.
|
2016-06-15 13:22:39 +00:00
|
|
|
inline CodeEntry(CodeEventListener::LogEventsAndTags tag, const char* name,
|
2013-06-26 16:04:25 +00:00
|
|
|
const char* resource_name = CodeEntry::kEmptyResourceName,
|
2013-10-10 13:15:47 +00:00
|
|
|
int line_number = v8::CpuProfileNode::kNoLineNumberInfo,
|
2014-11-06 09:16:34 +00:00
|
|
|
int column_number = v8::CpuProfileNode::kNoColumnNumberInfo,
|
2018-04-11 13:09:15 +00:00
|
|
|
std::unique_ptr<SourcePositionTable> line_info = nullptr,
|
2019-03-07 18:54:37 +00:00
|
|
|
Address instruction_start = kNullAddress,
|
|
|
|
bool is_shared_cross_origin = false);
|
2010-04-06 10:36:38 +00:00
|
|
|
|
2013-10-14 08:57:46 +00:00
|
|
|
const char* name() const { return name_; }
|
|
|
|
const char* resource_name() const { return resource_name_; }
|
|
|
|
int line_number() const { return line_number_; }
|
2013-10-10 13:15:47 +00:00
|
|
|
int column_number() const { return column_number_; }
|
2018-04-11 13:09:15 +00:00
|
|
|
const SourcePositionTable* line_info() const { return line_info_.get(); }
|
2013-10-14 08:57:46 +00:00
|
|
|
int script_id() const { return script_id_; }
|
|
|
|
void set_script_id(int script_id) { script_id_ = script_id; }
|
2015-02-20 13:28:42 +00:00
|
|
|
int position() const { return position_; }
|
|
|
|
void set_position(int position) { position_ = position; }
|
2013-10-14 08:57:46 +00:00
|
|
|
void set_bailout_reason(const char* bailout_reason) {
|
2018-05-18 07:38:14 +00:00
|
|
|
EnsureRareData()->bailout_reason_ = bailout_reason;
|
|
|
|
}
|
|
|
|
const char* bailout_reason() const {
|
|
|
|
return rare_data_ ? rare_data_->bailout_reason_ : kEmptyBailoutReason;
|
2013-09-05 13:20:51 +00:00
|
|
|
}
|
2015-02-12 19:51:26 +00:00
|
|
|
|
2018-05-24 11:09:16 +00:00
|
|
|
void set_deopt_info(const char* deopt_reason, int deopt_id,
|
|
|
|
std::vector<CpuProfileDeoptFrame> inlined_frames);
|
|
|
|
|
2015-04-08 16:13:24 +00:00
|
|
|
CpuProfileDeoptInfo GetDeoptInfo();
|
2018-05-05 01:33:33 +00:00
|
|
|
bool has_deopt_info() const {
|
|
|
|
return rare_data_ && rare_data_->deopt_id_ != kNoDeoptimizationId;
|
|
|
|
}
|
2015-02-12 19:51:26 +00:00
|
|
|
void clear_deopt_info() {
|
2018-05-05 01:33:33 +00:00
|
|
|
if (!rare_data_) return;
|
|
|
|
// TODO(alph): Clear rare_data_ if that was the only field in use.
|
|
|
|
rare_data_->deopt_reason_ = kNoDeoptReason;
|
|
|
|
rare_data_->deopt_id_ = kNoDeoptimizationId;
|
2015-02-10 14:32:42 +00:00
|
|
|
}
|
2018-05-11 18:02:24 +00:00
|
|
|
void mark_used() { bit_field_ = UsedField::update(bit_field_, true); }
|
|
|
|
bool used() const { return UsedField::decode(bit_field_); }
|
2010-04-06 10:36:38 +00:00
|
|
|
|
2018-11-28 19:57:30 +00:00
|
|
|
void FillFunctionInfo(SharedFunctionInfo shared);
|
2015-02-20 13:28:42 +00:00
|
|
|
|
2013-07-02 07:51:09 +00:00
|
|
|
void SetBuiltinId(Builtins::Name id);
|
2014-11-05 12:40:56 +00:00
|
|
|
Builtins::Name builtin_id() const {
|
|
|
|
return BuiltinIdField::decode(bit_field_);
|
|
|
|
}
|
2013-07-02 07:51:09 +00:00
|
|
|
|
2019-03-07 18:54:37 +00:00
|
|
|
bool is_shared_cross_origin() const {
|
|
|
|
return SharedCrossOriginField::decode(bit_field_);
|
|
|
|
}
|
|
|
|
|
2015-02-20 13:28:42 +00:00
|
|
|
uint32_t GetHash() const;
|
2018-04-23 09:18:26 +00:00
|
|
|
bool IsSameFunctionAs(const CodeEntry* entry) const;
|
2010-05-18 14:19:33 +00:00
|
|
|
|
2014-11-06 09:16:34 +00:00
|
|
|
int GetSourceLine(int pc_offset) const;
|
|
|
|
|
2019-01-08 14:16:03 +00:00
|
|
|
struct Equals {
|
|
|
|
bool operator()(const std::unique_ptr<CodeEntry>& lhs,
|
|
|
|
const std::unique_ptr<CodeEntry>& rhs) const {
|
|
|
|
return lhs.get()->IsSameFunctionAs(rhs.get());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct Hasher {
|
|
|
|
std::size_t operator()(const std::unique_ptr<CodeEntry>& e) const {
|
|
|
|
return e->GetHash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
[cpu-profiler] Reduce the size of inlining information
Previously we stored the source position table, which stored a mapping
of pc offsets to line numbers, and the inline_locations, which stored a
mapping of pc offsets to stacks of {CodeEntry, line_number} pairs. This
was slightly wasteful because we had two different tables which were
both keyed on the pc offset and contained some overlapping information.
This CL combines the two tables in a way. The source position table now
maps a pc offset to a pair of {line_number, inlining_id}. If the
inlining_id is valid, then it can be used to look up the inlining stack
which is stored in inline_locations, but is now keyed by inlining_id
rather than pc offset. This also has the nice effect of de-duplicating
inline stacks which we previously duplicated.
The new structure is similar to how this data is stored by the compiler,
except that we convert 'source positions' (char offset in a file) into
line numbers as we go, because we only care about attributing ticks to
a given line.
Also remove the helper RecordInliningInfo() as this is only actually
used to add inline stacks by one caller (where it is now inlined). The
other callers would always bail out or are only called from
test-cpu-profiler.
Remove AddInlineStack and replace it with SetInlineStacks which adds all
of the stacks at once. We need to do it this way because the source pos
table is passed into the constructor of CodeEntry, so we need to create
it before the CodeEntry, but the inline stacks are not (they are part of
rare_data which is not always present), so we need to add them after
construction. Given that we calculate both the source pos table and the
inline stacks before construction, it's just easier to add them all at
once.
Also add a print() method to CodeEntry to make future debugging easier
as I'm constantly rewriting this locally.
Bug: v8:8575, v8:7719, v8:7203
Change-Id: I39324d6ea13d116d5da5d0a0d243cae76a749c79
Reviewed-on: https://chromium-review.googlesource.com/c/1392195
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58554}
2019-01-04 11:57:50 +00:00
|
|
|
void SetInlineStacks(
|
2019-01-08 14:16:03 +00:00
|
|
|
std::unordered_set<std::unique_ptr<CodeEntry>, Hasher, Equals>
|
|
|
|
inline_entries,
|
|
|
|
std::unordered_map<int, std::vector<CodeEntryAndLineNumber>>
|
|
|
|
inline_stacks);
|
|
|
|
const std::vector<CodeEntryAndLineNumber>* GetInlineStack(
|
|
|
|
int pc_offset) const;
|
2016-03-01 05:59:32 +00:00
|
|
|
|
2018-07-27 09:08:25 +00:00
|
|
|
void set_instruction_start(Address start) { instruction_start_ = start; }
|
2014-11-06 09:16:34 +00:00
|
|
|
Address instruction_start() const { return instruction_start_; }
|
2018-07-27 09:08:25 +00:00
|
|
|
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEventListener::LogEventsAndTags tag() const {
|
|
|
|
return TagField::decode(bit_field_);
|
|
|
|
}
|
2014-11-06 09:16:34 +00:00
|
|
|
|
2018-05-17 19:37:58 +00:00
|
|
|
static const char* const kWasmResourceNamePrefix;
|
2019-03-27 11:55:41 +00:00
|
|
|
V8_EXPORT_PRIVATE static const char* const kEmptyResourceName;
|
2013-09-05 13:20:51 +00:00
|
|
|
static const char* const kEmptyBailoutReason;
|
2015-02-12 19:51:26 +00:00
|
|
|
static const char* const kNoDeoptReason;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2019-03-27 11:55:41 +00:00
|
|
|
V8_EXPORT_PRIVATE static const char* const kProgramEntryName;
|
|
|
|
V8_EXPORT_PRIVATE static const char* const kIdleEntryName;
|
2016-06-22 16:43:46 +00:00
|
|
|
static const char* const kGarbageCollectorEntryName;
|
|
|
|
// Used to represent frames for which we have no reliable way to
|
|
|
|
// detect function.
|
2019-03-27 11:55:41 +00:00
|
|
|
V8_EXPORT_PRIVATE static const char* const kUnresolvedFunctionName;
|
2019-04-03 00:07:48 +00:00
|
|
|
V8_EXPORT_PRIVATE static const char* const kRootEntryName;
|
2016-06-22 16:43:46 +00:00
|
|
|
|
|
|
|
V8_INLINE static CodeEntry* program_entry() {
|
|
|
|
return kProgramEntry.Pointer();
|
|
|
|
}
|
|
|
|
V8_INLINE static CodeEntry* idle_entry() { return kIdleEntry.Pointer(); }
|
|
|
|
V8_INLINE static CodeEntry* gc_entry() { return kGCEntry.Pointer(); }
|
|
|
|
V8_INLINE static CodeEntry* unresolved_entry() {
|
|
|
|
return kUnresolvedEntry.Pointer();
|
|
|
|
}
|
2019-04-03 00:07:48 +00:00
|
|
|
V8_INLINE static CodeEntry* root_entry() { return kRootEntry.Pointer(); }
|
2016-06-22 16:43:46 +00:00
|
|
|
|
[cpu-profiler] Reduce the size of inlining information
Previously we stored the source position table, which stored a mapping
of pc offsets to line numbers, and the inline_locations, which stored a
mapping of pc offsets to stacks of {CodeEntry, line_number} pairs. This
was slightly wasteful because we had two different tables which were
both keyed on the pc offset and contained some overlapping information.
This CL combines the two tables in a way. The source position table now
maps a pc offset to a pair of {line_number, inlining_id}. If the
inlining_id is valid, then it can be used to look up the inlining stack
which is stored in inline_locations, but is now keyed by inlining_id
rather than pc offset. This also has the nice effect of de-duplicating
inline stacks which we previously duplicated.
The new structure is similar to how this data is stored by the compiler,
except that we convert 'source positions' (char offset in a file) into
line numbers as we go, because we only care about attributing ticks to
a given line.
Also remove the helper RecordInliningInfo() as this is only actually
used to add inline stacks by one caller (where it is now inlined). The
other callers would always bail out or are only called from
test-cpu-profiler.
Remove AddInlineStack and replace it with SetInlineStacks which adds all
of the stacks at once. We need to do it this way because the source pos
table is passed into the constructor of CodeEntry, so we need to create
it before the CodeEntry, but the inline stacks are not (they are part of
rare_data which is not always present), so we need to add them after
construction. Given that we calculate both the source pos table and the
inline stacks before construction, it's just easier to add them all at
once.
Also add a print() method to CodeEntry to make future debugging easier
as I'm constantly rewriting this locally.
Bug: v8:8575, v8:7719, v8:7203
Change-Id: I39324d6ea13d116d5da5d0a0d243cae76a749c79
Reviewed-on: https://chromium-review.googlesource.com/c/1392195
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58554}
2019-01-04 11:57:50 +00:00
|
|
|
void print() const;
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
private:
|
2018-05-05 01:33:33 +00:00
|
|
|
struct RareData {
|
|
|
|
const char* deopt_reason_ = kNoDeoptReason;
|
2018-05-18 07:38:14 +00:00
|
|
|
const char* bailout_reason_ = kEmptyBailoutReason;
|
2018-05-05 01:33:33 +00:00
|
|
|
int deopt_id_ = kNoDeoptimizationId;
|
2019-01-08 14:16:03 +00:00
|
|
|
std::unordered_map<int, std::vector<CodeEntryAndLineNumber>> inline_stacks_;
|
|
|
|
std::unordered_set<std::unique_ptr<CodeEntry>, Hasher, Equals>
|
|
|
|
inline_entries_;
|
2018-05-24 11:09:16 +00:00
|
|
|
std::vector<CpuProfileDeoptFrame> deopt_inlined_frames_;
|
2018-05-05 01:33:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RareData* EnsureRareData();
|
|
|
|
|
2019-04-08 12:16:39 +00:00
|
|
|
struct V8_EXPORT_PRIVATE ProgramEntryCreateTrait {
|
2016-06-22 16:43:46 +00:00
|
|
|
static CodeEntry* Create();
|
|
|
|
};
|
2019-04-08 12:16:39 +00:00
|
|
|
struct V8_EXPORT_PRIVATE IdleEntryCreateTrait {
|
2016-06-22 16:43:46 +00:00
|
|
|
static CodeEntry* Create();
|
|
|
|
};
|
2019-04-08 12:16:39 +00:00
|
|
|
struct V8_EXPORT_PRIVATE GCEntryCreateTrait {
|
2016-06-22 16:43:46 +00:00
|
|
|
static CodeEntry* Create();
|
|
|
|
};
|
2019-04-08 12:16:39 +00:00
|
|
|
struct V8_EXPORT_PRIVATE UnresolvedEntryCreateTrait {
|
2016-06-22 16:43:46 +00:00
|
|
|
static CodeEntry* Create();
|
|
|
|
};
|
2019-04-08 12:16:39 +00:00
|
|
|
struct V8_EXPORT_PRIVATE RootEntryCreateTrait {
|
2019-04-03 00:07:48 +00:00
|
|
|
static CodeEntry* Create();
|
|
|
|
};
|
2016-06-22 16:43:46 +00:00
|
|
|
|
2019-04-08 12:16:39 +00:00
|
|
|
V8_EXPORT_PRIVATE static base::LazyDynamicInstance<
|
|
|
|
CodeEntry, ProgramEntryCreateTrait>::type kProgramEntry;
|
|
|
|
V8_EXPORT_PRIVATE static base::LazyDynamicInstance<
|
|
|
|
CodeEntry, IdleEntryCreateTrait>::type kIdleEntry;
|
|
|
|
V8_EXPORT_PRIVATE static base::LazyDynamicInstance<
|
|
|
|
CodeEntry, GCEntryCreateTrait>::type kGCEntry;
|
|
|
|
V8_EXPORT_PRIVATE static base::LazyDynamicInstance<
|
|
|
|
CodeEntry, UnresolvedEntryCreateTrait>::type kUnresolvedEntry;
|
|
|
|
V8_EXPORT_PRIVATE static base::LazyDynamicInstance<
|
|
|
|
CodeEntry, RootEntryCreateTrait>::type kRootEntry;
|
2016-06-22 16:43:46 +00:00
|
|
|
|
2019-01-20 20:26:47 +00:00
|
|
|
using TagField = BitField<CodeEventListener::LogEventsAndTags, 0, 8>;
|
2019-03-07 18:54:37 +00:00
|
|
|
using BuiltinIdField = BitField<Builtins::Name, 8, 22>;
|
|
|
|
static_assert(Builtins::builtin_count <= BuiltinIdField::kNumValues,
|
|
|
|
"builtin_count exceeds size of bitfield");
|
|
|
|
using UsedField = BitField<bool, 30, 1>;
|
|
|
|
using SharedCrossOriginField = BitField<bool, 31, 1>;
|
2014-11-05 12:40:56 +00:00
|
|
|
|
|
|
|
uint32_t bit_field_;
|
2010-03-15 14:11:19 +00:00
|
|
|
const char* name_;
|
|
|
|
const char* resource_name_;
|
|
|
|
int line_number_;
|
2013-10-10 13:15:47 +00:00
|
|
|
int column_number_;
|
2013-07-02 06:14:01 +00:00
|
|
|
int script_id_;
|
2015-02-20 13:28:42 +00:00
|
|
|
int position_;
|
2018-04-11 13:09:15 +00:00
|
|
|
std::unique_ptr<SourcePositionTable> line_info_;
|
2014-11-06 09:16:34 +00:00
|
|
|
Address instruction_start_;
|
2018-05-05 01:33:33 +00:00
|
|
|
std::unique_ptr<RareData> rare_data_;
|
2015-03-24 12:46:13 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CodeEntry);
|
2010-03-15 14:11:19 +00:00
|
|
|
};
|
|
|
|
|
2018-05-23 08:26:10 +00:00
|
|
|
struct CodeEntryAndLineNumber {
|
|
|
|
CodeEntry* code_entry;
|
|
|
|
int line_number;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<CodeEntryAndLineNumber> ProfileStackTrace;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
class ProfileTree;
|
|
|
|
|
2019-03-27 11:55:41 +00:00
|
|
|
class V8_EXPORT_PRIVATE ProfileNode {
|
2010-03-15 14:11:19 +00:00
|
|
|
public:
|
2018-05-23 08:26:10 +00:00
|
|
|
inline ProfileNode(ProfileTree* tree, CodeEntry* entry, ProfileNode* parent,
|
|
|
|
int line_number = 0);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2018-05-23 08:26:10 +00:00
|
|
|
ProfileNode* FindChild(
|
|
|
|
CodeEntry* entry,
|
|
|
|
int line_number = v8::CpuProfileNode::kNoLineNumberInfo);
|
|
|
|
ProfileNode* FindOrAddChild(CodeEntry* entry, int line_number = 0);
|
2013-10-14 08:57:46 +00:00
|
|
|
void IncrementSelfTicks() { ++self_ticks_; }
|
|
|
|
void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; }
|
2014-11-06 09:16:34 +00:00
|
|
|
void IncrementLineTicks(int src_line);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2013-10-14 08:57:46 +00:00
|
|
|
CodeEntry* entry() const { return entry_; }
|
|
|
|
unsigned self_ticks() const { return self_ticks_; }
|
2017-08-29 12:40:31 +00:00
|
|
|
const std::vector<ProfileNode*>* children() const { return &children_list_; }
|
2013-04-02 07:48:25 +00:00
|
|
|
unsigned id() const { return id_; }
|
2015-02-20 13:28:42 +00:00
|
|
|
unsigned function_id() const;
|
2016-10-06 18:14:03 +00:00
|
|
|
ProfileNode* parent() const { return parent_; }
|
2018-05-23 08:26:10 +00:00
|
|
|
int line_number() const {
|
|
|
|
return line_number_ != 0 ? line_number_ : entry_->line_number();
|
|
|
|
}
|
2019-04-03 00:07:48 +00:00
|
|
|
CpuProfileNode::SourceType source_type() const;
|
2018-05-23 08:26:10 +00:00
|
|
|
|
2018-04-23 09:18:26 +00:00
|
|
|
unsigned int GetHitLineCount() const {
|
|
|
|
return static_cast<unsigned int>(line_ticks_.size());
|
|
|
|
}
|
2014-11-06 09:16:34 +00:00
|
|
|
bool GetLineTicks(v8::CpuProfileNode::LineTick* entries,
|
|
|
|
unsigned int length) const;
|
2015-02-12 19:51:26 +00:00
|
|
|
void CollectDeoptInfo(CodeEntry* entry);
|
2015-04-08 16:13:24 +00:00
|
|
|
const std::vector<CpuProfileDeoptInfo>& deopt_infos() const {
|
|
|
|
return deopt_infos_;
|
|
|
|
}
|
2015-11-30 08:16:35 +00:00
|
|
|
Isolate* isolate() const;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
void Print(int indent);
|
|
|
|
|
2015-02-20 13:28:42 +00:00
|
|
|
private:
|
2018-05-23 08:26:10 +00:00
|
|
|
struct Equals {
|
|
|
|
bool operator()(CodeEntryAndLineNumber lhs,
|
|
|
|
CodeEntryAndLineNumber rhs) const {
|
|
|
|
return lhs.code_entry->IsSameFunctionAs(rhs.code_entry) &&
|
|
|
|
lhs.line_number == rhs.line_number;
|
2018-04-23 09:18:26 +00:00
|
|
|
}
|
|
|
|
};
|
2018-05-23 08:26:10 +00:00
|
|
|
struct Hasher {
|
|
|
|
std::size_t operator()(CodeEntryAndLineNumber pair) const {
|
2018-09-20 10:54:52 +00:00
|
|
|
return pair.code_entry->GetHash() ^ ComputeUnseededHash(pair.line_number);
|
2018-05-23 08:26:10 +00:00
|
|
|
}
|
2018-04-23 09:18:26 +00:00
|
|
|
};
|
2014-11-06 09:16:34 +00:00
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
ProfileTree* tree_;
|
2010-03-15 14:11:19 +00:00
|
|
|
CodeEntry* entry_;
|
|
|
|
unsigned self_ticks_;
|
2018-05-23 08:26:10 +00:00
|
|
|
std::unordered_map<CodeEntryAndLineNumber, ProfileNode*, Hasher, Equals>
|
2018-04-23 09:18:26 +00:00
|
|
|
children_;
|
2018-05-23 08:26:10 +00:00
|
|
|
int line_number_;
|
2017-08-29 12:40:31 +00:00
|
|
|
std::vector<ProfileNode*> children_list_;
|
2016-10-06 18:14:03 +00:00
|
|
|
ProfileNode* parent_;
|
2013-04-02 07:48:25 +00:00
|
|
|
unsigned id_;
|
2018-04-23 09:18:26 +00:00
|
|
|
// maps line number --> number of ticks
|
|
|
|
std::unordered_map<int, int> line_ticks_;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2015-04-08 16:13:24 +00:00
|
|
|
std::vector<CpuProfileDeoptInfo> deopt_infos_;
|
2015-03-24 12:46:13 +00:00
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ProfileNode);
|
|
|
|
};
|
|
|
|
|
2019-03-27 11:55:41 +00:00
|
|
|
class V8_EXPORT_PRIVATE ProfileTree {
|
2010-03-15 14:11:19 +00:00
|
|
|
public:
|
2015-11-30 08:16:35 +00:00
|
|
|
explicit ProfileTree(Isolate* isolate);
|
2010-03-15 14:11:19 +00:00
|
|
|
~ProfileTree();
|
|
|
|
|
2018-05-23 08:26:10 +00:00
|
|
|
typedef v8::CpuProfilingMode ProfilingMode;
|
|
|
|
|
2014-11-06 09:16:34 +00:00
|
|
|
ProfileNode* AddPathFromEnd(
|
2016-03-01 05:59:32 +00:00
|
|
|
const std::vector<CodeEntry*>& path,
|
2016-01-26 20:47:23 +00:00
|
|
|
int src_line = v8::CpuProfileNode::kNoLineNumberInfo,
|
|
|
|
bool update_stats = true);
|
2018-05-23 08:26:10 +00:00
|
|
|
ProfileNode* AddPathFromEnd(
|
|
|
|
const ProfileStackTrace& path,
|
|
|
|
int src_line = v8::CpuProfileNode::kNoLineNumberInfo,
|
|
|
|
bool update_stats = true,
|
|
|
|
ProfilingMode mode = ProfilingMode::kLeafNodeLineNumbers);
|
2010-03-30 11:38:39 +00:00
|
|
|
ProfileNode* root() const { return root_; }
|
2013-04-02 07:48:25 +00:00
|
|
|
unsigned next_node_id() { return next_node_id_++; }
|
2015-02-20 13:28:42 +00:00
|
|
|
unsigned GetFunctionId(const ProfileNode* node);
|
2013-04-02 07:48:25 +00:00
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
void Print() {
|
|
|
|
root_->Print(0);
|
|
|
|
}
|
|
|
|
|
2015-11-30 08:16:35 +00:00
|
|
|
Isolate* isolate() const { return isolate_; }
|
|
|
|
|
2016-10-06 18:14:03 +00:00
|
|
|
void EnqueueNode(const ProfileNode* node) { pending_nodes_.push_back(node); }
|
|
|
|
size_t pending_nodes_count() const { return pending_nodes_.size(); }
|
|
|
|
std::vector<const ProfileNode*> TakePendingNodes() {
|
|
|
|
return std::move(pending_nodes_);
|
|
|
|
}
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
private:
|
|
|
|
template <typename Callback>
|
2010-05-18 14:19:33 +00:00
|
|
|
void TraverseDepthFirst(Callback* callback);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2016-10-06 18:14:03 +00:00
|
|
|
std::vector<const ProfileNode*> pending_nodes_;
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
unsigned next_node_id_;
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* root_;
|
2015-11-30 08:16:35 +00:00
|
|
|
Isolate* isolate_;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2015-02-20 13:28:42 +00:00
|
|
|
unsigned next_function_id_;
|
2018-04-23 09:18:26 +00:00
|
|
|
std::unordered_map<CodeEntry*, unsigned> function_ids_;
|
2015-02-20 13:28:42 +00:00
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ProfileTree);
|
|
|
|
};
|
|
|
|
|
2019-01-20 20:26:47 +00:00
|
|
|
class CpuProfiler;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
class CpuProfile {
|
2010-03-15 14:11:19 +00:00
|
|
|
public:
|
2019-02-07 22:52:20 +00:00
|
|
|
struct SampleInfo {
|
|
|
|
ProfileNode* node;
|
|
|
|
base::TimeTicks timestamp;
|
|
|
|
int line;
|
|
|
|
};
|
|
|
|
|
2019-05-14 20:24:49 +00:00
|
|
|
V8_EXPORT_PRIVATE CpuProfile(CpuProfiler* profiler, const char* title,
|
|
|
|
CpuProfilingOptions options);
|
2010-03-30 11:38:39 +00:00
|
|
|
|
2019-05-14 20:24:49 +00:00
|
|
|
// Checks whether or not the given TickSample should be (sub)sampled, given
|
|
|
|
// the sampling interval of the profiler that recorded it (in microseconds).
|
|
|
|
V8_EXPORT_PRIVATE bool CheckSubsample(base::TimeDelta sampling_interval);
|
2010-03-15 14:11:19 +00:00
|
|
|
// Add pc -> ... -> main() call path to the profile.
|
2018-05-23 08:26:10 +00:00
|
|
|
void AddPath(base::TimeTicks timestamp, const ProfileStackTrace& path,
|
2019-05-14 20:24:49 +00:00
|
|
|
int src_line, bool update_stats,
|
|
|
|
base::TimeDelta sampling_interval);
|
2016-10-06 18:14:03 +00:00
|
|
|
void FinishProfile();
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2013-08-05 07:17:08 +00:00
|
|
|
const char* title() const { return title_; }
|
|
|
|
const ProfileTree* top_down() const { return &top_down_; }
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2017-09-07 11:58:25 +00:00
|
|
|
int samples_count() const { return static_cast<int>(samples_.size()); }
|
2019-02-07 22:52:20 +00:00
|
|
|
const SampleInfo& sample(int index) const { return samples_[index]; }
|
2013-08-05 07:17:08 +00:00
|
|
|
|
2019-05-14 20:24:49 +00:00
|
|
|
int64_t sampling_interval_us() const {
|
|
|
|
return options_.sampling_interval_us();
|
|
|
|
}
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
base::TimeTicks start_time() const { return start_time_; }
|
|
|
|
base::TimeTicks end_time() const { return end_time_; }
|
2016-06-15 09:59:00 +00:00
|
|
|
CpuProfiler* cpu_profiler() const { return profiler_; }
|
2013-04-02 07:48:25 +00:00
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
void UpdateTicksScale();
|
|
|
|
|
2019-03-27 11:55:41 +00:00
|
|
|
V8_EXPORT_PRIVATE void Print();
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
private:
|
2016-10-06 18:14:03 +00:00
|
|
|
void StreamPendingTraceEvents();
|
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
const char* title_;
|
2019-05-09 19:20:21 +00:00
|
|
|
const CpuProfilingOptions options_;
|
2014-06-30 13:25:46 +00:00
|
|
|
base::TimeTicks start_time_;
|
|
|
|
base::TimeTicks end_time_;
|
2019-02-07 22:52:20 +00:00
|
|
|
std::deque<SampleInfo> samples_;
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileTree top_down_;
|
2016-06-15 09:59:00 +00:00
|
|
|
CpuProfiler* const profiler_;
|
2017-09-07 11:58:25 +00:00
|
|
|
size_t streaming_next_sample_;
|
2018-07-02 22:01:24 +00:00
|
|
|
uint32_t id_;
|
2019-05-14 20:24:49 +00:00
|
|
|
// Number of microseconds worth of profiler ticks that should elapse before
|
|
|
|
// the next sample is recorded.
|
|
|
|
base::TimeDelta next_sample_delta_;
|
2018-07-02 22:01:24 +00:00
|
|
|
|
|
|
|
static std::atomic<uint32_t> last_id_;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CpuProfile);
|
|
|
|
};
|
|
|
|
|
2019-03-27 11:55:41 +00:00
|
|
|
class V8_EXPORT_PRIVATE CodeMap {
|
2010-03-15 14:11:19 +00:00
|
|
|
public:
|
2018-05-04 00:19:12 +00:00
|
|
|
CodeMap();
|
2018-05-11 18:02:24 +00:00
|
|
|
~CodeMap();
|
2016-06-10 16:37:49 +00:00
|
|
|
|
2011-09-14 11:47:03 +00:00
|
|
|
void AddCode(Address addr, CodeEntry* entry, unsigned size);
|
|
|
|
void MoveCode(Address from, Address to);
|
2015-09-11 16:29:55 +00:00
|
|
|
CodeEntry* FindEntry(Address addr);
|
2010-03-30 11:38:39 +00:00
|
|
|
void Print();
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
private:
|
2018-05-16 21:04:04 +00:00
|
|
|
struct CodeEntryMapInfo {
|
2018-05-11 18:02:24 +00:00
|
|
|
unsigned index;
|
2010-03-15 14:11:19 +00:00
|
|
|
unsigned size;
|
|
|
|
};
|
|
|
|
|
2018-05-16 21:04:04 +00:00
|
|
|
union CodeEntrySlotInfo {
|
|
|
|
CodeEntry* entry;
|
|
|
|
unsigned next_free_slot;
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr unsigned kNoFreeSlot = std::numeric_limits<unsigned>::max();
|
|
|
|
|
2018-05-11 18:02:24 +00:00
|
|
|
void ClearCodesInRange(Address start, Address end);
|
2018-05-16 21:04:04 +00:00
|
|
|
unsigned AddCodeEntry(Address start, CodeEntry*);
|
|
|
|
void DeleteCodeEntry(unsigned index);
|
|
|
|
|
|
|
|
CodeEntry* entry(unsigned index) { return code_entries_[index].entry; }
|
2011-09-14 11:47:03 +00:00
|
|
|
|
2018-05-16 21:04:04 +00:00
|
|
|
std::deque<CodeEntrySlotInfo> code_entries_;
|
|
|
|
std::map<Address, CodeEntryMapInfo> code_map_;
|
|
|
|
unsigned free_list_head_ = kNoFreeSlot;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CodeMap);
|
|
|
|
};
|
|
|
|
|
2019-03-27 11:55:41 +00:00
|
|
|
class V8_EXPORT_PRIVATE CpuProfilesCollection {
|
2010-03-15 14:11:19 +00:00
|
|
|
public:
|
2016-06-15 09:59:00 +00:00
|
|
|
explicit CpuProfilesCollection(Isolate* isolate);
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2016-06-15 09:59:00 +00:00
|
|
|
void set_cpu_profiler(CpuProfiler* profiler) { profiler_ = profiler; }
|
2019-05-09 19:20:21 +00:00
|
|
|
bool StartProfiling(const char* title, CpuProfilingOptions options = {});
|
2019-05-14 20:24:49 +00:00
|
|
|
|
2013-07-30 07:01:16 +00:00
|
|
|
CpuProfile* StopProfiling(const char* title);
|
2018-02-06 09:44:39 +00:00
|
|
|
std::vector<std::unique_ptr<CpuProfile>>* profiles() {
|
|
|
|
return &finished_profiles_;
|
|
|
|
}
|
2018-11-27 00:48:42 +00:00
|
|
|
const char* GetName(Name name) { return resource_names_.GetName(name); }
|
2010-08-10 12:06:42 +00:00
|
|
|
bool IsLastProfile(const char* title);
|
2011-03-22 16:10:01 +00:00
|
|
|
void RemoveProfile(CpuProfile* profile);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2019-05-14 20:24:49 +00:00
|
|
|
// Finds a common sampling interval dividing each CpuProfile's interval,
|
|
|
|
// rounded up to the nearest multiple of the CpuProfiler's sampling interval.
|
|
|
|
// Returns 0 if no profiles are attached.
|
|
|
|
base::TimeDelta GetCommonSamplingInterval() const;
|
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
// Called from profile generator thread.
|
2014-11-06 09:16:34 +00:00
|
|
|
void AddPathToCurrentProfiles(base::TimeTicks timestamp,
|
2018-05-23 08:26:10 +00:00
|
|
|
const ProfileStackTrace& path, int src_line,
|
2019-05-14 20:24:49 +00:00
|
|
|
bool update_stats,
|
|
|
|
base::TimeDelta sampling_interval);
|
2010-03-30 11:38:39 +00:00
|
|
|
|
2010-08-31 14:16:01 +00:00
|
|
|
// Limits the number of profiles that can be simultaneously collected.
|
|
|
|
static const int kMaxSimultaneousProfiles = 100;
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
private:
|
2016-06-22 16:43:46 +00:00
|
|
|
StringsStorage resource_names_;
|
2018-02-06 09:44:39 +00:00
|
|
|
std::vector<std::unique_ptr<CpuProfile>> finished_profiles_;
|
2016-06-15 09:59:00 +00:00
|
|
|
CpuProfiler* profiler_;
|
2015-11-30 08:16:35 +00:00
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
// Accessed by VM thread and profile generator thread.
|
2018-02-06 09:44:39 +00:00
|
|
|
std::vector<std::unique_ptr<CpuProfile>> current_profiles_;
|
2014-06-30 13:25:46 +00:00
|
|
|
base::Semaphore current_profiles_semaphore_;
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection);
|
|
|
|
};
|
|
|
|
|
2019-03-27 11:55:41 +00:00
|
|
|
class V8_EXPORT_PRIVATE ProfileGenerator {
|
2010-03-19 09:46:53 +00:00
|
|
|
public:
|
2017-01-27 01:12:53 +00:00
|
|
|
explicit ProfileGenerator(CpuProfilesCollection* profiles);
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
void RecordTickSample(const TickSample& sample);
|
|
|
|
|
2013-10-14 08:57:46 +00:00
|
|
|
CodeMap* code_map() { return &code_map_; }
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
private:
|
2018-05-11 18:02:24 +00:00
|
|
|
CodeEntry* FindEntry(Address address);
|
2013-10-14 08:57:46 +00:00
|
|
|
CodeEntry* EntryForVMState(StateTag tag);
|
2010-04-07 14:18:26 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
CpuProfilesCollection* profiles_;
|
2010-03-15 14:11:19 +00:00
|
|
|
CodeMap code_map_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ProfileGenerator);
|
|
|
|
};
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2015-09-28 19:34:08 +00:00
|
|
|
#endif // V8_PROFILER_PROFILE_GENERATOR_H_
|