From e82081a5061e06442c91ae952cef81050e7d3501 Mon Sep 17 00:00:00 2001 From: "mikhail.naganov@gmail.com" Date: Tue, 31 Aug 2010 14:16:01 +0000 Subject: [PATCH] CPU profiler: limit the number of simultaneously collected profiles. This is related to Chromium issue 51919 BUG=51919 TEST=test-profile-generator/Issue51919 Review URL: http://codereview.chromium.org/3287005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5384 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/profile-generator.cc | 4 ++++ src/profile-generator.h | 3 +++ test/cctest/test-profile-generator.cc | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/profile-generator.cc b/src/profile-generator.cc index 1c6c902..2de7a2f 100644 --- a/src/profile-generator.cc +++ b/src/profile-generator.cc @@ -492,6 +492,10 @@ CpuProfilesCollection::~CpuProfilesCollection() { bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid) { ASSERT(uid > 0); current_profiles_semaphore_->Wait(); + if (current_profiles_.length() >= kMaxSimultaneousProfiles) { + current_profiles_semaphore_->Signal(); + return false; + } for (int i = 0; i < current_profiles_.length(); ++i) { if (strcmp(current_profiles_[i]->title(), title) == 0) { // Ignore attempts to start profile with the same title. diff --git a/src/profile-generator.h b/src/profile-generator.h index 5611b6f..c6d6f4c 100644 --- a/src/profile-generator.h +++ b/src/profile-generator.h @@ -299,6 +299,9 @@ class CpuProfilesCollection { // Called from profile generator thread. void AddPathToCurrentProfiles(const Vector& path); + // Limits the number of profiles that can be simultaneously collected. + static const int kMaxSimultaneousProfiles = 100; + private: const char* GetName(int args_count); const char* GetFunctionName(String* name) { diff --git a/test/cctest/test-profile-generator.cc b/test/cctest/test-profile-generator.cc index ea477de..b362202 100644 --- a/test/cctest/test-profile-generator.cc +++ b/test/cctest/test-profile-generator.cc @@ -775,4 +775,21 @@ TEST(RecordStackTraceAtStartProfiling) { CHECK_EQ(0, current->children()->length()); } + +TEST(Issue51919) { + CpuProfilesCollection collection; + i::EmbeddedVector titles; + for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) { + i::Vector title = i::Vector::New(16); + i::OS::SNPrintF(title, "%d", i); + CHECK(collection.StartProfiling(title.start(), i + 1)); // UID must be > 0. + titles[i] = title.start(); + } + CHECK(!collection.StartProfiling( + "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1)); + for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) + i::DeleteArray(titles[i]); +} + #endif // ENABLE_LOGGING_AND_PROFILING -- 2.7.4