This repository was archived by the owner on Jan 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathTimerData.h
More file actions
110 lines (90 loc) · 4.8 KB
/
Copy pathTimerData.h
File metadata and controls
110 lines (90 loc) · 4.8 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) 2021 The Orbit 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 CLIENT_DATA_TIMER_DATA_H_
#define CLIENT_DATA_TIMER_DATA_H_
#include <absl/base/thread_annotations.h>
#include <absl/synchronization/mutex.h>
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <atomic>
#include <limits>
#include <map>
#include <memory>
#include <vector>
#include "ClientProtos/capture_data.pb.h"
#include "OrbitBase/ThreadConstants.h"
#include "TimerChain.h"
#include "TimerDataInterface.h"
namespace orbit_client_data {
// Stores all the timers from a particular TimerTrack and provides queries to get timers in a
// certain range as well as metadata from them. Timers might be divided in different depths.
class TimerData final : public TimerDataInterface {
public:
const orbit_client_protos::TimerInfo& AddTimer(orbit_client_protos::TimerInfo timer_info,
uint32_t depth = 0) override;
// Timers queries
[[nodiscard]] std::vector<const TimerChain*> GetChains() const override;
[[nodiscard]] const TimerChain* GetChain(uint64_t depth) const;
// The method is not optimized. The complexity is linear in the total number of timer_infos,
// sortedness is not made use of.
[[nodiscard]] std::vector<const orbit_client_protos::TimerInfo*> GetTimers(
uint64_t min_tick = std::numeric_limits<uint64_t>::min(),
uint64_t max_tick = std::numeric_limits<uint64_t>::max(),
bool exclusive = false) const override;
// Returns timers in a particular depth avoiding completely overlapped timers that map to the
// same pixels in the screen. It assures to return at least one timer in each occupied pixel. The
// overall complexity is faster than GetTimers since it doesn't require going through all timers.
// TODO(b/200692451): Provide a better solution for TimerTrack with intersecting timers.
[[nodiscard]] std::vector<const orbit_client_protos::TimerInfo*> GetTimersAtDepthDiscretized(
uint32_t depth, uint32_t resolution, uint64_t start_ns, uint64_t end_ns) const override;
// Metadata queries
[[nodiscard]] bool IsEmpty() const override { return GetNumberOfTimers() == 0; }
[[nodiscard]] size_t GetNumberOfTimers() const override { return num_timers_; }
[[nodiscard]] uint64_t GetMinTime() const override { return min_time_; }
[[nodiscard]] uint64_t GetMaxTime() const override { return max_time_; }
// TODO(b/204173036): Test depth and process_id.
[[nodiscard]] uint32_t GetDepth() const override { return depth_; }
[[nodiscard]] uint32_t GetProcessId() const override { return process_id_; }
// Relative timers queries.
// TODO(b/221024788): These queries assume Timers are inserted in order and don't work for
// GpuSubmissionTrack.
[[nodiscard]] const orbit_client_protos::TimerInfo* GetFirstAfterStartTime(uint64_t time,
uint32_t depth) const;
[[nodiscard]] const orbit_client_protos::TimerInfo* GetFirstBeforeStartTime(uint64_t time,
uint32_t depth) const;
const orbit_client_protos::TimerInfo* GetLeft(
const orbit_client_protos::TimerInfo& timer_info) const override {
return GetFirstBeforeStartTime(timer_info.start(), timer_info.depth());
}
const orbit_client_protos::TimerInfo* GetRight(
const orbit_client_protos::TimerInfo& timer_info) const override {
return GetFirstAfterStartTime(timer_info.start(), timer_info.depth());
}
const orbit_client_protos::TimerInfo* GetUp(
const orbit_client_protos::TimerInfo& timer_info) const override {
return GetFirstBeforeStartTime(timer_info.start(), timer_info.depth() - 1);
}
const orbit_client_protos::TimerInfo* GetDown(
const orbit_client_protos::TimerInfo& timer_info) const override {
return GetFirstAfterStartTime(timer_info.start(), timer_info.depth() + 1);
}
// Unused methods needed in TimerDataInterface
[[nodiscard]] int64_t GetThreadId() const override { return -1; }
void OnCaptureComplete() override {}
private:
void UpdateMinTime(uint64_t min_time);
void UpdateMaxTime(uint64_t max_time);
void UpdateDepth(uint32_t depth) { depth_ = std::max(depth_, depth); }
[[nodiscard]] TimerChain* GetOrCreateTimerChain(uint64_t depth);
uint32_t depth_ = 0;
mutable absl::Mutex mutex_;
std::map<uint32_t, std::unique_ptr<TimerChain>> timers_ ABSL_GUARDED_BY(mutex_);
std::atomic<size_t> num_timers_{0};
std::atomic<uint64_t> min_time_{std::numeric_limits<uint64_t>::max()};
std::atomic<uint64_t> max_time_{std::numeric_limits<uint64_t>::min()};
uint32_t process_id_ = orbit_base::kInvalidProcessId;
};
} // namespace orbit_client_data
#endif // CLIENT_DATA_TIMER_DATA_H_