tp: split packet_sequence_state_generation from packet_sequence_state
Allows splitting parser_types without having terrible circular deps.
Change-Id: I5cd44625a57eb0393710a243898cc448c525f0df
diff --git a/Android.bp b/Android.bp
index 959f21e..7ca2afa 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1976,6 +1976,7 @@
":perfetto_src_trace_processor_importers_fuchsia_fuchsia_record",
":perfetto_src_trace_processor_importers_importers_full",
":perfetto_src_trace_processor_importers_memory_tracker_graph_processor",
+ ":perfetto_src_trace_processor_importers_proto_packet_sequence_state_generation_hdr",
":perfetto_src_trace_processor_importers_proto_storage_full",
":perfetto_src_trace_processor_importers_proto_storage_minimal",
":perfetto_src_trace_processor_importers_systrace_systrace_line",
@@ -9327,6 +9328,11 @@
],
}
+// GN: //src/trace_processor/importers/proto:packet_sequence_state_generation_hdr
+filegroup {
+ name: "perfetto_src_trace_processor_importers_proto_packet_sequence_state_generation_hdr",
+}
+
// GN: //src/trace_processor/importers/proto:storage_full
filegroup {
name: "perfetto_src_trace_processor_importers_proto_storage_full",
@@ -9341,6 +9347,7 @@
srcs: [
"src/trace_processor/importers/proto/active_chrome_processes_tracker.cc",
"src/trace_processor/importers/proto/heap_profile_tracker.cc",
+ "src/trace_processor/importers/proto/packet_sequence_state_generation.cc",
"src/trace_processor/importers/proto/profiler_util.cc",
"src/trace_processor/importers/proto/stack_profile_tracker.cc",
],
@@ -9715,7 +9722,6 @@
"src/trace_processor/importers/proto/memory_tracker_snapshot_parser.cc",
"src/trace_processor/importers/proto/metadata_module.cc",
"src/trace_processor/importers/proto/metadata_tracker.cc",
- "src/trace_processor/importers/proto/packet_sequence_state.cc",
"src/trace_processor/importers/proto/perf_sample_tracker.cc",
"src/trace_processor/importers/proto/profile_module.cc",
"src/trace_processor/importers/proto/profile_packet_utils.cc",
@@ -11216,6 +11222,7 @@
":perfetto_src_trace_processor_importers_fuchsia_fuchsia_record",
":perfetto_src_trace_processor_importers_importers_full",
":perfetto_src_trace_processor_importers_memory_tracker_graph_processor",
+ ":perfetto_src_trace_processor_importers_proto_packet_sequence_state_generation_hdr",
":perfetto_src_trace_processor_importers_proto_storage_full",
":perfetto_src_trace_processor_importers_proto_storage_minimal",
":perfetto_src_trace_processor_importers_proto_unittests",
@@ -11860,6 +11867,7 @@
":perfetto_src_trace_processor_importers_fuchsia_fuchsia_record",
":perfetto_src_trace_processor_importers_importers_full",
":perfetto_src_trace_processor_importers_memory_tracker_graph_processor",
+ ":perfetto_src_trace_processor_importers_proto_packet_sequence_state_generation_hdr",
":perfetto_src_trace_processor_importers_proto_storage_full",
":perfetto_src_trace_processor_importers_proto_storage_minimal",
":perfetto_src_trace_processor_importers_systrace_systrace_line",
@@ -12056,6 +12064,7 @@
":perfetto_src_trace_processor_importers_fuchsia_fuchsia_record",
":perfetto_src_trace_processor_importers_importers_full",
":perfetto_src_trace_processor_importers_memory_tracker_graph_processor",
+ ":perfetto_src_trace_processor_importers_proto_packet_sequence_state_generation_hdr",
":perfetto_src_trace_processor_importers_proto_storage_full",
":perfetto_src_trace_processor_importers_proto_storage_minimal",
":perfetto_src_trace_processor_importers_systrace_systrace_line",
diff --git a/BUILD b/BUILD
index 0ecb3bc..ad66422 100644
--- a/BUILD
+++ b/BUILD
@@ -1162,6 +1162,14 @@
],
)
+# GN target: //src/trace_processor/importers/proto:packet_sequence_state_generation_hdr
+perfetto_filegroup(
+ name = "src_trace_processor_importers_proto_packet_sequence_state_generation_hdr",
+ srcs = [
+ "src/trace_processor/importers/proto/packet_sequence_state_generation.h",
+ ],
+)
+
# GN target: //src/trace_processor/importers/proto:storage_full
perfetto_filegroup(
name = "src_trace_processor_importers_proto_storage_full",
@@ -1179,6 +1187,8 @@
"src/trace_processor/importers/proto/active_chrome_processes_tracker.h",
"src/trace_processor/importers/proto/heap_profile_tracker.cc",
"src/trace_processor/importers/proto/heap_profile_tracker.h",
+ "src/trace_processor/importers/proto/packet_sequence_state.h",
+ "src/trace_processor/importers/proto/packet_sequence_state_generation.cc",
"src/trace_processor/importers/proto/profiler_util.cc",
"src/trace_processor/importers/proto/profiler_util.h",
"src/trace_processor/importers/proto/stack_profile_tracker.cc",
@@ -1957,8 +1967,6 @@
"src/trace_processor/importers/proto/metadata_module.h",
"src/trace_processor/importers/proto/metadata_tracker.cc",
"src/trace_processor/importers/proto/metadata_tracker.h",
- "src/trace_processor/importers/proto/packet_sequence_state.cc",
- "src/trace_processor/importers/proto/packet_sequence_state.h",
"src/trace_processor/importers/proto/perf_sample_tracker.cc",
"src/trace_processor/importers/proto/perf_sample_tracker.h",
"src/trace_processor/importers/proto/profile_module.cc",
@@ -4385,6 +4393,7 @@
":src_trace_processor_importers_fuchsia_fuchsia_record",
":src_trace_processor_importers_importers_full",
":src_trace_processor_importers_memory_tracker_graph_processor",
+ ":src_trace_processor_importers_proto_packet_sequence_state_generation_hdr",
":src_trace_processor_importers_proto_storage_full",
":src_trace_processor_importers_proto_storage_minimal",
":src_trace_processor_importers_systrace_systrace_line",
@@ -4517,6 +4526,7 @@
":src_trace_processor_importers_fuchsia_fuchsia_record",
":src_trace_processor_importers_importers_full",
":src_trace_processor_importers_memory_tracker_graph_processor",
+ ":src_trace_processor_importers_proto_packet_sequence_state_generation_hdr",
":src_trace_processor_importers_proto_storage_full",
":src_trace_processor_importers_proto_storage_minimal",
":src_trace_processor_importers_systrace_systrace_line",
@@ -4708,6 +4718,7 @@
":src_trace_processor_importers_fuchsia_fuchsia_record",
":src_trace_processor_importers_importers_full",
":src_trace_processor_importers_memory_tracker_graph_processor",
+ ":src_trace_processor_importers_proto_packet_sequence_state_generation_hdr",
":src_trace_processor_importers_proto_storage_full",
":src_trace_processor_importers_proto_storage_minimal",
":src_trace_processor_importers_systrace_systrace_line",
diff --git a/src/trace_processor/BUILD.gn b/src/trace_processor/BUILD.gn
index db6cd1a..45d1255 100644
--- a/src/trace_processor/BUILD.gn
+++ b/src/trace_processor/BUILD.gn
@@ -124,8 +124,6 @@
"importers/proto/metadata_module.h",
"importers/proto/metadata_tracker.cc",
"importers/proto/metadata_tracker.h",
- "importers/proto/packet_sequence_state.cc",
- "importers/proto/packet_sequence_state.h",
"importers/proto/perf_sample_tracker.cc",
"importers/proto/perf_sample_tracker.h",
"importers/proto/profile_module.cc",
@@ -187,7 +185,6 @@
"util",
"util:descriptors",
"util:gzip",
- "util:interned_message_view",
"util:proto_to_args_parser",
"util:stack_traces_util",
"views",
diff --git a/src/trace_processor/importers/proto/BUILD.gn b/src/trace_processor/importers/proto/BUILD.gn
index 48c2f26..8876f0e 100644
--- a/src/trace_processor/importers/proto/BUILD.gn
+++ b/src/trace_processor/importers/proto/BUILD.gn
@@ -18,12 +18,15 @@
"active_chrome_processes_tracker.h",
"heap_profile_tracker.cc",
"heap_profile_tracker.h",
+ "packet_sequence_state.h",
+ "packet_sequence_state_generation.cc",
"profiler_util.cc",
"profiler_util.h",
"stack_profile_tracker.cc",
"stack_profile_tracker.h",
]
deps = [
+ ":packet_sequence_state_generation_hdr",
"../../../../gn:default_deps",
"../../../../protos/perfetto/trace/profiling:zero",
"../../../base",
@@ -52,6 +55,17 @@
]
}
+source_set("packet_sequence_state_generation_hdr") {
+ sources = [ "packet_sequence_state_generation.h" ]
+ deps = [
+ "../../../../gn:default_deps",
+ "../../../../include/perfetto/ext/base",
+ "../../../../protos/perfetto/trace:non_minimal_zero",
+ "../../../../protos/perfetto/trace/track_event:zero",
+ "../../util:interned_message_view",
+ ]
+}
+
source_set("unittests") {
testonly = true
sources = [
diff --git a/src/trace_processor/importers/proto/packet_sequence_state.h b/src/trace_processor/importers/proto/packet_sequence_state.h
index d985572..d95fccc 100644
--- a/src/trace_processor/importers/proto/packet_sequence_state.h
+++ b/src/trace_processor/importers/proto/packet_sequence_state.h
@@ -23,100 +23,15 @@
#include <vector>
#include "perfetto/base/compiler.h"
-#include "perfetto/protozero/proto_decoder.h"
-#include "perfetto/trace_processor/ref_counted.h"
-#include "perfetto/trace_processor/trace_blob_view.h"
+#include "src/trace_processor/importers/proto/packet_sequence_state_generation.h"
#include "src/trace_processor/importers/proto/stack_profile_tracker.h"
#include "src/trace_processor/storage/trace_storage.h"
#include "src/trace_processor/types/trace_processor_context.h"
#include "src/trace_processor/util/interned_message_view.h"
-#include "protos/perfetto/trace/trace_packet_defaults.pbzero.h"
-#include "protos/perfetto/trace/track_event/track_event.pbzero.h"
-
namespace perfetto {
namespace trace_processor {
-using InternedMessageMap =
- std::unordered_map<uint64_t /*iid*/, InternedMessageView>;
-using InternedFieldMap =
- std::unordered_map<uint32_t /*field_id*/, InternedMessageMap>;
-
-class PacketSequenceState;
-
-class PacketSequenceStateGeneration : public RefCounted {
- public:
- // Returns |nullptr| if the message with the given |iid| was not found (also
- // records a stat in this case).
- template <uint32_t FieldId, typename MessageType>
- typename MessageType::Decoder* LookupInternedMessage(uint64_t iid);
-
- InternedMessageView* GetInternedMessageView(uint32_t field_id, uint64_t iid);
- // Returns |nullptr| if no defaults were set.
- InternedMessageView* GetTracePacketDefaultsView() {
- if (!trace_packet_defaults_)
- return nullptr;
- return &trace_packet_defaults_.value();
- }
-
- // Returns |nullptr| if no defaults were set.
- protos::pbzero::TracePacketDefaults::Decoder* GetTracePacketDefaults() {
- InternedMessageView* view = GetTracePacketDefaultsView();
- if (!view)
- return nullptr;
- return view->GetOrCreateDecoder<protos::pbzero::TracePacketDefaults>();
- }
-
- // Returns |nullptr| if no TrackEventDefaults were set.
- protos::pbzero::TrackEventDefaults::Decoder* GetTrackEventDefaults() {
- auto* packet_defaults_view = GetTracePacketDefaultsView();
- if (packet_defaults_view) {
- auto* track_event_defaults_view =
- packet_defaults_view
- ->GetOrCreateSubmessageView<protos::pbzero::TracePacketDefaults,
- protos::pbzero::TracePacketDefaults::
- kTrackEventDefaultsFieldNumber>();
- if (track_event_defaults_view) {
- return track_event_defaults_view
- ->GetOrCreateDecoder<protos::pbzero::TrackEventDefaults>();
- }
- }
- return nullptr;
- }
-
- PacketSequenceState* state() const { return state_; }
- size_t generation_index() const { return generation_index_; }
-
- private:
- friend class PacketSequenceState;
-
- PacketSequenceStateGeneration(PacketSequenceState* state,
- size_t generation_index)
- : state_(state), generation_index_(generation_index) {}
-
- PacketSequenceStateGeneration(PacketSequenceState* state,
- size_t generation_index,
- InternedFieldMap interned_data,
- TraceBlobView defaults)
- : state_(state),
- generation_index_(generation_index),
- interned_data_(interned_data),
- trace_packet_defaults_(InternedMessageView(std::move(defaults))) {}
-
- void InternMessage(uint32_t field_id, TraceBlobView message);
-
- void SetTracePacketDefaults(TraceBlobView defaults) {
- // Defaults should only be set once per generation.
- PERFETTO_DCHECK(!trace_packet_defaults_);
- trace_packet_defaults_ = InternedMessageView(std::move(defaults));
- }
-
- PacketSequenceState* state_;
- size_t generation_index_;
- InternedFieldMap interned_data_;
- base::Optional<InternedMessageView> trace_packet_defaults_;
-};
-
class PacketSequenceState {
public:
explicit PacketSequenceState(TraceProcessorContext* context)
diff --git a/src/trace_processor/importers/proto/packet_sequence_state.cc b/src/trace_processor/importers/proto/packet_sequence_state_generation.cc
similarity index 96%
rename from src/trace_processor/importers/proto/packet_sequence_state.cc
rename to src/trace_processor/importers/proto/packet_sequence_state_generation.cc
index 2eb2350..6e8e98d 100644
--- a/src/trace_processor/importers/proto/packet_sequence_state.cc
+++ b/src/trace_processor/importers/proto/packet_sequence_state_generation.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "src/trace_processor/importers/proto/packet_sequence_state_generation.h"
+
#include "src/trace_processor/importers/proto/packet_sequence_state.h"
namespace perfetto {
diff --git a/src/trace_processor/importers/proto/packet_sequence_state_generation.h b/src/trace_processor/importers/proto/packet_sequence_state_generation.h
new file mode 100644
index 0000000..c3dda05
--- /dev/null
+++ b/src/trace_processor/importers/proto/packet_sequence_state_generation.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PACKET_SEQUENCE_STATE_GENERATION_H_
+#define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PACKET_SEQUENCE_STATE_GENERATION_H_
+
+#include <unordered_map>
+
+#include "perfetto/ext/base/optional.h"
+#include "perfetto/trace_processor/ref_counted.h"
+#include "src/trace_processor/util/interned_message_view.h"
+
+#include "protos/perfetto/trace/trace_packet_defaults.pbzero.h"
+#include "protos/perfetto/trace/track_event/track_event.pbzero.h"
+
+namespace perfetto {
+namespace trace_processor {
+
+using InternedMessageMap =
+ std::unordered_map<uint64_t /*iid*/, InternedMessageView>;
+using InternedFieldMap =
+ std::unordered_map<uint32_t /*field_id*/, InternedMessageMap>;
+
+class PacketSequenceState;
+
+class PacketSequenceStateGeneration : public RefCounted {
+ public:
+ // Returns |nullptr| if the message with the given |iid| was not found (also
+ // records a stat in this case).
+ template <uint32_t FieldId, typename MessageType>
+ typename MessageType::Decoder* LookupInternedMessage(uint64_t iid);
+
+ InternedMessageView* GetInternedMessageView(uint32_t field_id, uint64_t iid);
+ // Returns |nullptr| if no defaults were set.
+ InternedMessageView* GetTracePacketDefaultsView() {
+ if (!trace_packet_defaults_)
+ return nullptr;
+ return &trace_packet_defaults_.value();
+ }
+
+ // Returns |nullptr| if no defaults were set.
+ protos::pbzero::TracePacketDefaults::Decoder* GetTracePacketDefaults() {
+ InternedMessageView* view = GetTracePacketDefaultsView();
+ if (!view)
+ return nullptr;
+ return view->GetOrCreateDecoder<protos::pbzero::TracePacketDefaults>();
+ }
+
+ // Returns |nullptr| if no TrackEventDefaults were set.
+ protos::pbzero::TrackEventDefaults::Decoder* GetTrackEventDefaults() {
+ auto* packet_defaults_view = GetTracePacketDefaultsView();
+ if (packet_defaults_view) {
+ auto* track_event_defaults_view =
+ packet_defaults_view
+ ->GetOrCreateSubmessageView<protos::pbzero::TracePacketDefaults,
+ protos::pbzero::TracePacketDefaults::
+ kTrackEventDefaultsFieldNumber>();
+ if (track_event_defaults_view) {
+ return track_event_defaults_view
+ ->GetOrCreateDecoder<protos::pbzero::TrackEventDefaults>();
+ }
+ }
+ return nullptr;
+ }
+
+ PacketSequenceState* state() const { return state_; }
+ size_t generation_index() const { return generation_index_; }
+
+ private:
+ friend class PacketSequenceState;
+
+ PacketSequenceStateGeneration(PacketSequenceState* state,
+ size_t generation_index)
+ : state_(state), generation_index_(generation_index) {}
+
+ PacketSequenceStateGeneration(PacketSequenceState* state,
+ size_t generation_index,
+ InternedFieldMap interned_data,
+ TraceBlobView defaults)
+ : state_(state),
+ generation_index_(generation_index),
+ interned_data_(interned_data),
+ trace_packet_defaults_(InternedMessageView(std::move(defaults))) {}
+
+ void InternMessage(uint32_t field_id, TraceBlobView message);
+
+ void SetTracePacketDefaults(TraceBlobView defaults) {
+ // Defaults should only be set once per generation.
+ PERFETTO_DCHECK(!trace_packet_defaults_);
+ trace_packet_defaults_ = InternedMessageView(std::move(defaults));
+ }
+
+ PacketSequenceState* state_;
+ size_t generation_index_;
+ InternedFieldMap interned_data_;
+ base::Optional<InternedMessageView> trace_packet_defaults_;
+};
+
+} // namespace trace_processor
+} // namespace perfetto
+
+#endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PACKET_SEQUENCE_STATE_GENERATION_H_