| 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 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 // Glibc doesn't provide a wrapper for gettid(2). | 803 // Glibc doesn't provide a wrapper for gettid(2). |
| 804 return syscall(SYS_gettid); | 804 return syscall(SYS_gettid); |
| 805 } | 805 } |
| 806 | 806 |
| 807 | 807 |
| 808 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { | 808 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { |
| 809 #ifndef V8_HOST_ARCH_MIPS | 809 #ifndef V8_HOST_ARCH_MIPS |
| 810 USE(info); | 810 USE(info); |
| 811 if (signal != SIGPROF) return; | 811 if (signal != SIGPROF) return; |
| 812 Isolate* isolate = Isolate::UncheckedCurrent(); | 812 Isolate* isolate = Isolate::UncheckedCurrent(); |
| 813 if (isolate == NULL || !isolate->IsInUse()) return; | 813 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { |
| 814 // We require a fully initialized and entered isolate. |
| 815 return; |
| 816 } |
| 814 Sampler* sampler = isolate->logger()->sampler(); | 817 Sampler* sampler = isolate->logger()->sampler(); |
| 815 if (sampler == NULL || !sampler->IsActive()) return; | 818 if (sampler == NULL || !sampler->IsActive()) return; |
| 816 | 819 |
| 817 TickSample sample_obj; | 820 TickSample sample_obj; |
| 818 TickSample* sample = CpuProfiler::TickSampleEvent(isolate); | 821 TickSample* sample = CpuProfiler::TickSampleEvent(isolate); |
| 819 if (sample == NULL) sample = &sample_obj; | 822 if (sample == NULL) sample = &sample_obj; |
| 820 | 823 |
| 821 // Extracting the sample from the context is extremely machine dependent. | 824 // Extracting the sample from the context is extremely machine dependent. |
| 822 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); | 825 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); |
| 823 mcontext_t& mcontext = ucontext->uc_mcontext; | 826 mcontext_t& mcontext = ucontext->uc_mcontext; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 static void AddActiveSampler(Sampler* sampler) { | 878 static void AddActiveSampler(Sampler* sampler) { |
| 876 ScopedLock lock(mutex_); | 879 ScopedLock lock(mutex_); |
| 877 SamplerRegistry::AddActiveSampler(sampler); | 880 SamplerRegistry::AddActiveSampler(sampler); |
| 878 if (instance_ == NULL) { | 881 if (instance_ == NULL) { |
| 879 // Install a signal handler. | 882 // Install a signal handler. |
| 880 struct sigaction sa; | 883 struct sigaction sa; |
| 881 sa.sa_sigaction = ProfilerSignalHandler; | 884 sa.sa_sigaction = ProfilerSignalHandler; |
| 882 sigemptyset(&sa.sa_mask); | 885 sigemptyset(&sa.sa_mask); |
| 883 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 886 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
| 884 signal_handler_installed_ = | 887 signal_handler_installed_ = |
| 885 (sigaction(SIGPROF, &sa, &old_signal_handler_) != 0); | 888 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); |
| 886 | 889 |
| 887 // Start a thread that sends SIGPROF signal to VM threads. | 890 // Start a thread that sends SIGPROF signal to VM threads. |
| 888 instance_ = new SignalSender(sampler->interval()); | 891 instance_ = new SignalSender(sampler->interval()); |
| 889 instance_->Start(); | 892 instance_->Start(); |
| 890 } else { | 893 } else { |
| 891 ASSERT(instance_->interval_ == sampler->interval()); | 894 ASSERT(instance_->interval_ == sampler->interval()); |
| 892 } | 895 } |
| 893 } | 896 } |
| 894 | 897 |
| 895 static void RemoveActiveSampler(Sampler* sampler) { | 898 static void RemoveActiveSampler(Sampler* sampler) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 | 1031 |
| 1029 void Sampler::Stop() { | 1032 void Sampler::Stop() { |
| 1030 ASSERT(IsActive()); | 1033 ASSERT(IsActive()); |
| 1031 SignalSender::RemoveActiveSampler(this); | 1034 SignalSender::RemoveActiveSampler(this); |
| 1032 SetActive(false); | 1035 SetActive(false); |
| 1033 } | 1036 } |
| 1034 | 1037 |
| 1035 #endif // ENABLE_LOGGING_AND_PROFILING | 1038 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1036 | 1039 |
| 1037 } } // namespace v8::internal | 1040 } } // namespace v8::internal |
| OLD | NEW |