forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instrumentation.h
88 lines (55 loc) · 1.68 KB
/
instrumentation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2015 The Chromium 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 FLUTTER_FLOW_INSTRUMENTATION_H_
#define FLUTTER_FLOW_INSTRUMENTATION_H_
#include <vector>
#include "lib/fxl/macros.h"
#include "lib/fxl/time/time_delta.h"
#include "lib/fxl/time/time_point.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace flow {
static const double kOneFrameMS = 1e3 / 60.0;
class Stopwatch {
public:
Stopwatch();
~Stopwatch();
const fxl::TimeDelta& LastLap() const;
fxl::TimeDelta CurrentLap() const { return fxl::TimePoint::Now() - start_; }
fxl::TimeDelta MaxDelta() const;
void Visualize(SkCanvas& canvas, const SkRect& rect) const;
void Start();
void Stop();
void SetLapTime(const fxl::TimeDelta& delta);
private:
fxl::TimePoint start_;
std::vector<fxl::TimeDelta> laps_;
size_t current_sample_;
FXL_DISALLOW_COPY_AND_ASSIGN(Stopwatch);
};
class Counter {
public:
Counter() : count_(0) {}
size_t count() const { return count_; }
void Reset(size_t count = 0) { count_ = count; }
void Increment(size_t count = 1) { count_ += count; }
private:
size_t count_;
FXL_DISALLOW_COPY_AND_ASSIGN(Counter);
};
class CounterValues {
public:
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;
private:
std::vector<int64_t> values_;
size_t current_sample_;
FXL_DISALLOW_COPY_AND_ASSIGN(CounterValues);
};
} // namespace flow
#endif // FLUTTER_FLOW_INSTRUMENTATION_H_