Skip to content

Commit

Permalink
Merge "Add bluetooth protos for custom datasource to perfetto" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng Li authored and Gerrit Code Review committed Jan 8, 2025
2 parents 465845e + 4a05632 commit 804e1cd
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -5729,6 +5729,7 @@ filegroup {
"protos/perfetto/trace/android/android_game_intervention_list.proto",
"protos/perfetto/trace/android/android_log.proto",
"protos/perfetto/trace/android/android_system_property.proto",
"protos/perfetto/trace/android/bluetooth_trace.proto",
"protos/perfetto/trace/android/camera_event.proto",
"protos/perfetto/trace/android/frame_timeline_event.proto",
"protos/perfetto/trace/android/gpu_mem_event.proto",
Expand Down Expand Up @@ -5758,6 +5759,7 @@ genrule {
"external/perfetto/protos/perfetto/trace/android/android_game_intervention_list.gen.cc",
"external/perfetto/protos/perfetto/trace/android/android_log.gen.cc",
"external/perfetto/protos/perfetto/trace/android/android_system_property.gen.cc",
"external/perfetto/protos/perfetto/trace/android/bluetooth_trace.gen.cc",
"external/perfetto/protos/perfetto/trace/android/camera_event.gen.cc",
"external/perfetto/protos/perfetto/trace/android/frame_timeline_event.gen.cc",
"external/perfetto/protos/perfetto/trace/android/gpu_mem_event.gen.cc",
Expand Down Expand Up @@ -5787,6 +5789,7 @@ genrule {
"external/perfetto/protos/perfetto/trace/android/android_game_intervention_list.gen.h",
"external/perfetto/protos/perfetto/trace/android/android_log.gen.h",
"external/perfetto/protos/perfetto/trace/android/android_system_property.gen.h",
"external/perfetto/protos/perfetto/trace/android/bluetooth_trace.gen.h",
"external/perfetto/protos/perfetto/trace/android/camera_event.gen.h",
"external/perfetto/protos/perfetto/trace/android/frame_timeline_event.gen.h",
"external/perfetto/protos/perfetto/trace/android/gpu_mem_event.gen.h",
Expand All @@ -5809,6 +5812,7 @@ filegroup {
"protos/perfetto/trace/android/android_game_intervention_list.proto",
"protos/perfetto/trace/android/android_log.proto",
"protos/perfetto/trace/android/android_system_property.proto",
"protos/perfetto/trace/android/bluetooth_trace.proto",
"protos/perfetto/trace/android/camera_event.proto",
"protos/perfetto/trace/android/frame_timeline_event.proto",
"protos/perfetto/trace/android/gpu_mem_event.proto",
Expand Down Expand Up @@ -5837,6 +5841,7 @@ genrule {
"external/perfetto/protos/perfetto/trace/android/android_game_intervention_list.pb.cc",
"external/perfetto/protos/perfetto/trace/android/android_log.pb.cc",
"external/perfetto/protos/perfetto/trace/android/android_system_property.pb.cc",
"external/perfetto/protos/perfetto/trace/android/bluetooth_trace.pb.cc",
"external/perfetto/protos/perfetto/trace/android/camera_event.pb.cc",
"external/perfetto/protos/perfetto/trace/android/frame_timeline_event.pb.cc",
"external/perfetto/protos/perfetto/trace/android/gpu_mem_event.pb.cc",
Expand Down Expand Up @@ -5865,6 +5870,7 @@ genrule {
"external/perfetto/protos/perfetto/trace/android/android_game_intervention_list.pb.h",
"external/perfetto/protos/perfetto/trace/android/android_log.pb.h",
"external/perfetto/protos/perfetto/trace/android/android_system_property.pb.h",
"external/perfetto/protos/perfetto/trace/android/bluetooth_trace.pb.h",
"external/perfetto/protos/perfetto/trace/android/camera_event.pb.h",
"external/perfetto/protos/perfetto/trace/android/frame_timeline_event.pb.h",
"external/perfetto/protos/perfetto/trace/android/gpu_mem_event.pb.h",
Expand Down Expand Up @@ -6459,6 +6465,7 @@ filegroup {
"protos/perfetto/trace/android/android_game_intervention_list.proto",
"protos/perfetto/trace/android/android_log.proto",
"protos/perfetto/trace/android/android_system_property.proto",
"protos/perfetto/trace/android/bluetooth_trace.proto",
"protos/perfetto/trace/android/camera_event.proto",
"protos/perfetto/trace/android/frame_timeline_event.proto",
"protos/perfetto/trace/android/gpu_mem_event.proto",
Expand Down Expand Up @@ -6488,6 +6495,7 @@ genrule {
"external/perfetto/protos/perfetto/trace/android/android_game_intervention_list.pbzero.cc",
"external/perfetto/protos/perfetto/trace/android/android_log.pbzero.cc",
"external/perfetto/protos/perfetto/trace/android/android_system_property.pbzero.cc",
"external/perfetto/protos/perfetto/trace/android/bluetooth_trace.pbzero.cc",
"external/perfetto/protos/perfetto/trace/android/camera_event.pbzero.cc",
"external/perfetto/protos/perfetto/trace/android/frame_timeline_event.pbzero.cc",
"external/perfetto/protos/perfetto/trace/android/gpu_mem_event.pbzero.cc",
Expand Down Expand Up @@ -6517,6 +6525,7 @@ genrule {
"external/perfetto/protos/perfetto/trace/android/android_game_intervention_list.pbzero.h",
"external/perfetto/protos/perfetto/trace/android/android_log.pbzero.h",
"external/perfetto/protos/perfetto/trace/android/android_system_property.pbzero.h",
"external/perfetto/protos/perfetto/trace/android/bluetooth_trace.pbzero.h",
"external/perfetto/protos/perfetto/trace/android/camera_event.pbzero.h",
"external/perfetto/protos/perfetto/trace/android/frame_timeline_event.pbzero.h",
"external/perfetto/protos/perfetto/trace/android/gpu_mem_event.pbzero.h",
Expand Down Expand Up @@ -6760,6 +6769,7 @@ genrule {
"protos/perfetto/trace/android/android_game_intervention_list.proto",
"protos/perfetto/trace/android/android_log.proto",
"protos/perfetto/trace/android/android_system_property.proto",
"protos/perfetto/trace/android/bluetooth_trace.proto",
"protos/perfetto/trace/android/camera_event.proto",
"protos/perfetto/trace/android/frame_timeline_event.proto",
"protos/perfetto/trace/android/gpu_mem_event.proto",
Expand Down Expand Up @@ -15155,6 +15165,7 @@ java_library {
"protos/perfetto/trace/android/android_game_intervention_list.proto",
"protos/perfetto/trace/android/android_log.proto",
"protos/perfetto/trace/android/android_system_property.proto",
"protos/perfetto/trace/android/bluetooth_trace.proto",
"protos/perfetto/trace/android/camera_event.proto",
"protos/perfetto/trace/android/frame_timeline_event.proto",
"protos/perfetto/trace/android/gpu_mem_event.proto",
Expand Down Expand Up @@ -16460,6 +16471,7 @@ filegroup {
"protos/perfetto/trace/android/android_system_property.proto",
"protos/perfetto/trace/android/app/statusbarmanager.proto",
"protos/perfetto/trace/android/app/window_configuration.proto",
"protos/perfetto/trace/android/bluetooth_trace.proto",
"protos/perfetto/trace/android/camera_event.proto",
"protos/perfetto/trace/android/content/activityinfo.proto",
"protos/perfetto/trace/android/content/configuration.proto",
Expand Down
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5491,6 +5491,7 @@ perfetto_proto_library(
"protos/perfetto/trace/android/android_game_intervention_list.proto",
"protos/perfetto/trace/android/android_log.proto",
"protos/perfetto/trace/android/android_system_property.proto",
"protos/perfetto/trace/android/bluetooth_trace.proto",
"protos/perfetto/trace/android/camera_event.proto",
"protos/perfetto/trace/android/frame_timeline_event.proto",
"protos/perfetto/trace/android/gpu_mem_event.proto",
Expand Down
1 change: 1 addition & 0 deletions protos/perfetto/trace/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ perfetto_proto_library("@TYPE@") {
"android_game_intervention_list.proto",
"android_log.proto",
"android_system_property.proto",
"bluetooth_trace.proto",
"camera_event.proto",
"frame_timeline_event.proto",
"gpu_mem_event.proto",
Expand Down
63 changes: 63 additions & 0 deletions protos/perfetto/trace/android/bluetooth_trace.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2025 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.
*/

syntax = "proto2";

package perfetto.protos;

// Describes the packet type and direction. CMD and EVT are unidirectional, so
// no need to differentiate the direction.
enum BluetoothTracePacketType {
HCI_CMD = 1;
HCI_EVT = 2;
HCI_ACL_RX = 3;
HCI_ACL_TX = 4;
HCI_SCO_RX = 5;
HCI_SCO_TX = 6;
HCI_ISO_RX = 7;
HCI_ISO_TX = 8;
}

// Trace event for bluetooth
message BluetoothTraceEvent {

// Packet type and direction
optional BluetoothTracePacketType packet_type = 1;

// Total count of the packets collected during the collection interval
optional uint32 count = 2;

// Total cumulative length of the packets collected during the collection
// interval
optional uint32 length = 3;

// The collection interval in ms. This is the duration between the first and
// last packets collected.
optional uint32 duration = 4;

// In case of CMD type, further breakdown of the type of command
optional uint32 op_code = 5;

// In the case of EVT type, further breakdown of the type of event
optional uint32 event_code = 6;

// When applicable for EVT type, further breakdown of event type into specific
// subevent
optional uint32 subevent_code = 7;

// Associated handle for the bluetooth packet
optional uint32 connection_handle = 8;
}
51 changes: 50 additions & 1 deletion protos/perfetto/trace/perfetto_trace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4810,6 +4810,53 @@ message AndroidSystemProperty {

// End of protos/perfetto/trace/android/android_system_property.proto

// Begin of protos/perfetto/trace/android/bluetooth_trace.proto

// Describes the packet type and direction. CMD and EVT are unidirectional, so
// no need to differentiate the direction.
enum BluetoothTracePacketType {
HCI_CMD = 1;
HCI_EVT = 2;
HCI_ACL_RX = 3;
HCI_ACL_TX = 4;
HCI_SCO_RX = 5;
HCI_SCO_TX = 6;
HCI_ISO_RX = 7;
HCI_ISO_TX = 8;
}

// Trace event for bluetooth
message BluetoothTraceEvent {

// Packet type and direction
optional BluetoothTracePacketType packet_type = 1;

// Total count of the packets collected during the collection interval
optional uint32 count = 2;

// Total cumulative length of the packets collected during the collection
// interval
optional uint32 length = 3;

// The collection interval in ms. This is the duration between the first and
// last packets collected.
optional uint32 duration = 4;

// In case of CMD type, further breakdown of the type of command
optional uint32 op_code = 5;

// In the case of EVT type, further breakdown of the type of event
optional uint32 event_code = 6;

// When applicable for EVT type, further breakdown of event type into specific
// subevent
optional uint32 subevent_code = 7;

// Associated handle for the bluetooth packet
optional uint32 connection_handle = 8;
}
// End of protos/perfetto/trace/android/bluetooth_trace.proto

// Begin of protos/perfetto/trace/android/camera_event.proto

// A profiling event corresponding to a single camera frame. This message
Expand Down Expand Up @@ -15691,7 +15738,7 @@ message UiState {
// See the [Buffers and Dataflow](/docs/concepts/buffers.md) doc for details.
//
// Next reserved id: 14 (up to 15).
// Next id: 114.
// Next id: 115.
message TracePacket {
// The timestamp of the TracePacket.
// By default this timestamps refers to the trace clock (CLOCK_BOOTTIME on
Expand Down Expand Up @@ -15833,6 +15880,8 @@ message TracePacket {

Trigger clone_snapshot_trigger = 113;

BluetoothTraceEvent bluetooth_trace_event = 114;

// This field is only used for testing.
// In previous versions of this proto this field had the id 268435455
// This caused many problems:
Expand Down
5 changes: 4 additions & 1 deletion protos/perfetto/trace/trace_packet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import "protos/perfetto/trace/extension_descriptor.proto";
import "protos/perfetto/trace/android/android_game_intervention_list.proto";
import "protos/perfetto/trace/android/android_log.proto";
import "protos/perfetto/trace/android/android_system_property.proto";
import "protos/perfetto/trace/android/bluetooth_trace.proto";
import "protos/perfetto/trace/android/camera_event.proto";
import "protos/perfetto/trace/android/frame_timeline_event.proto";
import "protos/perfetto/trace/android/gpu_mem_event.proto";
Expand Down Expand Up @@ -104,7 +105,7 @@ package perfetto.protos;
// See the [Buffers and Dataflow](/docs/concepts/buffers.md) doc for details.
//
// Next reserved id: 14 (up to 15).
// Next id: 114.
// Next id: 115.
message TracePacket {
// The timestamp of the TracePacket.
// By default this timestamps refers to the trace clock (CLOCK_BOOTTIME on
Expand Down Expand Up @@ -246,6 +247,8 @@ message TracePacket {

Trigger clone_snapshot_trigger = 113;

BluetoothTraceEvent bluetooth_trace_event = 114;

// This field is only used for testing.
// In previous versions of this proto this field had the id 268435455
// This caused many problems:
Expand Down
5 changes: 5 additions & 0 deletions src/trace_processor/importers/proto/android_probes_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "protos/perfetto/trace/power/android_entity_state_residency.pbzero.h"
#include "protos/perfetto/trace/power/power_rails.pbzero.h"
#include "protos/perfetto/trace/trace_packet.pbzero.h"
#include "protos/perfetto/trace/android/bluetooth_trace.pbzero.h"

namespace perfetto::trace_processor {
namespace {
Expand Down Expand Up @@ -115,6 +116,7 @@ AndroidProbesModule::AndroidProbesModule(TraceProcessorContext* context)
context);
RegisterForField(TracePacket::kInitialDisplayStateFieldNumber, context);
RegisterForField(TracePacket::kAndroidSystemPropertyFieldNumber, context);
RegisterForField(TracePacket::kBluetoothTraceEventFieldNumber, context);
}

ModuleResult AndroidProbesModule::TokenizePacket(
Expand Down Expand Up @@ -260,6 +262,9 @@ void AndroidProbesModule::ParseTracePacketData(
case TracePacket::kAndroidSystemPropertyFieldNumber:
parser_.ParseAndroidSystemProperty(ts, decoder.android_system_property());
return;
case TracePacket::kBluetoothTraceEventFieldNumber:
parser_.ParseBtTraceEvent(ts, decoder.bluetooth_trace_event());
return;
}
}

Expand Down
73 changes: 72 additions & 1 deletion src/trace_processor/importers/proto/android_probes_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "protos/perfetto/trace/power/android_entity_state_residency.pbzero.h"
#include "protos/perfetto/trace/power/battery_counters.pbzero.h"
#include "protos/perfetto/trace/power/power_rails.pbzero.h"
#include "protos/perfetto/trace/android/bluetooth_trace.pbzero.h"

namespace perfetto::trace_processor {

Expand All @@ -67,7 +68,16 @@ AndroidProbesParser::AndroidProbesParser(TraceProcessorContext* context)
energy_consumer_id_(
context_->storage->InternString("energy_consumer_id")),
consumer_type_id_(context_->storage->InternString("consumer_type")),
ordinal_id_(context_->storage->InternString("ordinal")) {}
ordinal_id_(context_->storage->InternString("ordinal")),
bt_trace_event_id_(context_->storage->InternString("BluetoothTraceEvent")),
bt_packet_type_id_(context_->storage->InternString("TracePacketType")),
bt_count_id_(context_->storage->InternString("Count")),
bt_length_id_(context_->storage->InternString("Length")),
bt_duration_id_(context_->storage->InternString("Duration")),
bt_op_code_id_(context_->storage->InternString("Op Code")),
bt_event_code_id_(context_->storage->InternString("Event Code")),
bt_subevent_code_id_(context_->storage->InternString("Subevent Code")),
bt_handle_id_(context_->storage->InternString("Handle")) {}

void AndroidProbesParser::ParseBatteryCounters(int64_t ts, ConstBytes blob) {
protos::pbzero::BatteryCounters::Decoder evt(blob);
Expand Down Expand Up @@ -491,4 +501,65 @@ void AndroidProbesParser::ParseAndroidSystemProperty(int64_t ts,
}
}

void AndroidProbesParser::ParseBtTraceEvent(int64_t ts,
ConstBytes blob) {
protos::pbzero::BluetoothTraceEvent::Decoder evt(blob);

static constexpr auto kBluetoothTraceEventBlueprint =
tracks::SliceBlueprint("bluetooth_trace_event",
tracks::DimensionBlueprints(),
tracks::StaticNameBlueprint("BluetoothTraceEvent"));

TrackId track_id = context_->track_tracker->InternTrack(
kBluetoothTraceEventBlueprint);

context_->slice_tracker->Scoped(ts, track_id, kNullStringId,
bt_trace_event_id_, 0, [&evt, this](ArgsTracker::BoundInserter* inserter) {
if (evt.has_packet_type()) {
StringId packet_type_str = context_->storage->InternString(
protos::pbzero::BluetoothTracePacketType_Name(
static_cast<::perfetto::protos::pbzero::BluetoothTracePacketType>(
evt.packet_type())));
inserter->AddArg(
bt_packet_type_id_,
Variadic::String(packet_type_str));
}
if (evt.has_count()) {
inserter->AddArg(
bt_count_id_,
Variadic::UnsignedInteger(evt.count()));
}
if (evt.has_length()) {
inserter->AddArg(
bt_length_id_,
Variadic::UnsignedInteger(evt.length()));
}
if (evt.has_duration()) {
inserter->AddArg(
bt_duration_id_,
Variadic::UnsignedInteger(evt.duration()));
}
if (evt.has_op_code()) {
inserter->AddArg(
bt_op_code_id_,
Variadic::UnsignedInteger(evt.op_code()));
}
if (evt.has_event_code()) {
inserter->AddArg(
bt_event_code_id_,
Variadic::UnsignedInteger(evt.event_code()));
}
if (evt.has_subevent_code()) {
inserter->AddArg(
bt_subevent_code_id_,
Variadic::UnsignedInteger(evt.subevent_code()));
}
if (evt.has_connection_handle()) {
inserter->AddArg(
bt_handle_id_,
Variadic::UnsignedInteger(evt.connection_handle()));
}
});
}

} // namespace perfetto::trace_processor
Loading

0 comments on commit 804e1cd

Please sign in to comment.