| 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 virtual void* memory() { return memory_; } | 320 virtual void* memory() { return memory_; } |
| 321 virtual int size() { return size_; } | 321 virtual int size() { return size_; } |
| 322 private: | 322 private: |
| 323 FILE* file_; | 323 FILE* file_; |
| 324 void* memory_; | 324 void* memory_; |
| 325 int size_; | 325 int size_; |
| 326 }; | 326 }; |
| 327 | 327 |
| 328 | 328 |
| 329 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { | 329 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { |
| 330 FILE* file = fopen(name, "w+"); | 330 FILE* file = fopen(name, "r+"); |
| 331 if (file == NULL) return NULL; | 331 if (file == NULL) return NULL; |
| 332 | 332 |
| 333 fseek(file, 0, SEEK_END); | 333 fseek(file, 0, SEEK_END); |
| 334 int size = ftell(file); | 334 int size = ftell(file); |
| 335 | 335 |
| 336 void* memory = | 336 void* memory = |
| 337 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); | 337 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); |
| 338 return new PosixMemoryMappedFile(file, memory, size); | 338 return new PosixMemoryMappedFile(file, memory, size); |
| 339 } | 339 } |
| 340 | 340 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 610 |
| 611 Thread::~Thread() { | 611 Thread::~Thread() { |
| 612 } | 612 } |
| 613 | 613 |
| 614 | 614 |
| 615 static void* ThreadEntry(void* arg) { | 615 static void* ThreadEntry(void* arg) { |
| 616 Thread* thread = reinterpret_cast<Thread*>(arg); | 616 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 617 // This is also initialized by the first argument to pthread_create() but we | 617 // This is also initialized by the first argument to pthread_create() but we |
| 618 // don't know which thread will run first (the original thread or the new | 618 // don't know which thread will run first (the original thread or the new |
| 619 // one) so we initialize it here too. | 619 // one) so we initialize it here too. |
| 620 prctl(PR_SET_NAME, thread->name(), 0, 0, 0); | 620 prctl(PR_SET_NAME, |
| 621 reinterpret_cast<unsigned long>(thread->name()), // NOLINT |
| 622 0, 0, 0); |
| 621 thread->thread_handle_data()->thread_ = pthread_self(); | 623 thread->thread_handle_data()->thread_ = pthread_self(); |
| 622 ASSERT(thread->IsValid()); | 624 ASSERT(thread->IsValid()); |
| 623 thread->Run(); | 625 thread->Run(); |
| 624 return NULL; | 626 return NULL; |
| 625 } | 627 } |
| 626 | 628 |
| 627 | 629 |
| 628 void Thread::set_name(const char* name) { | 630 void Thread::set_name(const char* name) { |
| 629 strncpy(name_, name, sizeof(name_)); | 631 strncpy(name_, name, sizeof(name_)); |
| 630 name_[sizeof(name_) - 1] = '\0'; | 632 name_[sizeof(name_) - 1] = '\0'; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 Sleep(HALF_INTERVAL); | 899 Sleep(HALF_INTERVAL); |
| 898 } else { | 900 } else { |
| 899 if (sampler_->IsProfiling()) SendProfilingSignal(); | 901 if (sampler_->IsProfiling()) SendProfilingSignal(); |
| 900 if (RuntimeProfiler::IsEnabled()) RuntimeProfiler::NotifyTick(); | 902 if (RuntimeProfiler::IsEnabled()) RuntimeProfiler::NotifyTick(); |
| 901 Sleep(FULL_INTERVAL); | 903 Sleep(FULL_INTERVAL); |
| 902 } | 904 } |
| 903 } | 905 } |
| 904 } | 906 } |
| 905 | 907 |
| 906 void SendProfilingSignal() { | 908 void SendProfilingSignal() { |
| 909 if (!signal_handler_installed_) return; |
| 907 // Glibc doesn't provide a wrapper for tgkill(2). | 910 // Glibc doesn't provide a wrapper for tgkill(2). |
| 908 syscall(SYS_tgkill, vm_tgid_, vm_tid_, SIGPROF); | 911 syscall(SYS_tgkill, vm_tgid_, vm_tid_, SIGPROF); |
| 909 } | 912 } |
| 910 | 913 |
| 911 void Sleep(SleepInterval full_or_half) { | 914 void Sleep(SleepInterval full_or_half) { |
| 912 // Convert ms to us and subtract 100 us to compensate delays | 915 // Convert ms to us and subtract 100 us to compensate delays |
| 913 // occuring during signal delivery. | 916 // occuring during signal delivery. |
| 914 useconds_t interval = sampler_->interval_ * 1000 - 100; | 917 useconds_t interval = sampler_->interval_ * 1000 - 100; |
| 915 if (full_or_half == HALF_INTERVAL) interval /= 2; | 918 if (full_or_half == HALF_INTERVAL) interval /= 2; |
| 916 int result = usleep(interval); | 919 int result = usleep(interval); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 // There can only be one active sampler at the time on POSIX | 966 // There can only be one active sampler at the time on POSIX |
| 964 // platforms. | 967 // platforms. |
| 965 ASSERT(!IsActive()); | 968 ASSERT(!IsActive()); |
| 966 vm_tid_ = GetThreadID(); | 969 vm_tid_ = GetThreadID(); |
| 967 | 970 |
| 968 // Request profiling signals. | 971 // Request profiling signals. |
| 969 struct sigaction sa; | 972 struct sigaction sa; |
| 970 sa.sa_sigaction = ProfilerSignalHandler; | 973 sa.sa_sigaction = ProfilerSignalHandler; |
| 971 sigemptyset(&sa.sa_mask); | 974 sigemptyset(&sa.sa_mask); |
| 972 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 975 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
| 973 if (sigaction(SIGPROF, &sa, &data_->old_signal_handler_) != 0) return; | 976 data_->signal_handler_installed_ = |
| 974 data_->signal_handler_installed_ = true; | 977 sigaction(SIGPROF, &sa, &data_->old_signal_handler_) == 0; |
| 975 | 978 |
| 976 // Start a thread that sends SIGPROF signal to VM thread. | 979 // Start a thread that sends SIGPROF signal to VM thread. |
| 977 // Sending the signal ourselves instead of relying on itimer provides | 980 // Sending the signal ourselves instead of relying on itimer provides |
| 978 // much better accuracy. | 981 // much better accuracy. |
| 979 SetActive(true); | 982 SetActive(true); |
| 980 if (pthread_create( | 983 if (pthread_create( |
| 981 &data_->signal_sender_thread_, NULL, SenderEntry, data_) == 0) { | 984 &data_->signal_sender_thread_, NULL, SenderEntry, data_) == 0) { |
| 982 data_->signal_sender_launched_ = true; | 985 data_->signal_sender_launched_ = true; |
| 983 } | 986 } |
| 984 | 987 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1005 } | 1008 } |
| 1006 | 1009 |
| 1007 // This sampler is no longer the active sampler. | 1010 // This sampler is no longer the active sampler. |
| 1008 active_sampler_ = NULL; | 1011 active_sampler_ = NULL; |
| 1009 } | 1012 } |
| 1010 | 1013 |
| 1011 | 1014 |
| 1012 #endif // ENABLE_LOGGING_AND_PROFILING | 1015 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1013 | 1016 |
| 1014 } } // namespace v8::internal | 1017 } } // namespace v8::internal |
| OLD | NEW |