Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: src/platform-linux.cc

Issue 13627002: Add sanity test for CPU profiler (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Start sampler and processor threads synchronously Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 778
779 class Thread::PlatformData : public Malloced { 779 class Thread::PlatformData : public Malloced {
780 public: 780 public:
781 PlatformData() : thread_(kNoThread) {} 781 PlatformData() : thread_(kNoThread) {}
782 782
783 pthread_t thread_; // Thread handle for pthread. 783 pthread_t thread_; // Thread handle for pthread.
784 }; 784 };
785 785
786 Thread::Thread(const Options& options) 786 Thread::Thread(const Options& options)
787 : data_(new PlatformData()), 787 : data_(new PlatformData()),
788 stack_size_(options.stack_size()) { 788 stack_size_(options.stack_size()),
789 start_semaphore_(NULL) {
789 set_name(options.name()); 790 set_name(options.name());
790 } 791 }
791 792
792 793
793 Thread::~Thread() { 794 Thread::~Thread() {
794 delete data_; 795 delete data_;
795 } 796 }
796 797
797 798
798 static void* ThreadEntry(void* arg) { 799 static void* ThreadEntry(void* arg) {
799 Thread* thread = reinterpret_cast<Thread*>(arg); 800 Thread* thread = reinterpret_cast<Thread*>(arg);
800 // This is also initialized by the first argument to pthread_create() but we 801 // This is also initialized by the first argument to pthread_create() but we
801 // don't know which thread will run first (the original thread or the new 802 // don't know which thread will run first (the original thread or the new
802 // one) so we initialize it here too. 803 // one) so we initialize it here too.
803 #ifdef PR_SET_NAME 804 #ifdef PR_SET_NAME
804 prctl(PR_SET_NAME, 805 prctl(PR_SET_NAME,
805 reinterpret_cast<unsigned long>(thread->name()), // NOLINT 806 reinterpret_cast<unsigned long>(thread->name()), // NOLINT
806 0, 0, 0); 807 0, 0, 0);
807 #endif 808 #endif
808 thread->data()->thread_ = pthread_self(); 809 thread->data()->thread_ = pthread_self();
809 ASSERT(thread->data()->thread_ != kNoThread); 810 ASSERT(thread->data()->thread_ != kNoThread);
810 thread->Run(); 811 thread->NotifyStartedAndRun();
811 return NULL; 812 return NULL;
812 } 813 }
813 814
814 815
815 void Thread::set_name(const char* name) { 816 void Thread::set_name(const char* name) {
816 strncpy(name_, name, sizeof(name_)); 817 strncpy(name_, name, sizeof(name_));
817 name_[sizeof(name_) - 1] = '\0'; 818 name_[sizeof(name_) - 1] = '\0';
818 } 819 }
819 820
820 821
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 } 1177 }
1177 } 1178 }
1178 1179
1179 static void AddActiveSampler(Sampler* sampler) { 1180 static void AddActiveSampler(Sampler* sampler) {
1180 ScopedLock lock(mutex_); 1181 ScopedLock lock(mutex_);
1181 SamplerRegistry::AddActiveSampler(sampler); 1182 SamplerRegistry::AddActiveSampler(sampler);
1182 if (instance_ == NULL) { 1183 if (instance_ == NULL) {
1183 // Start a thread that will send SIGPROF signal to VM threads, 1184 // Start a thread that will send SIGPROF signal to VM threads,
1184 // when CPU profiling will be enabled. 1185 // when CPU profiling will be enabled.
1185 instance_ = new SignalSender(sampler->interval()); 1186 instance_ = new SignalSender(sampler->interval());
1186 instance_->Start(); 1187 instance_->StartSynchronously();
1187 } else { 1188 } else {
1188 ASSERT(instance_->interval_ == sampler->interval()); 1189 ASSERT(instance_->interval_ == sampler->interval());
1189 } 1190 }
1190 } 1191 }
1191 1192
1192 static void RemoveActiveSampler(Sampler* sampler) { 1193 static void RemoveActiveSampler(Sampler* sampler) {
1193 ScopedLock lock(mutex_); 1194 ScopedLock lock(mutex_);
1194 SamplerRegistry::RemoveActiveSampler(sampler); 1195 SamplerRegistry::RemoveActiveSampler(sampler);
1195 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 1196 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
1196 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); 1197 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 1336
1336 1337
1337 void Sampler::Stop() { 1338 void Sampler::Stop() {
1338 ASSERT(IsActive()); 1339 ASSERT(IsActive());
1339 SignalSender::RemoveActiveSampler(this); 1340 SignalSender::RemoveActiveSampler(this);
1340 SetActive(false); 1341 SetActive(false);
1341 } 1342 }
1342 1343
1343 1344
1344 } } // namespace v8::internal 1345 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698