Flutter Engine
flutter::CounterValues Class Reference

#include <instrumentation.h>

Public Member Functions

 CounterValues ()
 
 ~CounterValues ()
 
void Add (int64_t value)
 
void Visualize (SkCanvas *canvas, const SkRect &rect) const
 
int64_t GetCurrentValue () const
 
int64_t GetMaxValue () const
 
int64_t GetMinValue () const
 

Detailed Description

Definition at line 76 of file instrumentation.h.

Constructor & Destructor Documentation

◆ CounterValues()

flutter::CounterValues::CounterValues ( )

Definition at line 232 of file instrumentation.cc.

References ~CounterValues().

232  : current_sample_(kMaxSamples - 1) {
233  values_.resize(kMaxSamples, 0);
234 }
static const size_t kMaxSamples

◆ ~CounterValues()

flutter::CounterValues::~CounterValues ( )
default

Referenced by CounterValues().

Member Function Documentation

◆ Add()

void flutter::CounterValues::Add ( int64_t  value)

Definition at line 238 of file instrumentation.cc.

References value.

238  {
239  current_sample_ = (current_sample_ + 1) % kMaxSamples;
240  values_[current_sample_] = value;
241 }
static const size_t kMaxSamples
uint8_t value

◆ GetCurrentValue()

int64_t flutter::CounterValues::GetCurrentValue ( ) const

Definition at line 304 of file instrumentation.cc.

304  {
305  return values_[current_sample_];
306 }

◆ GetMaxValue()

int64_t flutter::CounterValues::GetMaxValue ( ) const

Definition at line 308 of file instrumentation.cc.

References flutter::kMaxSamples.

Referenced by Visualize().

308  {
309  auto max = std::numeric_limits<int64_t>::min();
310  for (size_t i = 0; i < kMaxSamples; ++i) {
311  max = std::max<int64_t>(max, values_[i]);
312  }
313  return max;
314 }
static const size_t kMaxSamples

◆ GetMinValue()

int64_t flutter::CounterValues::GetMinValue ( ) const

Definition at line 316 of file instrumentation.cc.

References flutter::kMaxSamples.

Referenced by Visualize().

316  {
317  auto min = std::numeric_limits<int64_t>::max();
318  for (size_t i = 0; i < kMaxSamples; ++i) {
319  min = std::min<int64_t>(min, values_[i]);
320  }
321  return min;
322 }
static const size_t kMaxSamples

◆ Visualize()

void flutter::CounterValues::Visualize ( SkCanvas *  canvas,
const SkRect &  rect 
) const

Definition at line 243 of file instrumentation.cc.

References GetMaxValue(), GetMinValue(), height, flutter::kMaxSamples, flutter::path, and width.

243  {
244  size_t max_bytes = GetMaxValue();
245 
246  if (max_bytes == 0) {
247  // The backend for this counter probably did not fill in any values.
248  return;
249  }
250 
251  size_t min_bytes = GetMinValue();
252 
253  SkPaint paint;
254 
255  // Paint the background.
256  paint.setColor(0x99FFFFFF);
257  canvas->drawRect(rect, paint);
258 
259  // Establish the graph position.
260  const SkScalar x = rect.x();
261  const SkScalar y = rect.y();
262  const SkScalar width = rect.width();
263  const SkScalar height = rect.height();
264  const SkScalar bottom = y + height;
265  const SkScalar right = x + width;
266 
267  // Prepare a path for the data.
268  SkPath path;
269  path.moveTo(x, bottom);
270 
271  for (size_t i = 0; i < kMaxSamples; ++i) {
272  int64_t current_bytes = values_[i];
273  double ratio = static_cast<double>(current_bytes - min_bytes) /
274  static_cast<double>(max_bytes - min_bytes);
275  path.lineTo(
276  x + ((static_cast<double>(i) / static_cast<double>(kMaxSamples)) *
277  width),
278  y + ((1.0 - ratio) * height));
279  }
280 
281  path.rLineTo(100, 0);
282  path.lineTo(right, bottom);
283  path.close();
284 
285  // Draw the graph.
286  paint.setColor(0xAA0000FF);
287  canvas->drawPath(path, paint);
288 
289  // Paint the vertical marker for the current frame.
290  const double sample_unit_width = (1.0 / kMaxSamples);
291  const double sample_margin_unit_width = sample_unit_width / 6.0;
292  const double sample_margin_width = width * sample_margin_unit_width;
293  paint.setStyle(SkPaint::Style::kFill_Style);
294  paint.setColor(SK_ColorGRAY);
295  double sample_x =
296  x + width * (static_cast<double>(current_sample_) / kMaxSamples) -
297  sample_margin_width;
298  const auto marker_rect = SkRect::MakeLTRB(
299  sample_x, y,
300  sample_x + width * sample_unit_width + sample_margin_width * 2, bottom);
301  canvas->drawRect(marker_rect, paint);
302 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
static const size_t kMaxSamples
int32_t height
int32_t width
int64_t GetMaxValue() const
int64_t GetMinValue() const

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