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
parent a63f9545
...@@ -492,6 +492,10 @@ CpuProfilesCollection::~CpuProfilesCollection() { ...@@ -492,6 +492,10 @@ CpuProfilesCollection::~CpuProfilesCollection() {
bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid) { bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid) {
ASSERT(uid > 0); ASSERT(uid > 0);
current_profiles_semaphore_->Wait(); current_profiles_semaphore_->Wait();
if (current_profiles_.length() >= kMaxSimultaneousProfiles) {
current_profiles_semaphore_->Signal();
return false;
}
for (int i = 0; i < current_profiles_.length(); ++i) { for (int i = 0; i < current_profiles_.length(); ++i) {
if (strcmp(current_profiles_[i]->title(), title) == 0) { if (strcmp(current_profiles_[i]->title(), title) == 0) {
// Ignore attempts to start profile with the same title. // Ignore attempts to start profile with the same title.
......
...@@ -299,6 +299,9 @@ class CpuProfilesCollection { ...@@ -299,6 +299,9 @@ class CpuProfilesCollection {
// Called from profile generator thread. // Called from profile generator thread.
void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path); void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path);
// Limits the number of profiles that can be simultaneously collected.
static const int kMaxSimultaneousProfiles = 100;
private: private:
const char* GetName(int args_count); const char* GetName(int args_count);
const char* GetFunctionName(String* name) { const char* GetFunctionName(String* name) {
......
...@@ -775,4 +775,21 @@ TEST(RecordStackTraceAtStartProfiling) { ...@@ -775,4 +775,21 @@ TEST(RecordStackTraceAtStartProfiling) {
CHECK_EQ(0, current->children()->length()); 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 #endif // ENABLE_LOGGING_AND_PROFILING
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