OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 577 |
578 Thread::~Thread() { | 578 Thread::~Thread() { |
579 } | 579 } |
580 | 580 |
581 | 581 |
582 static void* ThreadEntry(void* arg) { | 582 static void* ThreadEntry(void* arg) { |
583 Thread* thread = reinterpret_cast<Thread*>(arg); | 583 Thread* thread = reinterpret_cast<Thread*>(arg); |
584 // This is also initialized by the first argument to pthread_create() but we | 584 // This is also initialized by the first argument to pthread_create() but we |
585 // don't know which thread will run first (the original thread or the new | 585 // don't know which thread will run first (the original thread or the new |
586 // one) so we initialize it here too. | 586 // one) so we initialize it here too. |
587 prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread->name()), 0, 0, 0); | 587 prctl(PR_SET_NAME, |
| 588 reinterpret_cast<unsigned long>(thread->name()), // NOLINT |
| 589 0, 0, 0); |
588 thread->thread_handle_data()->thread_ = pthread_self(); | 590 thread->thread_handle_data()->thread_ = pthread_self(); |
589 ASSERT(thread->IsValid()); | 591 ASSERT(thread->IsValid()); |
590 thread->Run(); | 592 thread->Run(); |
591 return NULL; | 593 return NULL; |
592 } | 594 } |
593 | 595 |
594 | 596 |
595 void Thread::set_name(const char* name) { | 597 void Thread::set_name(const char* name) { |
596 strncpy(name_, name, sizeof(name_)); | 598 strncpy(name_, name, sizeof(name_)); |
597 name_[sizeof(name_) - 1] = '\0'; | 599 name_[sizeof(name_) - 1] = '\0'; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 Sleep(HALF_INTERVAL); | 866 Sleep(HALF_INTERVAL); |
865 } else { | 867 } else { |
866 if (sampler_->IsProfiling()) SendProfilingSignal(); | 868 if (sampler_->IsProfiling()) SendProfilingSignal(); |
867 if (RuntimeProfiler::IsEnabled()) RuntimeProfiler::NotifyTick(); | 869 if (RuntimeProfiler::IsEnabled()) RuntimeProfiler::NotifyTick(); |
868 Sleep(FULL_INTERVAL); | 870 Sleep(FULL_INTERVAL); |
869 } | 871 } |
870 } | 872 } |
871 } | 873 } |
872 | 874 |
873 void SendProfilingSignal() { | 875 void SendProfilingSignal() { |
| 876 if (!signal_handler_installed_) return; |
874 // Glibc doesn't provide a wrapper for tgkill(2). | 877 // Glibc doesn't provide a wrapper for tgkill(2). |
875 syscall(SYS_tgkill, vm_tgid_, vm_tid_, SIGPROF); | 878 syscall(SYS_tgkill, vm_tgid_, vm_tid_, SIGPROF); |
876 } | 879 } |
877 | 880 |
878 void Sleep(SleepInterval full_or_half) { | 881 void Sleep(SleepInterval full_or_half) { |
879 // Convert ms to us and subtract 100 us to compensate delays | 882 // Convert ms to us and subtract 100 us to compensate delays |
880 // occuring during signal delivery. | 883 // occuring during signal delivery. |
881 useconds_t interval = sampler_->interval_ * 1000 - 100; | 884 useconds_t interval = sampler_->interval_ * 1000 - 100; |
882 if (full_or_half == HALF_INTERVAL) interval /= 2; | 885 if (full_or_half == HALF_INTERVAL) interval /= 2; |
883 int result = usleep(interval); | 886 int result = usleep(interval); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 // There can only be one active sampler at the time on POSIX | 933 // There can only be one active sampler at the time on POSIX |
931 // platforms. | 934 // platforms. |
932 ASSERT(!IsActive()); | 935 ASSERT(!IsActive()); |
933 vm_tid_ = GetThreadID(); | 936 vm_tid_ = GetThreadID(); |
934 | 937 |
935 // Request profiling signals. | 938 // Request profiling signals. |
936 struct sigaction sa; | 939 struct sigaction sa; |
937 sa.sa_sigaction = ProfilerSignalHandler; | 940 sa.sa_sigaction = ProfilerSignalHandler; |
938 sigemptyset(&sa.sa_mask); | 941 sigemptyset(&sa.sa_mask); |
939 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 942 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
940 if (sigaction(SIGPROF, &sa, &data_->old_signal_handler_) != 0) return; | 943 data_->signal_handler_installed_ = |
941 data_->signal_handler_installed_ = true; | 944 sigaction(SIGPROF, &sa, &data_->old_signal_handler_) == 0; |
942 | 945 |
943 // Start a thread that sends SIGPROF signal to VM thread. | 946 // Start a thread that sends SIGPROF signal to VM thread. |
944 // Sending the signal ourselves instead of relying on itimer provides | 947 // Sending the signal ourselves instead of relying on itimer provides |
945 // much better accuracy. | 948 // much better accuracy. |
946 SetActive(true); | 949 SetActive(true); |
947 if (pthread_create( | 950 if (pthread_create( |
948 &data_->signal_sender_thread_, NULL, SenderEntry, data_) == 0) { | 951 &data_->signal_sender_thread_, NULL, SenderEntry, data_) == 0) { |
949 data_->signal_sender_launched_ = true; | 952 data_->signal_sender_launched_ = true; |
950 } | 953 } |
951 | 954 |
(...skipping 20 matching lines...) Expand all Loading... |
972 } | 975 } |
973 | 976 |
974 // This sampler is no longer the active sampler. | 977 // This sampler is no longer the active sampler. |
975 active_sampler_ = NULL; | 978 active_sampler_ = NULL; |
976 } | 979 } |
977 | 980 |
978 | 981 |
979 #endif // ENABLE_LOGGING_AND_PROFILING | 982 #endif // ENABLE_LOGGING_AND_PROFILING |
980 | 983 |
981 } } // namespace v8::internal | 984 } } // namespace v8::internal |
OLD | NEW |