| Index: include/v8-sampler.h
|
| diff --git a/include/v8-sampler.h b/include/v8-sampler.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..30f467d6cbe956668eb202d2aede9b4427c62b29
|
| --- /dev/null
|
| +++ b/include/v8-sampler.h
|
| @@ -0,0 +1,114 @@
|
| +// Copyright 2016 the V8 project authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef V8_SAMPLER_H_
|
| +#define V8_SAMPLER_H_
|
| +
|
| +#include "src/globals.h"
|
| +#include "src/profiler/sampler.h"
|
| +
|
| +#if V8_OS_POSIX && !V8_OS_CYGWIN
|
| +#define USE_SIGNALS
|
| +#endif
|
| +
|
| +#if defined(ANDROID)
|
| + // Phones and tablets have processors that are much slower than desktop
|
| + // and laptop computers for which current heuristics are tuned.
|
| + static const int kSamplingIntervalMs = 5;
|
| +#else
|
| + static const int kSamplingIntervalMs = 1;
|
| +#endif
|
| +
|
| +namespace v8 {
|
| +
|
| +namespace internal {
|
| +class Isolate;
|
| +}
|
| +
|
| +class Isolate;
|
| +class SamplerThread;
|
| +#if defined(USE_SIGNALS)
|
| +class SignalHandler;
|
| +#endif
|
| +
|
| +class V8Sampler {
|
| + public:
|
| + // Initializes the sampler support. Called once at embedder startup.
|
| + static void SetUp();
|
| + static void TearDown();
|
| + static void SetInterval(int interval);
|
| +
|
| + // Initialize sampler.
|
| + V8Sampler(Isolate* isolate);
|
| + virtual ~V8Sampler();
|
| +
|
| + void CollectStackSample(const RegisterState& state,
|
| + void** frames, size_t frames_limit,
|
| + SampleInfo* sample_info);
|
| + void SetJitCodeEventHandler(JitCodeEventOptions,
|
| + void* handler);
|
| +
|
| + Isolate* isolate() const { return isolate_; }
|
| +
|
| + // Performs stack sampling.
|
| + void SampleStack(const RegisterState& regs);
|
| +
|
| + // Start and stop sampler.
|
| + void Start();
|
| + void Stop();
|
| +
|
| + // Whether the sampling thread should use this Sampler for CPU profiling?
|
| + bool IsProfiling() const {
|
| + return base::NoBarrier_Load(&profiling_) > 0 &&
|
| + !base::NoBarrier_Load(&has_processing_thread_);
|
| + }
|
| + void IncreaseProfilingDepth();
|
| + void DecreaseProfilingDepth();
|
| +
|
| + // Whether the sampler is running (that is, consumes resources).
|
| + bool IsActive() const { return base::NoBarrier_Load(&active_); }
|
| +
|
| + void DoSample();
|
| + // If true next sample must be initiated on the profiler event processor
|
| + // thread right after latest sample is processed.
|
| + void SetHasProcessingThread(bool value) {
|
| + base::NoBarrier_Store(&has_processing_thread_, value);
|
| + }
|
| +
|
| + // Used in tests to make sure that stack sampling is performed.
|
| + unsigned js_sample_count() const { return js_sample_count_; }
|
| + unsigned external_sample_count() const { return external_sample_count_; }
|
| + void StartCountingSamples() {
|
| + js_sample_count_ = 0;
|
| + external_sample_count_ = 0;
|
| + is_counting_samples_ = true;
|
| + }
|
| +
|
| + class PlatformData;
|
| + PlatformData* platform_data() const { return data_; }
|
| +
|
| + protected:
|
| + // This method is called for each sampling period with the current
|
| + // program counter.
|
| + virtual void Tick(i::TickSample* tick_sample) = 0;
|
| +
|
| + private:
|
| + void SetActive(bool value) { base::NoBarrier_Store(&active_, value); }
|
| +
|
| + Isolate* isolate_;
|
| + base::Atomic32 profiling_;
|
| + base::Atomic32 has_processing_thread_;
|
| + base::Atomic32 active_;
|
| + PlatformData* data_; // Platform specific data.
|
| + // Counts stack samples taken in JS VM state.
|
| + bool is_counting_samples_;
|
| + unsigned js_sample_count_;
|
| + unsigned external_sample_count_;
|
| + DISALLOW_COPY_AND_ASSIGN(V8Sampler);
|
| + // DISALLOW_IMPLICIT_CONSTRUCTORS(V8Sampler);
|
| +};
|
| +
|
| +} // v8
|
| +
|
| +#endif // V8_SAMPLER_H_
|
|
|