From e383605528d54572ce13dfd165068bea32bc99fa Mon Sep 17 00:00:00 2001 From: Henri Chataing Date: Wed, 12 Mar 2025 20:39:14 +0000 Subject: btif: Inline methods from btif_metrics_logging.h Bug: 401588157 Test: m com.android.bt Flag: EXEMPT, no logical change Change-Id: I3be0fd47902e75c876220bf90b838832252ad7d7 --- system/btif/Android.bp | 1 - system/btif/BUILD.gn | 1 - system/btif/include/btif_metrics_logging.h | 72 ------------------- system/btif/src/bluetooth.cc | 4 +- system/btif/src/btif_a2dp_source.cc | 41 ++++++----- system/btif/src/btif_av.cc | 31 ++++---- system/btif/src/btif_config.cc | 15 ++-- system/btif/src/btif_dm.cc | 9 +-- system/btif/src/btif_hf.cc | 11 ++- system/btif/src/btif_hh.cc | 26 +++---- system/btif/src/btif_metrics_logging.cc | 111 ----------------------------- system/btif/src/btif_sock_logging.cc | 4 +- system/btif/src/btif_sock_rfc.cc | 14 ++-- 13 files changed, 80 insertions(+), 260 deletions(-) delete mode 100644 system/btif/include/btif_metrics_logging.h delete mode 100644 system/btif/src/btif_metrics_logging.cc (limited to 'system/btif') diff --git a/system/btif/Android.bp b/system/btif/Android.bp index 0eb097dca7..82544f36ba 100644 --- a/system/btif/Android.bp +++ b/system/btif/Android.bp @@ -122,7 +122,6 @@ cc_library_static { "src/btif_keystore.cc", "src/btif_le_audio.cc", "src/btif_le_audio_broadcaster.cc", - "src/btif_metrics_logging.cc", "src/btif_pan.cc", "src/btif_profile_queue.cc", "src/btif_profile_queue.cc", diff --git a/system/btif/BUILD.gn b/system/btif/BUILD.gn index ea6a0f6fbc..9def60989b 100644 --- a/system/btif/BUILD.gn +++ b/system/btif/BUILD.gn @@ -64,7 +64,6 @@ static_library("btif") { "src/btif_jni_task.cc", "src/btif_keystore.cc", "src/btif_le_audio.cc", - "src/btif_metrics_logging.cc", "src/btif_pan.cc", "src/btif_profile_queue.cc", "src/btif_profile_storage.cc", diff --git a/system/btif/include/btif_metrics_logging.h b/system/btif/include/btif_metrics_logging.h deleted file mode 100644 index 94f7a66b79..0000000000 --- a/system/btif/include/btif_metrics_logging.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2021 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. - */ - -#pragma once - -#include -#include - -#include "main/shim/metric_id_api.h" -#include "types/raw_address.h" - -void log_a2dp_audio_underrun_event(const RawAddress& address, uint64_t encoding_interval_millis, - int num_missing_pcm_bytes); - -void log_a2dp_audio_overrun_event(const RawAddress& address, uint64_t encoding_interval_millis, - int num_dropped_buffers, int num_dropped_encoded_frames, - int num_dropped_encoded_bytes); - -void log_a2dp_playback_event(const RawAddress& address, int playback_state, int audio_coding_mode); - -void log_a2dp_session_metrics_event(const RawAddress& address, int64_t audio_duration_ms, - int media_timer_min_ms, int media_timer_max_ms, - int media_timer_avg_ms, int total_scheduling_count, - int buffer_overruns_max_count, int buffer_overruns_total, - float buffer_underruns_average, int buffer_underruns_count, - int64_t codec_index, bool is_a2dp_offload); - -void log_read_rssi_result(const RawAddress& address, uint16_t handle, uint32_t cmd_status, - int8_t rssi); - -void log_read_failed_contact_counter_result(const RawAddress& address, uint16_t handle, - uint32_t cmd_status, int32_t failed_contact_counter); - -void log_read_tx_power_level_result(const RawAddress& address, uint16_t handle, uint32_t cmd_status, - int32_t transmit_power_level); - -void log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum key, int64_t value); - -void log_socket_connection_state(const RawAddress& address, int port, int type, - android::bluetooth::SocketConnectionstateEnum connection_state, - int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port, - android::bluetooth::SocketRoleEnum socket_role, - uint64_t connection_duration_ms, - android::bluetooth::SocketErrorEnum error_code, - bool is_hardware_offload); - -bool init_metric_id_allocator(const std::unordered_map& paired_device_map, - bluetooth::shim::CallbackLegacy save_id_callback, - bluetooth::shim::CallbackLegacy forget_device_callback); - -bool close_metric_id_allocator(); - -int allocate_metric_id_from_metric_id_allocator(const RawAddress&); - -int save_metric_id_from_metric_id_allocator(const RawAddress&); - -void forget_device_from_metric_id_allocator(const RawAddress&); - -bool is_valid_id_from_metric_id_allocator(const int id); diff --git a/system/btif/src/bluetooth.cc b/system/btif/src/bluetooth.cc index 5741b05c4f..9badbc9ab6 100644 --- a/system/btif/src/bluetooth.cc +++ b/system/btif/src/bluetooth.cc @@ -71,7 +71,6 @@ #include "btif/include/btif_hh.h" #include "btif/include/btif_keystore.h" #include "btif/include/btif_le_audio.h" -#include "btif/include/btif_metrics_logging.h" #include "btif/include/btif_pan.h" #include "btif/include/btif_profile_storage.h" #include "btif/include/btif_rc.h" @@ -99,6 +98,7 @@ #include "hardware/bt_vc.h" #include "internal_include/bt_target.h" #include "main/shim/dumpsys.h" +#include "main/shim/metric_id_api.h" #include "os/parameter_provider.h" #include "osi/include/alarm.h" #include "osi/include/allocator.h" @@ -1099,7 +1099,7 @@ static std::string obfuscate_address(const RawAddress& address) { } static int get_metric_id(const RawAddress& address) { - return allocate_metric_id_from_metric_id_allocator(address); + return bluetooth::shim::AllocateIdFromMetricIdAllocator(address); } static int set_dynamic_audio_buffer_size(int codec, int size) { diff --git a/system/btif/src/btif_a2dp_source.cc b/system/btif/src/btif_a2dp_source.cc index bf4c00c0d5..20805a92bd 100644 --- a/system/btif/src/btif_a2dp_source.cc +++ b/system/btif/src/btif_a2dp_source.cc @@ -46,13 +46,13 @@ #include "btif_av_co.h" #include "btif_common.h" #include "btif_hf.h" -#include "btif_metrics_logging.h" #include "btm_iso_api.h" #include "common/message_loop_thread.h" #include "common/metrics.h" #include "common/repeating_timer.h" #include "common/time_util.h" #include "hardware/bt_av.h" +#include "main/shim/metrics_api.h" #include "osi/include/allocator.h" #include "osi/include/fixed_queue.h" #include "osi/include/wakelock.h" @@ -931,8 +931,9 @@ static uint32_t btif_a2dp_source_read_callback(uint8_t* p_buf, uint32_t len) { btif_a2dp_source_cb.stats.media_read_total_underflow_count++; btif_a2dp_source_cb.stats.media_read_last_underflow_us = bluetooth::common::time_get_os_boottime_us(); - log_a2dp_audio_underrun_event(btif_av_source_active_peer(), - btif_a2dp_source_cb.encoder_interval_ms, len - bytes_read); + bluetooth::shim::LogMetricA2dpAudioUnderrunEvent(btif_av_source_active_peer(), + btif_a2dp_source_cb.encoder_interval_ms, + len - bytes_read); } return bytes_read; @@ -984,9 +985,9 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n, osi_free(p_data); } } - log_a2dp_audio_overrun_event(btif_av_source_active_peer(), - btif_a2dp_source_cb.encoder_interval_ms, drop_n, - num_dropped_encoded_frames, num_dropped_encoded_bytes); + bluetooth::shim::LogMetricA2dpAudioOverrunEvent( + btif_av_source_active_peer(), btif_a2dp_source_cb.encoder_interval_ms, drop_n, + num_dropped_encoded_frames, num_dropped_encoded_bytes); // Request additional debug info if we had to flush buffers RawAddress peer_bda = btif_av_source_active_peer(); @@ -1276,12 +1277,12 @@ static void btif_a2dp_source_update_metrics(void) { } if (metrics.audio_duration_ms != -1) { - log_a2dp_session_metrics_event(btif_av_source_active_peer(), metrics.audio_duration_ms, - metrics.media_timer_min_ms, metrics.media_timer_max_ms, - metrics.media_timer_avg_ms, metrics.total_scheduling_count, - metrics.buffer_overruns_max_count, metrics.buffer_overruns_total, - metrics.buffer_underruns_average, metrics.buffer_underruns_count, - metrics.codec_index, metrics.is_a2dp_offload); + bluetooth::shim::LogMetricA2dpSessionMetricsEvent( + btif_av_source_active_peer(), metrics.audio_duration_ms, metrics.media_timer_min_ms, + metrics.media_timer_max_ms, metrics.media_timer_avg_ms, metrics.total_scheduling_count, + metrics.buffer_overruns_max_count, metrics.buffer_overruns_total, + metrics.buffer_underruns_average, metrics.buffer_underruns_count, metrics.codec_index, + metrics.is_a2dp_offload); } } @@ -1301,8 +1302,9 @@ static void btm_read_rssi_cb(void* data) { return; } - log_read_rssi_result(result->rem_bda, bluetooth::common::kUnknownConnectionHandle, - result->hci_status, result->rssi); + bluetooth::shim::LogMetricReadRssiResult(result->rem_bda, + bluetooth::common::kUnknownConnectionHandle, + result->hci_status, result->rssi); log::warn("device: {}, rssi: {}", result->rem_bda, result->rssi); } @@ -1318,9 +1320,9 @@ static void btm_read_failed_contact_counter_cb(void* data) { log::error("unable to read Failed Contact Counter (status {})", result->status); return; } - log_read_failed_contact_counter_result(result->rem_bda, - bluetooth::common::kUnknownConnectionHandle, - result->hci_status, result->failed_contact_counter); + bluetooth::shim::LogMetricReadFailedContactCounterResult( + result->rem_bda, bluetooth::common::kUnknownConnectionHandle, result->hci_status, + result->failed_contact_counter); log::warn("device: {}, Failed Contact Counter: {}", result->rem_bda, result->failed_contact_counter); @@ -1337,8 +1339,9 @@ static void btm_read_tx_power_cb(void* data) { log::error("unable to read Tx Power (status {})", result->status); return; } - log_read_tx_power_level_result(result->rem_bda, bluetooth::common::kUnknownConnectionHandle, - result->hci_status, result->tx_power); + bluetooth::shim::LogMetricReadTxPowerLevelResult(result->rem_bda, + bluetooth::common::kUnknownConnectionHandle, + result->hci_status, result->tx_power); log::warn("device: {}, Tx Power: {}", result->rem_bda, result->tx_power); } diff --git a/system/btif/src/btif_av.cc b/system/btif/src/btif_av.cc index 101ebcc4a0..2ee3be4c88 100644 --- a/system/btif/src/btif_av.cc +++ b/system/btif/src/btif_av.cc @@ -52,18 +52,17 @@ #include "btif/include/btif_a2dp_source.h" #include "btif/include/btif_av_co.h" #include "btif/include/btif_common.h" -#include "btif/include/btif_metrics_logging.h" #include "btif/include/btif_profile_queue.h" #include "btif/include/btif_rc.h" #include "btif/include/btif_util.h" #include "btif/include/stack_manager_t.h" -#include "btif_metrics_logging.h" #include "common/state_machine.h" #include "device/include/device_iot_conf_defs.h" #include "device/include/device_iot_config.h" #include "hardware/bluetooth.h" #include "hardware/bt_av.h" #include "include/hardware/bt_rc.h" +#include "main/shim/metrics_api.h" #include "osi/include/alarm.h" #include "osi/include/allocator.h" #include "osi/include/properties.h" @@ -1985,7 +1984,7 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data // incoming/outgoing connect/disconnect requests. log::warn("Peer {} : event={}: transitioning to Idle due to ACL Disconnect", peer_.PeerAddress(), BtifAvEvent::EventName(event)); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_ACL_DISCONNECTED, 1); btif_report_connection_state(peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED, bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL, @@ -1998,7 +1997,7 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data case BTA_AV_REJECT_EVT: log::warn("Peer {} : event={} flags={}", peer_.PeerAddress(), BtifAvEvent::EventName(event), peer_.FlagsToString()); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_REJECT_EVT, 1); btif_report_connection_state(peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED, bt_status_t::BT_STATUS_AUTH_REJECTED, BTA_AV_FAIL, @@ -2080,7 +2079,7 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data btif_report_connection_state(peer_.PeerAddress(), BTAV_CONNECTION_STATE_CONNECTED, bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS, peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_SUCCESS, 1); } else { if (btif_rc_is_connected_peer(peer_.PeerAddress())) { @@ -2099,7 +2098,7 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data btif_report_connection_state(peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED, bt_status_t::BT_STATUS_FAIL, status, peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_FAILURE, 1); } @@ -2139,8 +2138,8 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data "Peer {} : event={} : device is already connecting, ignore Connect " "request", peer_.PeerAddress(), BtifAvEvent::EventName(event)); - log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING, - 1); + bluetooth::shim::CountCounterMetrics( + android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING, 1); btif_queue_advance(); } break; @@ -2151,15 +2150,15 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data "Peer {} : event={} : device is already connecting, ignore incoming " "request", peer_.PeerAddress(), BtifAvEvent::EventName(event)); - log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING, - 1); + bluetooth::shim::CountCounterMetrics( + android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING, 1); } break; case BTIF_AV_OFFLOAD_START_REQ_EVT: log::error("Peer {} : event={}: stream is not Opened", peer_.PeerAddress(), BtifAvEvent::EventName(event)); btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::A2DP_OFFLOAD_START_REQ_FAILURE, 1); break; @@ -2169,8 +2168,8 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL, peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource); peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle); - log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_CLOSE, - 1); + bluetooth::shim::CountCounterMetrics( + android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_CLOSE, 1); DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(peer_.PeerAddress(), IOT_CONF_KEY_A2DP_CONN_FAIL_COUNT); if (peer_.SelfInitiatedConnection()) { btif_queue_advance(); @@ -2184,7 +2183,7 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource); peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle); DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(peer_.PeerAddress(), IOT_CONF_KEY_A2DP_CONN_FAIL_COUNT); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_DISCONNECTED, 1); if (peer_.SelfInitiatedConnection()) { btif_queue_advance(); @@ -2203,7 +2202,7 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data CHECK_RC_EVENT(event, reinterpret_cast(p_data)); default: - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_UNKNOWN_EVENT, 1); log::warn("Peer {} : Unhandled event={}", peer_.PeerAddress(), BtifAvEvent::EventName(event)); return false; @@ -2933,7 +2932,7 @@ static void btif_report_audio_state(const RawAddress& peer_address, btav_audio_s ? AudioCodingModeEnum::AUDIO_CODING_MODE_HARDWARE : AudioCodingModeEnum::AUDIO_CODING_MODE_SOFTWARE; - log_a2dp_playback_event(peer_address, playback_state, audio_coding_mode); + bluetooth::shim::LogMetricA2dpPlaybackEvent(peer_address, playback_state, audio_coding_mode); } void btif_av_report_source_codec_state( diff --git a/system/btif/src/btif_config.cc b/system/btif/src/btif_config.cc index 2ee8fe494d..9a0e50dea1 100644 --- a/system/btif/src/btif_config.cc +++ b/system/btif/src/btif_config.cc @@ -32,9 +32,10 @@ #include #include "btif_keystore.h" -#include "btif_metrics_logging.h" #include "common/address_obfuscator.h" #include "main/shim/config.h" +#include "main/shim/metric_id_api.h" +#include "main/shim/metrics_api.h" #include "main/shim/shim.h" #include "storage/config_keys.h" #include "types/raw_address.h" @@ -111,7 +112,7 @@ static void init_metric_id_allocator() { // there is one metric id under this mac_address int id = 0; btif_config_get_int(addr_str, BTIF_STORAGE_KEY_METRICS_ID_KEY, &id); - if (is_valid_id_from_metric_id_allocator(id)) { + if (bluetooth::shim::IsValidIdFromMetricIdAllocator(id)) { paired_device_map[mac_address] = id; is_valid_id_found = true; } @@ -128,15 +129,15 @@ static void init_metric_id_allocator() { auto forget_device_callback = [](const RawAddress& address, const int /* id */) { return btif_config_remove(address.ToString(), BTIF_STORAGE_KEY_METRICS_ID_KEY); }; - if (!init_metric_id_allocator(paired_device_map, std::move(save_device_callback), - std::move(forget_device_callback))) { + if (!bluetooth::shim::InitMetricIdAllocator(paired_device_map, std::move(save_device_callback), + std::move(forget_device_callback))) { log::fatal("Failed to initialize MetricIdAllocator"); } // Add device_without_id for (auto& address : addresses_without_id) { - allocate_metric_id_from_metric_id_allocator(address); - save_metric_id_from_metric_id_allocator(address); + bluetooth::shim::AllocateIdFromMetricIdAllocator(address); + bluetooth::shim::SaveDeviceOnMetricIdAllocator(address); } } @@ -160,7 +161,7 @@ static future_t* clean_up(void) { "assert failed: bluetooth::shim::is_gd_stack_started_up()"); // GD storage module cleanup by itself std::unique_lock lock(config_lock); - close_metric_id_allocator(); + bluetooth::shim::CloseMetricIdAllocator(); return future_new_immediate(FUTURE_SUCCESS); } diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc index 96ed5848b1..44b876af4e 100644 --- a/system/btif/src/btif_dm.cc +++ b/system/btif/src/btif_dm.cc @@ -57,7 +57,6 @@ #include "btif_api.h" #include "btif_bqr.h" #include "btif_config.h" -#include "btif_metrics_logging.h" #include "btif_sdp.h" #include "btif_storage.h" #include "btif_util.h" @@ -72,6 +71,8 @@ #include "main/shim/entry.h" #include "main/shim/helpers.h" #include "main/shim/le_advertising_manager.h" +#include "main/shim/metric_id_api.h" +#include "main/shim/metrics_api.h" #include "main_thread.h" #include "metrics/bluetooth_event.h" #include "os/system_properties.h" @@ -582,11 +583,11 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, state, pairing_cb.state, pairing_cb.sdp_attempts); if (state == BT_BOND_STATE_NONE) { - forget_device_from_metric_id_allocator(bd_addr); + bluetooth::shim::ForgetDeviceFromMetricIdAllocator(bd_addr); btif_config_remove_device(bd_addr.ToString()); } else if (state == BT_BOND_STATE_BONDED) { - allocate_metric_id_from_metric_id_allocator(bd_addr); - if (!save_metric_id_from_metric_id_allocator(bd_addr)) { + bluetooth::shim::AllocateIdFromMetricIdAllocator(bd_addr); + if (!bluetooth::shim::SaveDeviceOnMetricIdAllocator(bd_addr)) { log::error("Fail to save metric id for device:{}", bd_addr); } } diff --git a/system/btif/src/btif_hf.cc b/system/btif/src/btif_hf.cc index 33fb900e07..c5dc2bca6a 100644 --- a/system/btif/src/btif_hf.cc +++ b/system/btif/src/btif_hf.cc @@ -51,7 +51,6 @@ #include "bta/include/utl.h" #include "bta_ag_swb_aptx.h" #include "btif/include/btif_common.h" -#include "btif/include/btif_metrics_logging.h" #include "btif/include/btif_profile_queue.h" #include "btif/include/btif_util.h" #include "btm_api_types.h" @@ -390,7 +389,7 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { p_data->open.status, btif_hf_cb[idx].connected_bda, p_data->open.bd_addr); bt_hf_callbacks->ConnectionStateCallback(BTHF_CONNECTION_STATE_DISCONNECTED, &(p_data->open.bd_addr)); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::HFP_COLLISON_AT_AG_OPEN, 1); } break; @@ -412,7 +411,7 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { btif_hf_cb[idx].connected_bda, p_data->open.bd_addr); bt_hf_callbacks->ConnectionStateCallback(BTHF_CONNECTION_STATE_DISCONNECTED, &(btif_hf_cb[idx].connected_bda)); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::HFP_COLLISON_AT_CONNECTING, 1); reset_control_block(&btif_hf_cb[idx]); btif_queue_advance(); @@ -472,7 +471,7 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state, &connected_bda); } - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::HFP_SELF_INITIATED_AG_FAILED, 1); btif_queue_advance(); if (btm_sec_is_a_bonded_dev(connected_bda)) { @@ -496,8 +495,8 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state, &connected_bda); if (failed_to_setup_slc) { log::error("failed to setup SLC for {}", connected_bda); - log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum::HFP_SLC_SETUP_FAILED, - 1); + bluetooth::shim::CountCounterMetrics( + android::bluetooth::CodePathCounterKeyEnum::HFP_SLC_SETUP_FAILED, 1); btif_queue_advance(); LogMetricHfpSlcFail(ToGdAddress(p_data->open.bd_addr)); DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(btif_hf_cb[idx].connected_bda, diff --git a/system/btif/src/btif_hh.cc b/system/btif/src/btif_hh.cc index 7288abe98c..36ad3d148e 100644 --- a/system/btif/src/btif_hh.cc +++ b/system/btif/src/btif_hh.cc @@ -48,7 +48,6 @@ #include "btif/include/btif_common.h" #include "btif/include/btif_dm.h" #include "btif/include/btif_hd.h" -#include "btif/include/btif_metrics_logging.h" #include "btif/include/btif_profile_storage.h" #include "btif/include/btif_storage.h" #include "btif/include/btif_util.h" @@ -56,6 +55,7 @@ #include "include/hardware/bt_hh.h" #include "internal_include/bt_target.h" #include "main/shim/dumpsys.h" +#include "main/shim/metrics_api.h" #include "osi/include/alarm.h" #include "osi/include/allocator.h" #include "stack/include/bt_hdr.h" @@ -468,7 +468,7 @@ static void btif_hh_incoming_connection_timeout(void* data) { handle); } log::warn("Reject unexpected incoming HID Connection, device: {}", conn.link_spec); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_INCOMING_CONNECTION_REJECTED, 1); btif_hh_device_t* p_dev = btif_hh_find_dev_by_link_spec(conn.link_spec); @@ -529,7 +529,7 @@ static bool hh_add_device(const tAclLinkSpec& link_spec, tBTA_HH_ATTR_MASK attr_ } log::error("Out of space to add device"); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_MAX_ADDED_DEVICE_LIMIT_REACHED, 1); return false; } @@ -633,7 +633,7 @@ static void hh_open_handler(tBTA_HH_CONN& conn) { log::warn("Reject Incoming HID Connection, device: {}, state: {}", conn.link_spec, bthh_connection_state_text(dev_status)); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_INCOMING_CONNECTION_REJECTED, 1); if (p_dev != nullptr) { @@ -910,9 +910,10 @@ static void hh_vc_unplug_handler(tBTA_HH_CBDATA& dev_status) { BTHH_STATE_UPDATE(p_dev->link_spec, p_dev->dev_status); if (!p_dev->local_vup) { - log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum:: - HIDH_COUNT_VIRTUAL_UNPLUG_REQUESTED_BY_REMOTE_DEVICE, - 1); + bluetooth::shim::CountCounterMetrics( + android::bluetooth::CodePathCounterKeyEnum:: + HIDH_COUNT_VIRTUAL_UNPLUG_REQUESTED_BY_REMOTE_DEVICE, + 1); } // Remove the HID device @@ -1193,9 +1194,10 @@ bt_status_t btif_hh_connect(const tAclLinkSpec& link_spec) { if (!p_dev && btif_hh_cb.device_num >= BTIF_HH_MAX_HID) { // No space for more HID device now. log::warn("Error, exceeded the maximum supported HID device number {}", BTIF_HH_MAX_HID); - log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum:: - HIDH_COUNT_CONNECT_REQ_WHEN_MAX_DEVICE_LIMIT_REACHED, - 1); + bluetooth::shim::CountCounterMetrics( + android::bluetooth::CodePathCounterKeyEnum:: + HIDH_COUNT_CONNECT_REQ_WHEN_MAX_DEVICE_LIMIT_REACHED, + 1); return BT_STATUS_NOMEM; } @@ -2030,7 +2032,7 @@ static bt_status_t get_report(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, return BT_STATUS_DEVICE_NOT_FOUND; } else if (((int)reportType) <= BTA_HH_RPTT_RESRV || ((int)reportType) > BTA_HH_RPTT_FEATURE) { log::error("report type={} not supported", reportType); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_WRONG_REPORT_TYPE, 1); return BT_STATUS_UNSUPPORTED; } else { @@ -2102,7 +2104,7 @@ static bt_status_t set_report(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, return BT_STATUS_DEVICE_NOT_FOUND; } else if (((int)reportType) <= BTA_HH_RPTT_RESRV || ((int)reportType) > BTA_HH_RPTT_FEATURE) { log::error("report type={} not supported", reportType); - log_counter_metrics_btif( + bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_WRONG_REPORT_TYPE, 1); return BT_STATUS_UNSUPPORTED; } else { diff --git a/system/btif/src/btif_metrics_logging.cc b/system/btif/src/btif_metrics_logging.cc deleted file mode 100644 index 40f2fed315..0000000000 --- a/system/btif/src/btif_metrics_logging.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2021 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. - */ - -#include "btif/include/btif_metrics_logging.h" - -#include -#include - -#include "main/shim/metrics_api.h" -#include "types/raw_address.h" - -void log_a2dp_audio_underrun_event(const RawAddress& address, uint64_t encoding_interval_millis, - int num_missing_pcm_bytes) { - bluetooth::shim::LogMetricA2dpAudioUnderrunEvent(address, encoding_interval_millis, - num_missing_pcm_bytes); -} - -void log_a2dp_audio_overrun_event(const RawAddress& address, uint64_t encoding_interval_millis, - int num_dropped_buffers, int num_dropped_encoded_frames, - int num_dropped_encoded_bytes) { - bluetooth::shim::LogMetricA2dpAudioOverrunEvent(address, encoding_interval_millis, - num_dropped_buffers, num_dropped_encoded_frames, - num_dropped_encoded_bytes); -} - -void log_a2dp_playback_event(const RawAddress& address, int playback_state, int audio_coding_mode) { - bluetooth::shim::LogMetricA2dpPlaybackEvent(address, playback_state, audio_coding_mode); -} - -void log_a2dp_session_metrics_event(const RawAddress& address, int64_t audio_duration_ms, - int media_timer_min_ms, int media_timer_max_ms, - int media_timer_avg_ms, int total_scheduling_count, - int buffer_overruns_max_count, int buffer_overruns_total, - float buffer_underruns_average, int buffer_underruns_count, - int64_t codec_index, bool is_a2dp_offload) { - bluetooth::shim::LogMetricA2dpSessionMetricsEvent( - address, audio_duration_ms, media_timer_min_ms, media_timer_max_ms, media_timer_avg_ms, - total_scheduling_count, buffer_overruns_max_count, buffer_overruns_total, - buffer_underruns_average, buffer_underruns_count, codec_index, is_a2dp_offload); -} - -void log_read_rssi_result(const RawAddress& address, uint16_t handle, uint32_t cmd_status, - int8_t rssi) { - bluetooth::shim::LogMetricReadRssiResult(address, handle, cmd_status, rssi); -} - -void log_read_failed_contact_counter_result(const RawAddress& address, uint16_t handle, - uint32_t cmd_status, int32_t failed_contact_counter) { - bluetooth::shim::LogMetricReadFailedContactCounterResult(address, handle, cmd_status, - failed_contact_counter); -} - -void log_read_tx_power_level_result(const RawAddress& address, uint16_t handle, uint32_t cmd_status, - int32_t transmit_power_level) { - bluetooth::shim::LogMetricReadTxPowerLevelResult(address, handle, cmd_status, - transmit_power_level); -} - -void log_socket_connection_state(const RawAddress& address, int port, int type, - android::bluetooth::SocketConnectionstateEnum connection_state, - int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port, - android::bluetooth::SocketRoleEnum socket_role, - uint64_t connection_duration_ms, - android::bluetooth::SocketErrorEnum error_code, - bool is_hardware_offload) { - bluetooth::shim::LogMetricSocketConnectionState( - address, port, type, connection_state, tx_bytes, rx_bytes, uid, server_port, socket_role, - connection_duration_ms, error_code, is_hardware_offload); -} - -void log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum key, int64_t value) { - bluetooth::shim::CountCounterMetrics(key, value); -} - -bool init_metric_id_allocator(const std::unordered_map& paired_device_map, - bluetooth::shim::CallbackLegacy save_device_callback, - bluetooth::shim::CallbackLegacy forget_device_callback) { - return bluetooth::shim::InitMetricIdAllocator(paired_device_map, std::move(save_device_callback), - std::move(forget_device_callback)); -} - -bool close_metric_id_allocator() { return bluetooth::shim::CloseMetricIdAllocator(); } - -int allocate_metric_id_from_metric_id_allocator(const RawAddress& address) { - return bluetooth::shim::AllocateIdFromMetricIdAllocator(address); -} - -int save_metric_id_from_metric_id_allocator(const RawAddress& address) { - return bluetooth::shim::SaveDeviceOnMetricIdAllocator(address); -} - -void forget_device_from_metric_id_allocator(const RawAddress& address) { - bluetooth::shim::ForgetDeviceFromMetricIdAllocator(address); -} - -bool is_valid_id_from_metric_id_allocator(const int id) { - return bluetooth::shim::IsValidIdFromMetricIdAllocator(id); -} diff --git a/system/btif/src/btif_sock_logging.cc b/system/btif/src/btif_sock_logging.cc index 111e52002b..8847daa7f1 100644 --- a/system/btif/src/btif_sock_logging.cc +++ b/system/btif/src/btif_sock_logging.cc @@ -23,9 +23,9 @@ #include -#include "btif/include/btif_metrics_logging.h" #include "btif/include/btif_sock.h" #include "common/time_util.h" +#include "main/shim/metrics_api.h" #include "types/raw_address.h" #define SOCK_LOGGER_SIZE_MAX 16 @@ -79,7 +79,7 @@ void btif_sock_connection_logger(const RawAddress& address, int port, int type, } clock_gettime(CLOCK_REALTIME, &connection_logger[index].timestamp); - log_socket_connection_state( + bluetooth::shim::LogMetricSocketConnectionState( address, port, type, toConnectionStateEnum(state), tx_bytes, rx_bytes, uid, server_port, toSocketRoleEnum(role), getConnectionDuration(connection_start_time_ms), toSocketErrorEnum(error_code), data_path == BTSOCK_DATA_PATH_HARDWARE_OFFLOAD); diff --git a/system/btif/src/btif_sock_rfc.cc b/system/btif/src/btif_sock_rfc.cc index 4c75b0f355..1ea4bf9981 100644 --- a/system/btif/src/btif_sock_rfc.cc +++ b/system/btif/src/btif_sock_rfc.cc @@ -33,7 +33,6 @@ #include "bta/include/bta_jv_co.h" #include "bta/include/bta_rfcomm_metrics.h" #include "bta/include/bta_rfcomm_scn.h" -#include "btif/include/btif_metrics_logging.h" #include "btif/include/btif_sock.h" #include "btif/include/btif_sock_l2cap.h" #include "btif/include/btif_sock_logging.h" @@ -45,6 +44,7 @@ #include "include/hardware/bt_sock.h" #include "lpp/lpp_offload_interface.h" #include "main/shim/entry.h" +#include "main/shim/metrics_api.h" #include "osi/include/allocator.h" #include "osi/include/compat.h" #include "osi/include/list.h" @@ -909,12 +909,12 @@ static void on_rfc_close(tBTA_JV_RFCOMM_CLOSE* /* p_close */, uint32_t id) { log::warn("RFCOMM slot with id {} not found.", id); return; } - log_socket_connection_state(slot->addr, slot->id, BTSOCK_RFCOMM, - android::bluetooth::SOCKET_CONNECTION_STATE_DISCONNECTING, 0, 0, - slot->app_uid, slot->scn, - slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN - : android::bluetooth::SOCKET_ROLE_CONNECTION, - 0, android::bluetooth::SOCKET_ERROR_NONE, slot->data_path); + bluetooth::shim::LogMetricSocketConnectionState( + slot->addr, slot->id, BTSOCK_RFCOMM, + android::bluetooth::SOCKET_CONNECTION_STATE_DISCONNECTING, 0, 0, slot->app_uid, slot->scn, + slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN + : android::bluetooth::SOCKET_ROLE_CONNECTION, + 0, android::bluetooth::SOCKET_ERROR_NONE, slot->data_path); cleanup_rfc_slot(slot, BTSOCK_ERROR_NONE); } -- cgit v1.2.3-59-g8ed1b