From 9af0078f41f489059982614e8558536e100f9a1a Mon Sep 17 00:00:00 2001 From: Jack He Date: Wed, 31 Jan 2018 16:51:26 -0800 Subject: [PATCH] Metrics: Dump native metrics to Java as std:string * Dump metrics to Java layer as std::string instead of going through a file descriptor so that Java layer can process metrics data directly * Add new method dumpMetrics(std::string*) Bug: 33693818 Test: adb shell dumpsys bluetooth_manager --proto-bin SL4A metrics tests: BtMetricsTest, BtFunhausMetricsTest Change-Id: I67883c1371862d7e4ff33cec01d710d2d8f274c9 --- btif/src/bluetooth.cc | 13 ++++++------- device/include/interop.h | 2 +- device/src/interop.cc | 2 +- include/hardware/bluetooth.h | 8 ++++++++ service/hal/fake_bluetooth_interface.cc | 1 + 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/btif/src/bluetooth.cc b/btif/src/bluetooth.cc index 5d2ffcc5e..d0c090b66 100644 --- a/btif/src/bluetooth.cc +++ b/btif/src/bluetooth.cc @@ -303,13 +303,6 @@ static int read_energy_info() { } static void dump(int fd, const char** arguments) { - if (arguments != NULL && arguments[0] != NULL) { - if (strncmp(arguments[0], "--proto-bin", 11) == 0) { - system_bt_osi::BluetoothMetricsLogger::GetInstance()->WriteBase64(fd, - true); - return; - } - } btif_debug_conn_dump(fd); btif_debug_bond_event_dump(fd); btif_debug_a2dp_dump(fd); @@ -328,6 +321,11 @@ static void dump(int fd, const char** arguments) { close(fd); } +static void dumpMetrics(std::string* output) { + system_bt_osi::BluetoothMetricsLogger::GetInstance()->WriteString(output, + true); +} + static const void* get_profile_interface(const char* profile_id) { LOG_INFO(LOG_TAG, "%s: id = %s", __func__, profile_id); @@ -447,6 +445,7 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = { set_os_callouts, read_energy_info, dump, + dumpMetrics, config_clear, interop_database_clear, interop_database_add, diff --git a/device/include/interop.h b/device/include/interop.h index 2d6c8ac05..b31efc36b 100644 --- a/device/include/interop.h +++ b/device/include/interop.h @@ -113,7 +113,7 @@ bool interop_match_name(const interop_feature_t feature, const char* name); // |length| must be greater than 0 and less than RawAddress::kLength. // As |interop_feature_t| is not exposed in the public API, feature must be a // valid integer representing an option in the enum. -void interop_database_add(const uint16_t feature, const RawAddress* addr, +void interop_database_add(uint16_t feature, const RawAddress* addr, size_t length); // Clear the dynamic portion of the interoperability workaround database. diff --git a/device/src/interop.cc b/device/src/interop.cc index 4ddad1d98..c2ed2a8c9 100644 --- a/device/src/interop.cc +++ b/device/src/interop.cc @@ -76,7 +76,7 @@ bool interop_match_name(const interop_feature_t feature, const char* name) { return false; } -void interop_database_add(const uint16_t feature, const RawAddress* addr, +void interop_database_add(uint16_t feature, const RawAddress* addr, size_t length) { CHECK(addr); CHECK(length > 0); diff --git a/include/hardware/bluetooth.h b/include/hardware/bluetooth.h index 692083cdb..dd7b8e119 100644 --- a/include/hardware/bluetooth.h +++ b/include/hardware/bluetooth.h @@ -559,6 +559,14 @@ typedef struct { void (*dump)(int fd, const char** arguments); /** + * Native support for metrics protobuf dumping. The dumping format will be + * raw byte array + * + * @param output an externally allocated string to dump serialized protobuf + */ + void (*dumpMetrics)(std::string* output); + + /** * Clear /data/misc/bt_config.conf and erase all stored connections */ int (*config_clear)(void); diff --git a/service/hal/fake_bluetooth_interface.cc b/service/hal/fake_bluetooth_interface.cc index 0cb66b84c..08751cd53 100644 --- a/service/hal/fake_bluetooth_interface.cc +++ b/service/hal/fake_bluetooth_interface.cc @@ -69,6 +69,7 @@ bt_interface_t fake_bt_iface = { nullptr, /* set_os_callouts */ nullptr, /* read_energy_info */ nullptr, /* dump */ + nullptr, /* dumpMetrics */ nullptr, /* config clear */ nullptr, /* interop_database_clear */ nullptr /* interop_database_add */ -- 2.11.0