Commit c99c25a9 authored by alph's avatar alph Committed by Commit bot

[profiler] Fix a memory leak of CodeEvent objects

BUG=v8:5753

Review-Url: https://codereview.chromium.org/2655963003
Cr-Commit-Position: refs/heads/master@{#42720}
parent 2a78f298
......@@ -277,6 +277,21 @@ void CpuProfiler::ResetProfiles() {
profiles_->set_cpu_profiler(this);
}
void CpuProfiler::CreateEntriesForRuntimeCallStats() {
static_entries_.clear();
RuntimeCallStats* rcs = isolate_->counters()->runtime_call_stats();
CodeMap* code_map = generator_->code_map();
for (int i = 0; i < RuntimeCallStats::counters_count; ++i) {
RuntimeCallCounter* counter = &(rcs->*(RuntimeCallStats::counters[i]));
DCHECK(counter->name());
std::unique_ptr<CodeEntry> entry(
new CodeEntry(CodeEventListener::FUNCTION_TAG, counter->name(),
CodeEntry::kEmptyNamePrefix, "native V8Runtime"));
code_map->AddCode(reinterpret_cast<Address>(counter), entry.get(), 1);
static_entries_.push_back(std::move(entry));
}
}
void CpuProfiler::CollectSample() {
if (processor_) {
processor_->AddCurrentStack(isolate_);
......@@ -305,9 +320,10 @@ void CpuProfiler::StartProcessorIfNotStarted() {
// Disable logging when using the new implementation.
saved_is_logging_ = logger->is_logging_;
logger->is_logging_ = false;
generator_.reset(new ProfileGenerator(isolate_, profiles_.get()));
generator_.reset(new ProfileGenerator(profiles_.get()));
processor_.reset(new ProfilerEventsProcessor(isolate_, generator_.get(),
sampling_interval_));
CreateEntriesForRuntimeCallStats();
logger->SetUpProfilerListener();
ProfilerListener* profiler_listener = logger->profiler_listener();
profiler_listener->AddObserver(this);
......
......@@ -220,12 +220,14 @@ class CpuProfiler : public CodeEventObserver {
void StopProcessor();
void ResetProfiles();
void LogBuiltins();
void CreateEntriesForRuntimeCallStats();
Isolate* const isolate_;
base::TimeDelta sampling_interval_;
std::unique_ptr<CpuProfilesCollection> profiles_;
std::unique_ptr<ProfileGenerator> generator_;
std::unique_ptr<ProfilerEventsProcessor> processor_;
std::vector<std::unique_ptr<CodeEntry>> static_entries_;
bool saved_is_logging_;
bool is_profiling_;
......
......@@ -635,18 +635,8 @@ void CpuProfilesCollection::AddPathToCurrentProfiles(
current_profiles_semaphore_.Signal();
}
ProfileGenerator::ProfileGenerator(Isolate* isolate,
CpuProfilesCollection* profiles)
: isolate_(isolate), profiles_(profiles) {
RuntimeCallStats* rcs = isolate_->counters()->runtime_call_stats();
for (int i = 0; i < RuntimeCallStats::counters_count; ++i) {
RuntimeCallCounter* counter = &(rcs->*(RuntimeCallStats::counters[i]));
DCHECK(counter->name());
auto entry = new CodeEntry(CodeEventListener::FUNCTION_TAG, counter->name(),
CodeEntry::kEmptyNamePrefix, "native V8Runtime");
code_map_.AddCode(reinterpret_cast<Address>(counter), entry, 1);
}
}
ProfileGenerator::ProfileGenerator(CpuProfilesCollection* profiles)
: profiles_(profiles) {}
void ProfileGenerator::RecordTickSample(const TickSample& sample) {
std::vector<CodeEntry*> entries;
......
......@@ -368,7 +368,7 @@ class CpuProfilesCollection {
class ProfileGenerator {
public:
ProfileGenerator(Isolate* isolate, CpuProfilesCollection* profiles);
explicit ProfileGenerator(CpuProfilesCollection* profiles);
void RecordTickSample(const TickSample& sample);
......@@ -378,7 +378,6 @@ class ProfileGenerator {
CodeEntry* FindEntry(void* address);
CodeEntry* EntryForVMState(StateTag tag);
Isolate* isolate_;
CpuProfilesCollection* profiles_;
CodeMap code_map_;
......
......@@ -78,7 +78,7 @@ static const char* reason(const i::DeoptimizeReason reason) {
TEST(StartStop) {
i::Isolate* isolate = CcTest::i_isolate();
CpuProfilesCollection profiles(isolate);
ProfileGenerator generator(isolate, &profiles);
ProfileGenerator generator(&profiles);
std::unique_ptr<ProfilerEventsProcessor> processor(
new ProfilerEventsProcessor(isolate, &generator,
v8::base::TimeDelta::FromMicroseconds(100)));
......@@ -163,7 +163,7 @@ TEST(CodeEvents) {
i::AbstractCode* args4_code = CreateCode(&env);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfileGenerator* generator = new ProfileGenerator(isolate, profiles);
ProfileGenerator* generator = new ProfileGenerator(profiles);
ProfilerEventsProcessor* processor = new ProfilerEventsProcessor(
isolate, generator, v8::base::TimeDelta::FromMicroseconds(100));
CpuProfiler profiler(isolate, profiles, generator, processor);
......@@ -231,7 +231,7 @@ TEST(TickEvents) {
i::AbstractCode* frame3_code = CreateCode(&env);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfileGenerator* generator = new ProfileGenerator(isolate, profiles);
ProfileGenerator* generator = new ProfileGenerator(profiles);
ProfilerEventsProcessor* processor =
new ProfilerEventsProcessor(CcTest::i_isolate(), generator,
v8::base::TimeDelta::FromMicroseconds(100));
......@@ -304,7 +304,7 @@ TEST(Issue1398) {
i::AbstractCode* code = CreateCode(&env);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfileGenerator* generator = new ProfileGenerator(isolate, profiles);
ProfileGenerator* generator = new ProfileGenerator(profiles);
ProfilerEventsProcessor* processor =
new ProfilerEventsProcessor(CcTest::i_isolate(), generator,
v8::base::TimeDelta::FromMicroseconds(100));
......@@ -1077,7 +1077,7 @@ static void TickLines(bool optimize) {
CHECK(code_address);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfileGenerator* generator = new ProfileGenerator(isolate, profiles);
ProfileGenerator* generator = new ProfileGenerator(profiles);
ProfilerEventsProcessor* processor =
new ProfilerEventsProcessor(CcTest::i_isolate(), generator,
v8::base::TimeDelta::FromMicroseconds(100));
......
......@@ -350,7 +350,7 @@ TEST(RecordTickSample) {
CpuProfiler profiler(isolate);
profiles.set_cpu_profiler(&profiler);
profiles.StartProfiling("", false);
ProfileGenerator generator(isolate, &profiles);
ProfileGenerator generator(&profiles);
CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
......@@ -423,7 +423,7 @@ TEST(SampleIds) {
CpuProfiler profiler(isolate);
profiles.set_cpu_profiler(&profiler);
profiles.StartProfiling("", true);
ProfileGenerator generator(isolate, &profiles);
ProfileGenerator generator(&profiles);
CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
......@@ -481,7 +481,7 @@ TEST(NoSamples) {
CpuProfiler profiler(isolate);
profiles.set_cpu_profiler(&profiler);
profiles.StartProfiling("", false);
ProfileGenerator generator(isolate, &profiles);
ProfileGenerator generator(&profiles);
CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment