trace_processor: migrate GPU tables to new macros
This CL migrates the newly added GPU tables to the new Table macros. As
these tables are simple, have not been exposed to SQLite and thus have
no dependencies, they were chosen to be the easiest to try migration.
Context: go/perfetto-tp-refactor
Bug: 135177627
Change-Id: I9f520b8cf8637b9be9a44444e867d1c4b19af75f
diff --git a/src/trace_processor/trace_storage.h b/src/trace_processor/trace_storage.h
index d0375eb..4c7515d 100644
--- a/src/trace_processor/trace_storage.h
+++ b/src/trace_processor/trace_storage.h
@@ -35,6 +35,8 @@
#include "src/trace_processor/metadata.h"
#include "src/trace_processor/stats.h"
#include "src/trace_processor/string_pool.h"
+#include "src/trace_processor/tables/slice_tables.h"
+#include "src/trace_processor/tables/track_tables.h"
#include "src/trace_processor/variadic.h"
namespace perfetto {
@@ -265,44 +267,6 @@
std::deque<UniquePid> upids_;
};
- class GpuTracks {
- public:
- inline void AddGpuTrack(TrackId track_id,
- StringId scope,
- // For all below: null == numeric_limits<int_type>::max()
- uint64_t context_id) {
- track_ids_.emplace_back(track_id);
- scopes_.emplace_back(scope);
- context_ids_.emplace_back(context_id);
- }
-
- uint32_t gpu_track_count() const {
- return static_cast<uint32_t>(track_ids_.size());
- }
-
- base::Optional<uint32_t> FindRowForTrackId(uint32_t track_id) const {
- auto it =
- std::lower_bound(track_ids().begin(), track_ids().end(), track_id);
- if (it != track_ids().end() && *it == track_id) {
- return static_cast<uint32_t>(std::distance(track_ids().begin(), it));
- }
- return base::nullopt;
- }
-
- const std::deque<TrackId>& track_ids() const { return track_ids_; }
- const std::deque<StringId>& scopes() const { return scopes_; }
- const std::deque<uint64_t>& context_ids() const {
- return context_ids_;
- }
-
- private:
- std::deque<TrackId> track_ids_;
- std::deque<StringId> scopes_;
-
- // For all below: null == numeric_limits<int_type>::max()
- std::deque<uint64_t> context_ids_;
- };
-
class GpuContexts {
public:
inline void AddGpuContext(uint64_t context_id,
@@ -578,65 +542,6 @@
std::deque<int64_t> thread_instruction_deltas_;
};
- class GpuSlices {
- public:
- inline uint32_t AddGpuSlice(uint32_t slice_id,
- // For all below: null == numeric_limits<int_type>::max()
- uint64_t context_id,
- uint64_t render_target,
- uint32_t frame_id,
- uint32_t job_id,
- uint32_t hw_queue_id) {
- slice_ids_.emplace_back(slice_id);
- context_ids_.emplace_back(context_id);
- render_targets_.emplace_back(render_target);
- frame_ids_.emplace_back(frame_id);
- job_ids_.emplace_back(job_id);
- hw_queue_ids_.emplace_back(hw_queue_id);
- return slice_count() - 1;
- }
-
- uint32_t slice_count() const {
- return static_cast<uint32_t>(slice_ids_.size());
- }
-
- const std::deque<uint32_t>& slice_ids() const { return slice_ids_; }
- const std::deque<uint64_t>& context_ids() const {
- return context_ids_;
- }
- const std::deque<uint64_t>& render_targets() const {
- return render_targets_;
- }
- const std::deque<uint32_t>& frame_ids() const {
- return frame_ids_;
- }
- const std::deque<uint32_t>& job_ids() const {
- return job_ids_;
- }
- const std::deque<uint32_t>& hw_queue_ids() const {
- return hw_queue_ids_;
- }
-
- base::Optional<uint32_t> FindRowForSliceId(uint32_t slice_id) const {
- auto it =
- std::lower_bound(slice_ids().begin(), slice_ids().end(), slice_id);
- if (it != slice_ids().end() && *it == slice_id) {
- return static_cast<uint32_t>(std::distance(slice_ids().begin(), it));
- }
- return base::nullopt;
- }
-
- private:
- std::deque<uint32_t> slice_ids_;
-
- // For all below: null == numeric_limits<int_type>::max()
- std::deque<uint64_t> context_ids_;
- std::deque<uint64_t> render_targets_;
- std::deque<uint32_t> frame_ids_;
- std::deque<uint32_t> job_ids_;
- std::deque<uint32_t> hw_queue_ids_;
- };
-
class CounterDefinitions {
public:
using Id = uint32_t;
@@ -1127,8 +1032,6 @@
std::deque<UniqueTid> utids_;
};
- void ResetStorage();
-
UniqueTid AddEmptyThread(uint32_t tid) {
unique_threads_.emplace_back(tid);
return static_cast<UniqueTid>(unique_threads_.size() - 1);
@@ -1291,8 +1194,10 @@
return &virtual_track_slices_;
}
- const GpuSlices& gpu_track_slices() const { return gpu_track_slices_; }
- GpuSlices* mutable_gpu_track_slices() { return &gpu_track_slices_; }
+ const tables::GpuSliceTable& gpu_slice_table() const {
+ return gpu_slice_table_;
+ }
+ tables::GpuSliceTable* mutable_gpu_slice_table() { return &gpu_slice_table_; }
const CounterDefinitions& counter_definitions() const {
return counter_definitions_;
@@ -1358,8 +1263,10 @@
return &cpu_profile_stack_samples_;
}
- const GpuTracks& gpu_tracks() const { return gpu_tracks_; }
- GpuTracks* mutable_gpu_tracks() { return &gpu_tracks_; }
+ const tables::GpuTrackTable& gpu_track_table() const {
+ return gpu_track_table_;
+ }
+ tables::GpuTrackTable* mutable_gpu_track_table() { return &gpu_track_table_; }
const StringPool& string_pool() const { return string_pool_; }
@@ -1386,8 +1293,11 @@
TraceStorage(const TraceStorage&) = delete;
TraceStorage& operator=(const TraceStorage&) = delete;
- TraceStorage(TraceStorage&&) = default;
- TraceStorage& operator=(TraceStorage&&) = default;
+ TraceStorage(TraceStorage&&) = delete;
+ TraceStorage& operator=(TraceStorage&&) = delete;
+
+ // One entry for each unique string in the trace.
+ StringPool string_pool_;
// Stats about parsing the trace.
StatsMap stats_{};
@@ -1404,7 +1314,7 @@
VirtualTracks virtual_tracks_;
// Metadata for gpu tracks.
- GpuTracks gpu_tracks_;
+ tables::GpuTrackTable gpu_track_table_{&string_pool_, nullptr};
GpuContexts gpu_contexts_;
// One entry for each CPU in the trace.
@@ -1413,9 +1323,6 @@
// Args for all other tables.
Args args_;
- // One entry for each unique string in the trace.
- StringPool string_pool_;
-
// One entry for each UniquePid, with UniquePid as the index.
// Never hold on to pointers to Process, as vector resize will
// invalidate them.
@@ -1436,7 +1343,7 @@
// Additional attributes for gpu track slices (sub-type of
// NestableSlices).
- GpuSlices gpu_track_slices_;
+ tables::GpuSliceTable gpu_slice_table_{&string_pool_, nullptr};
// The type of counters in the trace. Can be thought of as the "metadata".
CounterDefinitions counter_definitions_;