CPU profiler: limit the number of simultaneously collected profiles.
authormikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 31 Aug 2010 14:16:01 +0000 (14:16 +0000)
committermikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 31 Aug 2010 14:16:01 +0000 (14:16 +0000)
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
src/profile-generator.h
test/cctest/test-profile-generator.cc

index 1c6c902..2de7a2f 100644 (file)
@@ -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.
index 5611b6f..c6d6f4c 100644 (file)
@@ -299,6 +299,9 @@ class CpuProfilesCollection {
   // Called from profile generator thread.
   void AddPathToCurrentProfiles(const Vector<CodeEntry*>& 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) {
index ea477de..b362202 100644 (file)
@@ -775,4 +775,21 @@ TEST(RecordStackTraceAtStartProfiling) {
   CHECK_EQ(0, current->children()->length());
 }
 
+
+TEST(Issue51919) {
+  CpuProfilesCollection collection;
+  i::EmbeddedVector<char*,
+      CpuProfilesCollection::kMaxSimultaneousProfiles> titles;
+  for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) {
+    i::Vector<char> title = i::Vector<char>::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