Reviewers: Søren Gjesse,
Description:
CPU profiler: limit the number of simultaneously collected profiles.
This is related to Chromium issue 51919
BUG=51919
TEST=test-profile-generator/Issue51919
Please review this at http://codereview.chromium.org/3287005/show
Affected files:
M src/profile-generator.h
M src/profile-generator.cc
M test/cctest/test-profile-generator.cc
Index: src/profile-generator.cc
diff --git a/src/profile-generator.cc b/src/profile-generator.cc
index
1c6c902a4dcd9c7abe5e5eddb6aac11d5b108484..2de7a2fb912ae8a444524a9ca5ce7f27ee207d65
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.
Index: src/profile-generator.h
diff --git a/src/profile-generator.h b/src/profile-generator.h
index
5611b6fa4ed3bf05f6937e3012a2f6781dab7796..c6d6f4cbc63fdd8d2cffb4b4b8bcb61302d22015
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<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: test/cctest/test-profile-generator.cc
diff --git a/test/cctest/test-profile-generator.cc
b/test/cctest/test-profile-generator.cc
index
ea477de661b788e48a6ffa91251f6bd0b496de1d..b36220284f29279c909c7498b2afa267ca267d30
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<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
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev