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.
// 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) {
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