Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | List of all members
dart::Metric Class Reference

#include <metrics.h>

Inheritance diagram for dart::Metric:
dart::MaxMetric dart::MetricCurrentRSS dart::MetricHeapNewCapacity dart::MetricHeapNewExternal dart::MetricHeapNewUsed dart::MetricHeapOldCapacity dart::MetricHeapOldExternal dart::MetricHeapOldUsed dart::MetricHeapUsed dart::MetricIsolateCount dart::MetricPeakRSS dart::MinMetric dart::MyMetric

Public Types

enum  Unit { kCounter , kByte , kMicrosecond }
 

Public Member Functions

 Metric ()
 
void InitInstance (Isolate *isolate, const char *name, const char *description, Unit unit)
 
void InitInstance (IsolateGroup *isolate_group, const char *name, const char *description, Unit unit)
 
void InitInstance (const char *name, const char *description, Unit unit)
 
virtual ~Metric ()
 
void PrintJSON (JSONStream *stream)
 
char * ToString ()
 
int64_t value () const
 
void set_value (int64_t value)
 
void increment ()
 
const char * name () const
 
const char * description () const
 
Unit unit () const
 
Isolateisolate () const
 
IsolateGroupisolate_group () const
 
virtual int64_t Value () const
 

Static Public Member Functions

static void Init ()
 
static void Cleanup ()
 
static char * ValueToString (int64_t value, Unit unit)
 
static Metricvm_head ()
 

Detailed Description

Definition at line 53 of file metrics.h.

Member Enumeration Documentation

◆ Unit

Enumerator
kCounter 
kByte 
kMicrosecond 

Definition at line 55 of file metrics.h.

55 {
57 kByte,
59 };
@ kMicrosecond
Definition: metrics.h:58

Constructor & Destructor Documentation

◆ Metric()

dart::Metric::Metric ( )

Definition at line 23 of file metrics.cc.

23: unit_(kCounter), value_(0) {}

◆ ~Metric()

dart::Metric::~Metric ( )
virtual

Definition at line 24 of file metrics.cc.

24{}

Member Function Documentation

◆ Cleanup()

static void dart::Metric::Cleanup ( )
static

◆ description()

const char * dart::Metric::description ( ) const
inline

Definition at line 101 of file metrics.h.

101{ return description_; }

◆ increment()

void dart::Metric::increment ( )
inline

Definition at line 98 of file metrics.h.

98{ value_++; }

◆ Init()

static void dart::Metric::Init ( )
static

◆ InitInstance() [1/3]

void dart::Metric::InitInstance ( const char *  name,
const char *  description,
Unit  unit 
)

Definition at line 51 of file metrics.cc.

53 {
54 // Only called once.
55 ASSERT(name != nullptr);
56 name_ = name;
57 description_ = description;
58 unit_ = unit;
59}
const char * description() const
Definition: metrics.h:101
Unit unit() const
Definition: metrics.h:102
const char * name() const
Definition: metrics.h:100
#define ASSERT(E)

◆ InitInstance() [2/3]

void dart::Metric::InitInstance ( Isolate isolate,
const char *  name,
const char *  description,
Unit  unit 
)

Definition at line 39 of file metrics.cc.

42 {
43 // Only called once.
44 ASSERT(name != nullptr);
45 isolate_ = isolate;
46 name_ = name;
47 description_ = description;
48 unit_ = unit;
49}
Isolate * isolate() const
Definition: metrics.h:105

◆ InitInstance() [3/3]

void dart::Metric::InitInstance ( IsolateGroup isolate_group,
const char *  name,
const char *  description,
Unit  unit 
)

Definition at line 26 of file metrics.cc.

29 {
30 // Only called once.
31 ASSERT(name != nullptr);
32 isolate_group_ = isolate_group;
33 name_ = name;
34 description_ = description;
35 unit_ = unit;
36}
IsolateGroup * isolate_group() const
Definition: metrics.h:108

◆ isolate()

Isolate * dart::Metric::isolate ( ) const
inline

Definition at line 105 of file metrics.h.

105{ return isolate_; }

◆ isolate_group()

IsolateGroup * dart::Metric::isolate_group ( ) const
inline

Definition at line 108 of file metrics.h.

108{ return isolate_group_; }

◆ name()

const char * dart::Metric::name ( ) const
inline

Definition at line 100 of file metrics.h.

100{ return name_; }

◆ PrintJSON()

void dart::Metric::PrintJSON ( JSONStream stream)

Definition at line 76 of file metrics.cc.

76 {
77 JSONObject obj(stream);
78 obj.AddProperty("type", "Counter");
79 obj.AddProperty("name", name_);
80 obj.AddProperty("description", description_);
81 obj.AddProperty("unit", UnitString(unit()));
82 if (isolate_ == nullptr && isolate_group_ == nullptr) {
83 obj.AddFixedServiceId("vm/metrics/%s", name_);
84 } else {
85 obj.AddFixedServiceId("metrics/native/%s", name_);
86 }
87 // TODO(johnmccutchan): Overflow?
88 double value_as_double = static_cast<double>(Value());
89 obj.AddProperty("value", value_as_double);
90}
virtual int64_t Value() const
Definition: metrics.h:114
static const char * UnitString(intptr_t unit)
Definition: metrics.cc:61

◆ set_value()

void dart::Metric::set_value ( int64_t  value)
inline

Definition at line 96 of file metrics.h.

96{ value_ = value; }
int64_t value() const
Definition: metrics.h:95

◆ ToString()

char * dart::Metric::ToString ( )

Definition at line 136 of file metrics.cc.

136 {
137 Thread* thread = Thread::Current();
138 ASSERT(thread != nullptr);
139 Zone* zone = thread->zone();
140 ASSERT(zone != nullptr);
141 return zone->PrintToString("%s %s", name(), ValueToString(Value(), unit()));
142}
static char * ValueToString(int64_t value, Unit unit)
Definition: metrics.cc:93
static Thread * Current()
Definition: thread.h:362

◆ unit()

Unit dart::Metric::unit ( ) const
inline

Definition at line 102 of file metrics.h.

102{ return unit_; }

◆ value()

int64_t dart::Metric::value ( ) const
inline

Definition at line 95 of file metrics.h.

95{ return value_; }

◆ Value()

virtual int64_t dart::Metric::Value ( ) const
inlinevirtual

◆ ValueToString()

char * dart::Metric::ValueToString ( int64_t  value,
Unit  unit 
)
static

Definition at line 93 of file metrics.cc.

93 {
94 Thread* thread = Thread::Current();
95 ASSERT(thread != nullptr);
96 Zone* zone = thread->zone();
97 ASSERT(zone != nullptr);
98 switch (unit) {
99 case kCounter:
100 return zone->PrintToString("%" Pd64 "", value);
101 case kByte: {
102 const char* scaled_suffix = "B";
103 double scaled_value = static_cast<double>(value);
104 if (value > GB) {
105 scaled_suffix = "GB";
106 scaled_value /= GB;
107 } else if (value > MB) {
108 scaled_suffix = "MB";
109 scaled_value /= MB;
110 } else if (value > KB) {
111 scaled_suffix = "kB";
112 scaled_value /= KB;
113 }
114 return zone->PrintToString("%.3f %s (%" Pd64 " B)", scaled_value,
115 scaled_suffix, value);
116 }
117 case kMicrosecond: {
118 const char* scaled_suffix = "us";
119 double scaled_value = static_cast<double>(value);
121 scaled_suffix = "s";
122 scaled_value /= kMicrosecondsPerSecond;
123 } else if (value > kMicrosecondsPerMillisecond) {
124 scaled_suffix = "ms";
125 scaled_value /= kMicrosecondsPerMillisecond;
126 }
127 return zone->PrintToString("%.3f %s (%" Pd64 " us)", scaled_value,
128 scaled_suffix, value);
129 }
130 default:
131 UNREACHABLE();
132 return nullptr;
133 }
134}
#define UNREACHABLE()
Definition: assert.h:248
constexpr intptr_t MB
Definition: globals.h:530
constexpr intptr_t kMicrosecondsPerMillisecond
Definition: globals.h:561
constexpr intptr_t kMicrosecondsPerSecond
Definition: globals.h:562
constexpr intptr_t KB
Definition: globals.h:528
constexpr intptr_t GB
Definition: globals.h:532
#define Pd64
Definition: globals.h:416

◆ vm_head()

static Metric * dart::Metric::vm_head ( )
inlinestatic

Definition at line 110 of file metrics.h.

110{ return vm_list_head_; }

The documentation for this class was generated from the following files: