Index: runtime/vm/profiler.h |
diff --git a/runtime/vm/profiler.h b/runtime/vm/profiler.h |
index bec51e648f0f0ab2ec96c07175e085016d2184c2..1e0ab7328c7863a8061017a3ffa99e40fcd2c696 100644 |
--- a/runtime/vm/profiler.h |
+++ b/runtime/vm/profiler.h |
@@ -5,109 +5,61 @@ |
#ifndef VM_PROFILER_H_ |
#define VM_PROFILER_H_ |
-#include "platform/hashmap.h" |
-#include "platform/thread.h" |
#include "vm/allocation.h" |
#include "vm/code_observers.h" |
#include "vm/globals.h" |
+#include "vm/thread.h" |
+#include "vm/thread_interrupter.h" |
namespace dart { |
// Forward declarations. |
+class JSONArray; |
class JSONStream; |
+struct Sample; |
-// Profiler manager. |
-class ProfilerManager : public AllStatic { |
+// Profiler |
+class Profiler : public AllStatic { |
public: |
static void InitOnce(); |
static void Shutdown(); |
- static void SetupIsolateForProfiling(Isolate* isolate); |
- static void ShutdownIsolateForProfiling(Isolate* isolate); |
- static void ScheduleIsolate(Isolate* isolate, bool inside_signal = false); |
- static void DescheduleIsolate(Isolate* isolate); |
+ static void InitProfilingForIsolate(Isolate* isolate, |
+ bool shared_buffer = false); |
+ static void ShutdownProfilingForIsolate(Isolate* isolate); |
+ |
+ static void BeginExecution(Isolate* isolate); |
+ static void EndExecution(Isolate* isolate); |
static void PrintToJSONStream(Isolate* isolate, JSONStream* stream); |
- static void WriteTracing(Isolate* isolate, const char* name, Dart_Port port); |
+ static void WriteTracing(Isolate* isolate); |
+ |
+ static SampleBuffer* sample_buffer() { |
+ return sample_buffer_; |
+ } |
private: |
- static const intptr_t kMaxProfiledIsolates = 4096; |
static bool initialized_; |
- static bool shutdown_; |
- static bool thread_running_; |
static Monitor* monitor_; |
- static Monitor* start_stop_monitor_; |
- |
- static Isolate** isolates_; |
- static intptr_t isolates_capacity_; |
- static intptr_t isolates_size_; |
- |
- static void ScheduleIsolateHelper(Isolate* isolate); |
- static void ResizeIsolates(intptr_t new_capacity); |
- static void AddIsolate(Isolate* isolate); |
- static intptr_t FindIsolate(Isolate* isolate); |
- static void RemoveIsolate(intptr_t i); |
- |
- // Returns the microseconds until the next live timer fires. |
- static int64_t SampleAndRescheduleIsolates(int64_t current_time); |
- static void FreeIsolateProfilingData(Isolate* isolate); |
- static void ThreadMain(uword parameters); |
-}; |
- |
- |
-class IsolateProfilerData { |
- public: |
- static const int64_t kDescheduledCpuUsage = -1; |
- static const int64_t kNoExpirationTime = -2; |
- |
- IsolateProfilerData(Isolate* isolate, SampleBuffer* sample_buffer); |
- ~IsolateProfilerData(); |
- |
- int64_t sample_interval_micros() const { return sample_interval_micros_; } |
- |
- void set_sample_interval_micros(int64_t sample_interval) { |
- sample_interval_micros_ = sample_interval; |
- } |
- |
- bool CanExpire() const { |
- return timer_expiration_micros_ != kNoExpirationTime; |
- } |
- bool ShouldSample(int64_t current_time) const { |
- return CanExpire() && TimeUntilExpiration(current_time) <= 0; |
- } |
- |
- int64_t TimeUntilExpiration(int64_t current_time_micros) const { |
- ASSERT(CanExpire()); |
- return timer_expiration_micros_ - current_time_micros; |
- } |
- |
- void set_cpu_usage(int64_t cpu_usage) { |
- cpu_usage_ = cpu_usage; |
- } |
- |
- void SampledAt(int64_t current_time); |
+ static void WriteTracingSample(Isolate* isolate, intptr_t pid, |
+ Sample* sample, JSONArray& events); |
- void Scheduled(int64_t current_time, ThreadId thread); |
+ static void RecordTickInterruptCallback(const InterruptedThreadState& state, |
+ void* data); |
- void Descheduled(); |
+ static void RecordSampleInterruptCallback(const InterruptedThreadState& state, |
+ void* data); |
- int64_t cpu_usage() const { return cpu_usage_; } |
- |
- int64_t ComputeDeltaAndSetCpuUsage(int64_t cpu_usage) { |
- int64_t delta = 0; |
- if (cpu_usage_ != kDescheduledCpuUsage) { |
- // Only compute the real delta if we are being sampled regularly. |
- delta = cpu_usage - cpu_usage_; |
- } |
- set_cpu_usage(cpu_usage); |
- return delta; |
- } |
+ static SampleBuffer* sample_buffer_; |
+}; |
- ThreadId thread_id() const { return thread_id_; } |
- Isolate* isolate() const { return isolate_; } |
+class IsolateProfilerData { |
+ public: |
+ IsolateProfilerData(SampleBuffer* sample_buffer, bool own_sample_buffer); |
+ ~IsolateProfilerData(); |
SampleBuffer* sample_buffer() const { return sample_buffer_; } |
@@ -116,13 +68,8 @@ class IsolateProfilerData { |
} |
private: |
- int64_t last_sampled_micros_; |
- int64_t timer_expiration_micros_; |
- int64_t sample_interval_micros_; |
- int64_t cpu_usage_; |
- ThreadId thread_id_; |
- Isolate* isolate_; |
SampleBuffer* sample_buffer_; |
+ bool own_sample_buffer_; |
DISALLOW_COPY_AND_ASSIGN(IsolateProfilerData); |
}; |
@@ -131,22 +78,26 @@ class IsolateProfilerData { |
struct Sample { |
static const char* kLookupSymbol; |
static const char* kNoSymbol; |
- static const intptr_t kNumStackFrames = 4; |
- enum SampleState { |
- kIdle = 0, |
- kExecuting = 1, |
- kNumSampleStates |
+ static const char* kNoFrame; |
+ static const intptr_t kNumStackFrames = 6; |
+ enum SampleType { |
+ kIsolateStart, |
+ kIsolateStop, |
+ kIsolateSample, |
}; |
int64_t timestamp; |
- int64_t cpu_usage; |
+ ThreadId tid; |
+ Isolate* isolate; |
uintptr_t pcs[kNumStackFrames]; |
+ SampleType type; |
uint16_t vm_tags; |
uint16_t runtime_tags; |
- Sample(); |
+ |
+ void Init(SampleType type, Isolate* isolate, int64_t timestamp, ThreadId tid); |
}; |
-// Ring buffer of samples. One per isolate. |
+// Ring buffer of samples. |
class SampleBuffer { |
public: |
static const intptr_t kDefaultBufferCapacity = 120000; // 2 minutes @ 1000hz. |
@@ -158,16 +109,17 @@ class SampleBuffer { |
Sample* ReserveSample(); |
- Sample* FirstSample() const; |
- Sample* NextSample(Sample* sample) const; |
- Sample* LastSample() const; |
+ Sample* GetSample(intptr_t i) const { |
+ ASSERT(i >= 0); |
+ ASSERT(i < capacity_); |
+ return &samples_[i]; |
+ } |
+ |
private: |
Sample* samples_; |
intptr_t capacity_; |
- intptr_t start_; |
- intptr_t end_; |
+ uintptr_t cursor_; |
- intptr_t WrapIncrement(intptr_t i) const; |
DISALLOW_COPY_AND_ASSIGN(SampleBuffer); |
}; |