OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 | 109 |
110 Atomic32 RuntimeProfiler::state_ = 0; | 110 Atomic32 RuntimeProfiler::state_ = 0; |
111 // TODO(isolates): Create the semaphore lazily and clean it up when no | 111 // TODO(isolates): Create the semaphore lazily and clean it up when no |
112 // longer required. | 112 // longer required. |
113 #ifdef ENABLE_LOGGING_AND_PROFILING | 113 #ifdef ENABLE_LOGGING_AND_PROFILING |
114 Semaphore* RuntimeProfiler::semaphore_ = OS::CreateSemaphore(0); | 114 Semaphore* RuntimeProfiler::semaphore_ = OS::CreateSemaphore(0); |
115 #endif | 115 #endif |
116 | 116 |
| 117 #ifdef DEBUG |
| 118 bool RuntimeProfiler::has_been_globally_setup_ = false; |
| 119 #endif |
| 120 bool RuntimeProfiler::enabled_ = false; |
| 121 |
117 | 122 |
118 RuntimeProfiler::RuntimeProfiler(Isolate* isolate) | 123 RuntimeProfiler::RuntimeProfiler(Isolate* isolate) |
119 : isolate_(isolate), | 124 : isolate_(isolate), |
120 sampler_threshold_(kSamplerThresholdInit), | 125 sampler_threshold_(kSamplerThresholdInit), |
121 sampler_threshold_size_factor_(kSamplerThresholdSizeFactorInit), | 126 sampler_threshold_size_factor_(kSamplerThresholdSizeFactorInit), |
122 sampler_ticks_until_threshold_adjustment_( | 127 sampler_ticks_until_threshold_adjustment_( |
123 kSamplerTicksBetweenThresholdAdjustment), | 128 kSamplerTicksBetweenThresholdAdjustment), |
124 js_ratio_(0), | 129 js_ratio_(0), |
125 sampler_window_position_(0), | 130 sampler_window_position_(0), |
126 optimize_soon_list_(NULL), | 131 optimize_soon_list_(NULL), |
127 state_window_position_(0), | 132 state_window_position_(0), |
128 state_window_ticks_(0) { | 133 state_window_ticks_(0) { |
129 state_counts_[IN_NON_JS_STATE] = kStateWindowSize; | 134 state_counts_[IN_NON_JS_STATE] = kStateWindowSize; |
130 state_counts_[IN_JS_STATE] = 0; | 135 state_counts_[IN_JS_STATE] = 0; |
131 STATIC_ASSERT(IN_NON_JS_STATE == 0); | 136 STATIC_ASSERT(IN_NON_JS_STATE == 0); |
132 memset(state_window_, 0, sizeof(state_window_)); | 137 memset(state_window_, 0, sizeof(state_window_)); |
133 ClearSampleBuffer(); | 138 ClearSampleBuffer(); |
134 } | 139 } |
135 | 140 |
136 | 141 |
137 bool RuntimeProfiler::IsEnabled() { | 142 void RuntimeProfiler::GlobalSetup() { |
138 return V8::UseCrankshaft() && FLAG_opt; | 143 ASSERT(!has_been_globally_setup_); |
| 144 enabled_ = V8::UseCrankshaft() && FLAG_opt; |
| 145 #ifdef DEBUG |
| 146 has_been_globally_setup_ = true; |
| 147 #endif |
139 } | 148 } |
140 | 149 |
141 | 150 |
142 void RuntimeProfiler::Optimize(JSFunction* function, bool eager, int delay) { | 151 void RuntimeProfiler::Optimize(JSFunction* function, bool eager, int delay) { |
143 ASSERT(function->IsOptimizable()); | 152 ASSERT(function->IsOptimizable()); |
144 if (FLAG_trace_opt) { | 153 if (FLAG_trace_opt) { |
145 PrintF("[marking (%s) ", eager ? "eagerly" : "lazily"); | 154 PrintF("[marking (%s) ", eager ? "eagerly" : "lazily"); |
146 function->PrintName(); | 155 function->PrintName(); |
147 PrintF(" for recompilation"); | 156 PrintF(" for recompilation"); |
148 if (delay > 0) { | 157 if (delay > 0) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 SamplerState state = IsSomeIsolateInJS() | 365 SamplerState state = IsSomeIsolateInJS() |
357 ? IN_JS_STATE | 366 ? IN_JS_STATE |
358 : IN_NON_JS_STATE; | 367 : IN_NON_JS_STATE; |
359 UpdateStateRatio(state); | 368 UpdateStateRatio(state); |
360 isolate_->stack_guard()->RequestRuntimeProfilerTick(); | 369 isolate_->stack_guard()->RequestRuntimeProfilerTick(); |
361 #endif | 370 #endif |
362 } | 371 } |
363 | 372 |
364 | 373 |
365 void RuntimeProfiler::Setup() { | 374 void RuntimeProfiler::Setup() { |
| 375 ASSERT(has_been_globally_setup_); |
366 ClearSampleBuffer(); | 376 ClearSampleBuffer(); |
367 // If the ticker hasn't already started, make sure to do so to get | 377 // If the ticker hasn't already started, make sure to do so to get |
368 // the ticks for the runtime profiler. | 378 // the ticks for the runtime profiler. |
369 if (IsEnabled()) isolate_->logger()->EnsureTickerStarted(); | 379 if (IsEnabled()) isolate_->logger()->EnsureTickerStarted(); |
370 } | 380 } |
371 | 381 |
372 | 382 |
373 void RuntimeProfiler::Reset() { | 383 void RuntimeProfiler::Reset() { |
374 sampler_threshold_ = kSamplerThresholdInit; | 384 sampler_threshold_ = kSamplerThresholdInit; |
375 sampler_threshold_size_factor_ = kSamplerThresholdSizeFactorInit; | 385 sampler_threshold_size_factor_ = kSamplerThresholdSizeFactorInit; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 } else { | 479 } else { |
470 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); | 480 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); |
471 } | 481 } |
472 } | 482 } |
473 #endif | 483 #endif |
474 return false; | 484 return false; |
475 } | 485 } |
476 | 486 |
477 | 487 |
478 } } // namespace v8::internal | 488 } } // namespace v8::internal |
OLD | NEW |