5#ifndef RUNTIME_VM_PROFILER_SERVICE_H_
6#define RUNTIME_VM_PROFILER_SERVICE_H_
19#if defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
20#include "perfetto/protozero/scattered_heap_buffer.h"
35class ProfileFunctionTable;
36class ProfileCodeTable;
39class ProcessedSampleBuffer;
46 void Tick(
bool exclusive);
54 intptr_t exclusive_ticks_;
55 intptr_t inclusive_ticks_;
57 DISALLOW_ALLOCATION();
63 for (intptr_t
i = 0;
i < kCacheSize;
i++) {
71 if (FLAG_trace_profiler) {
72 intptr_t total = cache_hit_ + cache_miss_;
74 cache_hit_, cache_miss_);
88 bool FindInCache(
uword pc,
104 intptr_t NextFreeIndex() {
105 cache_cursor_ = (cache_cursor_ + 1) % kCacheSize;
106 return cache_cursor_;
109 intptr_t OffsetForPC(
uword pc,
111 ProcessedSample* sample,
112 intptr_t frame_index);
117 inlined_functions.Clear();
118 inlined_token_positions.Clear();
122 GrowableArray<const Function*> inlined_functions;
123 GrowableArray<TokenPosition> inlined_token_positions;
124 TokenPosition token_position = TokenPosition::kNoSource;
127 static constexpr intptr_t kCacheSize = 128;
128 intptr_t cache_cursor_;
130 CacheEntry cache_[kCacheSize];
131 intptr_t cache_miss_;
156 const char*
Name()
const;
174 void Tick(
bool exclusive,
175 intptr_t inclusive_serial,
188 return source_position_ticks_.length();
192 return source_position_ticks_.At(
i);
199 const intptr_t table_index_;
203 intptr_t exclusive_ticks_;
204 intptr_t inclusive_ticks_;
205 intptr_t inclusive_serial_;
209 void AddProfileCode(intptr_t code_table_index);
219 void Tick(
bool exclusive);
227 intptr_t exclusive_ticks_;
228 intptr_t inclusive_ticks_;
267 compile_timestamp_ = timestamp;
285 const char*
name()
const {
return name_; }
298 void Tick(
uword pc,
bool exclusive, intptr_t
serial);
299 void TickAddress(
uword pc,
bool exclusive);
303 void PrintNativeCode(
JSONObject* profile_code_obj);
304 void PrintCollectedCode(
JSONObject* profile_code_obj);
305 void PrintOverwrittenCode(
JSONObject* profile_code_obj);
306 void PrintTagCode(
JSONObject* profile_code_obj);
308 void set_code_table_index(intptr_t index) { code_table_index_ = index; }
313 intptr_t exclusive_ticks_;
314 intptr_t inclusive_ticks_;
315 intptr_t inclusive_serial_;
317 const AbstractCode code_;
319 int64_t compile_timestamp_;
320 ProfileFunction* function_;
321 intptr_t code_table_index_;
322 ZoneGrowableArray<ProfileCodeAddress> address_ticks_;
331 intptr_t
length()
const {
return table_.length(); }
336 return table_[index];
356 void FindNeighbors(
uword pc,
363 void VerifyOverlap();
395 bool include_code_samples,
396 bool is_event =
false);
397#if defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
405 void ProcessSampleFrameJSON(
JSONArray* stack,
408 intptr_t frame_index);
409#if defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
410 void ProcessSampleFramePerfetto(
414 intptr_t frame_index);
416 void ProcessInlinedFunctionFrameJSON(
JSONArray* stack,
419 void PrintCodeFrameIndexJSON(
JSONArray* stack,
421 intptr_t frame_index);
422 void PrintSamplesJSON(
JSONObject* obj,
bool code_samples);
423#if defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
429 void PrintSamplesPerfetto(
431 protozero::HeapBuffered<perfetto::protos::pbzero::TracePacket>* packet);
440 intptr_t dead_code_index_offset_;
441 intptr_t tag_code_index_offset_;
446 intptr_t sample_count_;
457 int64_t time_origin_micros,
458 int64_t time_extent_micros,
459 bool include_code_samples);
461#if defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
466 int64_t time_origin_micros,
467 int64_t time_extent_micros);
472 int64_t time_origin_micros,
473 int64_t time_extent_micros);
476 int64_t time_origin_micros,
477 int64_t time_extent_micros);
482 enum PrintFormat :
bool { JSON =
false, Perfetto =
true };
484 static void PrintCommonImpl(PrintFormat
format,
489 bool include_code_samples);
497 static void PrintCommon(PrintFormat
format,
499 int64_t time_origin_micros,
500 int64_t time_extent_micros,
501 bool include_code_samples =
false);
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
void Tick(bool exclusive)
ProfileCodeAddress(uword pc)
intptr_t exclusive_ticks() const
intptr_t inclusive_ticks() const
ProfileCodeInlinedFunctionsCache()
~ProfileCodeInlinedFunctionsCache()
void Get(uword pc, const Code &code, ProcessedSample *sample, intptr_t frame_index, GrowableArray< const Function * > **inlined_functions, GrowableArray< TokenPosition > **inlined_token_positions, TokenPosition *token_position)
ProfileCode * At(intptr_t index) const
intptr_t InsertCode(ProfileCode *new_code)
ProfileCode * FindCodeForPC(uword pc) const
intptr_t FindCodeIndexForPC(uword pc) const
void ExpandUpper(uword end)
const AbstractCode code() const
void set_inclusive_ticks(intptr_t inclusive_ticks)
void TruncateLower(uword start)
intptr_t inclusive_ticks() const
static const char * KindToCString(Kind kind)
int64_t compile_timestamp() const
ProfileFunction * function() const
void TruncateUpper(uword end)
void SetName(const char *name)
intptr_t exclusive_ticks() const
bool IsOptimizedDart() const
bool Contains(uword pc) const
void ExpandLower(uword start)
void PrintToJSONArray(JSONArray *codes)
bool Overlaps(const ProfileCode *other) const
void set_compile_timestamp(int64_t timestamp)
void GenerateAndSetSymbolName(const char *prefix)
void set_exclusive_ticks(intptr_t exclusive_ticks)
ProfileCode(Kind kind, uword start, uword end, int64_t timestamp, const AbstractCode code)
void set_start(uword start)
const char * name() const
intptr_t code_table_index() const
intptr_t exclusive_ticks() const
intptr_t inclusive_ticks() const
TokenPosition token_pos() const
ProfileFunctionSourcePosition(TokenPosition token_pos)
void Tick(bool exclusive)
ProfileFunction(Kind kind, const char *name, const Function &function, const intptr_t table_index)
void Tick(bool exclusive, intptr_t inclusive_serial, TokenPosition token_position)
const Function * function() const
intptr_t table_index() const
const char * name() const
void TickSourcePosition(TokenPosition token_position, bool exclusive)
intptr_t inclusive_ticks() const
const char * ResolvedScriptUrl() const
void PrintToJSONArray(JSONArray *functions, bool print_only_ids=false)
bool GetSinglePosition(ProfileFunctionSourcePosition *pfsp)
intptr_t exclusive_ticks() const
const ProfileFunctionSourcePosition & GetSourcePosition(intptr_t i) const
const char * Name() const
intptr_t NumSourcePositions() const
static const char * KindToCString(Kind kind)
intptr_t sample_count() const
ProcessedSample * SampleAt(intptr_t index)
ProfileCode * GetCodeFromPC(uword pc, int64_t timestamp)
intptr_t NumFunctions() const
void Build(Thread *thread, Isolate *isolate, SampleFilter *filter, SampleBlockBuffer *sample_block_buffer)
ProfileCode * GetCode(intptr_t index)
void PrintProfileJSON(JSONStream *stream, bool include_code_samples)
ProfileFunction * FindFunction(const Function &function)
ProfileFunction * GetFunction(intptr_t index)
int64_t GetTimeSpan() const
static void PrintAllocationJSON(JSONStream *stream, const Class &cls, int64_t time_origin_micros, int64_t time_extent_micros)
static void ClearSamples()
static void PrintJSON(JSONStream *stream, int64_t time_origin_micros, int64_t time_extent_micros, bool include_code_samples)
uint32_t uint32_t * format
Dart_NativeFunction function
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer