Loading system/btif/src/btif_a2dp_source.cc +2 −2 Original line number Diff line number Diff line Loading @@ -324,8 +324,8 @@ static void btif_a2dp_source_shutdown_delayed(UNUSED_ATTR void* context) { btif_a2dp_source_cb.tx_audio_queue = NULL; btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_OFF; BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd("A2DP_SHUTDOWN", 0); BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd( system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0); } bool btif_a2dp_source_media_task_is_running(void) { Loading system/osi/include/metrics.h +15 −1 Original line number Diff line number Diff line Loading @@ -52,6 +52,12 @@ typedef enum { CONNECTION_TECHNOLOGY_TYPE_BREDR, } connection_tech_t; typedef enum { DISCONNECT_REASON_UNKNOWN, DISCONNECT_REASON_METRICS_DUMP, DISCONNECT_REASON_NEXT_START_WITHOUT_END_PREVIOUS, } disconnect_reason_t; /* Values of A2DP metrics that we care about * * audio_duration_ms : sum of audio duration (in milliseconds). Loading Loading @@ -173,7 +179,7 @@ class BluetoothMetricsLogger { * timestamp_ms : the timestamp of session end, 0 means now * */ void LogBluetoothSessionEnd(const std::string& disconnect_reason, void LogBluetoothSessionEnd(disconnect_reason_t disconnect_reason, uint64_t timestamp_ms); /* Loading Loading @@ -217,6 +223,14 @@ class BluetoothMetricsLogger { */ void Reset(); /* * Maximum number of log entries for each session or event */ static const size_t kMaxNumBluetoothSession = 50; static const size_t kMaxNumPairEvent = 50; static const size_t kMaxNumWakeEvent = 1000; static const size_t kMaxNumScanEvent = 50; private: BluetoothMetricsLogger(); Loading system/osi/src/metrics.cc +44 −18 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ using clearcut::connectivity::A2DPSession; using clearcut::connectivity::BluetoothLog; using clearcut::connectivity::BluetoothSession; using clearcut::connectivity::BluetoothSession_ConnectionTechnologyType; using clearcut::connectivity::BluetoothSession_DisconnectReasonType; using clearcut::connectivity::DeviceInfo; using clearcut::connectivity::DeviceInfo_DeviceType; using clearcut::connectivity::PairEvent; Loading @@ -54,17 +55,6 @@ using clearcut::connectivity::ScanEvent_ScanEventType; using clearcut::connectivity::WakeEvent; using clearcut::connectivity::WakeEvent_WakeEventType; namespace { // Maximum number of log entries for each repeated field const size_t global_max_num_bluetooth_session = 50; const size_t global_max_num_pair_event = 50; const size_t global_max_num_wake_event = 50; const size_t global_max_num_scan_event = 50; const std::string global_next_session_start_without_ending_previous = "NEXT_SESSION_START_WITHOUT_ENDING_PREVIOUS"; const std::string global_metrics_dump = "METRICS_DUMP"; } /* * Get current OS boot time in millisecond */ Loading Loading @@ -217,6 +207,22 @@ static WakeEvent_WakeEventType get_wake_event_type(wake_event_type_t type) { } } static BluetoothSession_DisconnectReasonType get_disconnect_reason_type( disconnect_reason_t type) { switch (type) { case DISCONNECT_REASON_METRICS_DUMP: return BluetoothSession_DisconnectReasonType:: BluetoothSession_DisconnectReasonType_METRICS_DUMP; case DISCONNECT_REASON_NEXT_START_WITHOUT_END_PREVIOUS: return BluetoothSession_DisconnectReasonType:: BluetoothSession_DisconnectReasonType_NEXT_START_WITHOUT_END_PREVIOUS; case DISCONNECT_REASON_UNKNOWN: default: return BluetoothSession_DisconnectReasonType:: BluetoothSession_DisconnectReasonType_UNKNOWN; } } struct BluetoothMetricsLogger::impl { impl(size_t max_bluetooth_session, size_t max_pair_event, size_t max_wake_event, size_t max_scan_event) Loading Loading @@ -248,9 +254,8 @@ struct BluetoothMetricsLogger::impl { }; BluetoothMetricsLogger::BluetoothMetricsLogger() : pimpl_(new impl(global_max_num_bluetooth_session, global_max_num_pair_event, global_max_num_wake_event, global_max_num_scan_event)) {} : pimpl_(new impl(kMaxNumBluetoothSession, kMaxNumPairEvent, kMaxNumWakeEvent, kMaxNumScanEvent)) {} void BluetoothMetricsLogger::LogPairEvent(uint32_t disconnect_reason, uint64_t timestamp_ms, Loading @@ -263,6 +268,11 @@ void BluetoothMetricsLogger::LogPairEvent(uint32_t disconnect_reason, event->set_disconnect_reason(disconnect_reason); event->set_event_time_millis(timestamp_ms); pimpl_->pair_event_queue_->Enqueue(event); { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_log_lock_); pimpl_->bluetooth_log_->set_num_pair_event( pimpl_->bluetooth_log_->num_pair_event() + 1); } } void BluetoothMetricsLogger::LogWakeEvent(wake_event_type_t type, Loading @@ -275,6 +285,11 @@ void BluetoothMetricsLogger::LogWakeEvent(wake_event_type_t type, event->set_name(name); event->set_event_time_millis(timestamp_ms); pimpl_->wake_event_queue_->Enqueue(event); { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_log_lock_); pimpl_->bluetooth_log_->set_num_wake_event( pimpl_->bluetooth_log_->num_wake_event() + 1); } } void BluetoothMetricsLogger::LogScanEvent(bool start, Loading @@ -292,13 +307,18 @@ void BluetoothMetricsLogger::LogScanEvent(bool start, event->set_number_results(results); event->set_event_time_millis(timestamp_ms); pimpl_->scan_event_queue_->Enqueue(event); { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_log_lock_); pimpl_->bluetooth_log_->set_num_scan_event( pimpl_->bluetooth_log_->num_scan_event() + 1); } } void BluetoothMetricsLogger::LogBluetoothSessionStart( connection_tech_t connection_tech_type, uint64_t timestamp_ms) { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_session_lock_); if (pimpl_->bluetooth_session_ != nullptr) { LogBluetoothSessionEnd(global_next_session_start_without_ending_previous, LogBluetoothSessionEnd(DISCONNECT_REASON_NEXT_START_WITHOUT_END_PREVIOUS, 0); } if (timestamp_ms == 0) { Loading @@ -311,7 +331,7 @@ void BluetoothMetricsLogger::LogBluetoothSessionStart( } void BluetoothMetricsLogger::LogBluetoothSessionEnd( const std::string& disconnect_reason, uint64_t timestamp_ms) { disconnect_reason_t disconnect_reason, uint64_t timestamp_ms) { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_session_lock_); if (pimpl_->bluetooth_session_ == nullptr) { return; Loading @@ -322,9 +342,15 @@ void BluetoothMetricsLogger::LogBluetoothSessionEnd( int64_t session_duration_sec = (timestamp_ms - pimpl_->bluetooth_session_start_time_ms_) / 1000; pimpl_->bluetooth_session_->set_session_duration_sec(session_duration_sec); pimpl_->bluetooth_session_->set_disconnect_reason(disconnect_reason); pimpl_->bluetooth_session_->set_disconnect_reason_type( get_disconnect_reason_type(disconnect_reason)); pimpl_->bt_session_queue_->Enqueue(pimpl_->bluetooth_session_); pimpl_->bluetooth_session_ = nullptr; { std::lock_guard<std::recursive_mutex> log_lock(pimpl_->bluetooth_log_lock_); pimpl_->bluetooth_log_->set_num_bluetooth_session( pimpl_->bluetooth_log_->num_bluetooth_session() + 1); } } void BluetoothMetricsLogger::LogBluetoothSessionDeviceInfo( Loading Loading @@ -408,7 +434,7 @@ void BluetoothMetricsLogger::CutoffSession() { new BluetoothSession(*pimpl_->bluetooth_session_); new_bt_session->clear_a2dp_session(); new_bt_session->clear_rfcomm_session(); LogBluetoothSessionEnd(global_metrics_dump, 0); LogBluetoothSessionEnd(DISCONNECT_REASON_METRICS_DUMP, 0); pimpl_->bluetooth_session_ = new_bt_session; pimpl_->bluetooth_session_start_time_ms_ = time_get_os_boottime_ms(); pimpl_->a2dp_session_metrics_ = A2dpSessionMetrics(); Loading system/osi/src/protos/bluetooth.proto +30 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,21 @@ message BluetoothLog { // Scan event information. repeated ScanEvent scan_event = 4; // Number of bonded devices. optional int32 num_bonded_devices = 5; // Number of BluetoothSession including discarded ones beyond capacity optional int64 num_bluetooth_session = 6; // Number of PairEvent including discarded ones beyond capacity optional int64 num_pair_event = 7; // Number of WakeEvent including discarded ones beyond capacity optional int64 num_wake_event = 8; // Number of ScanEvent including discarded ones beyond capacity optional int64 num_scan_event = 9; } // The information about the device. Loading Loading @@ -59,6 +74,17 @@ message BluetoothSession { CONNECTION_TECHNOLOGY_TYPE_BREDR = 2; } enum DisconnectReasonType { UNKNOWN = 0; // A metrics dump takes a snapshot of current Bluetooth session and thus // is not a real disconnect, but a discontinuation in metrics logging. // This enum indicates this situation. METRICS_DUMP = 1; NEXT_START_WITHOUT_END_PREVIOUS = 2; } // Duration of the session. optional int64 session_duration_sec = 2; Loading @@ -66,7 +92,7 @@ message BluetoothSession { optional ConnectionTechnologyType connection_technology_type = 3; // Reason for disconnecting. optional string disconnect_reason = 4; optional string disconnect_reason = 4 [deprecated = true]; // The information about the device which it is connected to. optional DeviceInfo device_connected_to = 5; Loading @@ -76,6 +102,9 @@ message BluetoothSession { // The information about the A2DP audio session. optional A2DPSession a2dp_session = 7; // Numeric reason for disconnecting as defined in metrics.h optional DisconnectReasonType disconnect_reason_type = 8; } message RFCommSession { Loading system/osi/src/wakelock.cc +2 −2 Original line number Diff line number Diff line Loading @@ -278,7 +278,7 @@ static void update_wakelock_acquired_stats(bt_status_t acquired_status) { wakelock_stats.last_acquired_timestamp_ms = now_ms; BluetoothMetricsLogger::GetInstance()->LogWakeEvent( system_bt_osi::WAKE_EVENT_ACQUIRED, "", WAKE_LOCK_ID, now_ms); system_bt_osi::WAKE_EVENT_ACQUIRED, "", "", now_ms); } // Loading Loading @@ -320,7 +320,7 @@ static void update_wakelock_released_stats(bt_status_t released_status) { wakelock_stats.total_acquired_interval_ms += delta_ms; BluetoothMetricsLogger::GetInstance()->LogWakeEvent( system_bt_osi::WAKE_EVENT_RELEASED, "", WAKE_LOCK_ID, now_ms); system_bt_osi::WAKE_EVENT_RELEASED, "", "", now_ms); } void wakelock_debug_dump(int fd) { Loading Loading
system/btif/src/btif_a2dp_source.cc +2 −2 Original line number Diff line number Diff line Loading @@ -324,8 +324,8 @@ static void btif_a2dp_source_shutdown_delayed(UNUSED_ATTR void* context) { btif_a2dp_source_cb.tx_audio_queue = NULL; btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_OFF; BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd("A2DP_SHUTDOWN", 0); BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd( system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0); } bool btif_a2dp_source_media_task_is_running(void) { Loading
system/osi/include/metrics.h +15 −1 Original line number Diff line number Diff line Loading @@ -52,6 +52,12 @@ typedef enum { CONNECTION_TECHNOLOGY_TYPE_BREDR, } connection_tech_t; typedef enum { DISCONNECT_REASON_UNKNOWN, DISCONNECT_REASON_METRICS_DUMP, DISCONNECT_REASON_NEXT_START_WITHOUT_END_PREVIOUS, } disconnect_reason_t; /* Values of A2DP metrics that we care about * * audio_duration_ms : sum of audio duration (in milliseconds). Loading Loading @@ -173,7 +179,7 @@ class BluetoothMetricsLogger { * timestamp_ms : the timestamp of session end, 0 means now * */ void LogBluetoothSessionEnd(const std::string& disconnect_reason, void LogBluetoothSessionEnd(disconnect_reason_t disconnect_reason, uint64_t timestamp_ms); /* Loading Loading @@ -217,6 +223,14 @@ class BluetoothMetricsLogger { */ void Reset(); /* * Maximum number of log entries for each session or event */ static const size_t kMaxNumBluetoothSession = 50; static const size_t kMaxNumPairEvent = 50; static const size_t kMaxNumWakeEvent = 1000; static const size_t kMaxNumScanEvent = 50; private: BluetoothMetricsLogger(); Loading
system/osi/src/metrics.cc +44 −18 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ using clearcut::connectivity::A2DPSession; using clearcut::connectivity::BluetoothLog; using clearcut::connectivity::BluetoothSession; using clearcut::connectivity::BluetoothSession_ConnectionTechnologyType; using clearcut::connectivity::BluetoothSession_DisconnectReasonType; using clearcut::connectivity::DeviceInfo; using clearcut::connectivity::DeviceInfo_DeviceType; using clearcut::connectivity::PairEvent; Loading @@ -54,17 +55,6 @@ using clearcut::connectivity::ScanEvent_ScanEventType; using clearcut::connectivity::WakeEvent; using clearcut::connectivity::WakeEvent_WakeEventType; namespace { // Maximum number of log entries for each repeated field const size_t global_max_num_bluetooth_session = 50; const size_t global_max_num_pair_event = 50; const size_t global_max_num_wake_event = 50; const size_t global_max_num_scan_event = 50; const std::string global_next_session_start_without_ending_previous = "NEXT_SESSION_START_WITHOUT_ENDING_PREVIOUS"; const std::string global_metrics_dump = "METRICS_DUMP"; } /* * Get current OS boot time in millisecond */ Loading Loading @@ -217,6 +207,22 @@ static WakeEvent_WakeEventType get_wake_event_type(wake_event_type_t type) { } } static BluetoothSession_DisconnectReasonType get_disconnect_reason_type( disconnect_reason_t type) { switch (type) { case DISCONNECT_REASON_METRICS_DUMP: return BluetoothSession_DisconnectReasonType:: BluetoothSession_DisconnectReasonType_METRICS_DUMP; case DISCONNECT_REASON_NEXT_START_WITHOUT_END_PREVIOUS: return BluetoothSession_DisconnectReasonType:: BluetoothSession_DisconnectReasonType_NEXT_START_WITHOUT_END_PREVIOUS; case DISCONNECT_REASON_UNKNOWN: default: return BluetoothSession_DisconnectReasonType:: BluetoothSession_DisconnectReasonType_UNKNOWN; } } struct BluetoothMetricsLogger::impl { impl(size_t max_bluetooth_session, size_t max_pair_event, size_t max_wake_event, size_t max_scan_event) Loading Loading @@ -248,9 +254,8 @@ struct BluetoothMetricsLogger::impl { }; BluetoothMetricsLogger::BluetoothMetricsLogger() : pimpl_(new impl(global_max_num_bluetooth_session, global_max_num_pair_event, global_max_num_wake_event, global_max_num_scan_event)) {} : pimpl_(new impl(kMaxNumBluetoothSession, kMaxNumPairEvent, kMaxNumWakeEvent, kMaxNumScanEvent)) {} void BluetoothMetricsLogger::LogPairEvent(uint32_t disconnect_reason, uint64_t timestamp_ms, Loading @@ -263,6 +268,11 @@ void BluetoothMetricsLogger::LogPairEvent(uint32_t disconnect_reason, event->set_disconnect_reason(disconnect_reason); event->set_event_time_millis(timestamp_ms); pimpl_->pair_event_queue_->Enqueue(event); { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_log_lock_); pimpl_->bluetooth_log_->set_num_pair_event( pimpl_->bluetooth_log_->num_pair_event() + 1); } } void BluetoothMetricsLogger::LogWakeEvent(wake_event_type_t type, Loading @@ -275,6 +285,11 @@ void BluetoothMetricsLogger::LogWakeEvent(wake_event_type_t type, event->set_name(name); event->set_event_time_millis(timestamp_ms); pimpl_->wake_event_queue_->Enqueue(event); { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_log_lock_); pimpl_->bluetooth_log_->set_num_wake_event( pimpl_->bluetooth_log_->num_wake_event() + 1); } } void BluetoothMetricsLogger::LogScanEvent(bool start, Loading @@ -292,13 +307,18 @@ void BluetoothMetricsLogger::LogScanEvent(bool start, event->set_number_results(results); event->set_event_time_millis(timestamp_ms); pimpl_->scan_event_queue_->Enqueue(event); { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_log_lock_); pimpl_->bluetooth_log_->set_num_scan_event( pimpl_->bluetooth_log_->num_scan_event() + 1); } } void BluetoothMetricsLogger::LogBluetoothSessionStart( connection_tech_t connection_tech_type, uint64_t timestamp_ms) { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_session_lock_); if (pimpl_->bluetooth_session_ != nullptr) { LogBluetoothSessionEnd(global_next_session_start_without_ending_previous, LogBluetoothSessionEnd(DISCONNECT_REASON_NEXT_START_WITHOUT_END_PREVIOUS, 0); } if (timestamp_ms == 0) { Loading @@ -311,7 +331,7 @@ void BluetoothMetricsLogger::LogBluetoothSessionStart( } void BluetoothMetricsLogger::LogBluetoothSessionEnd( const std::string& disconnect_reason, uint64_t timestamp_ms) { disconnect_reason_t disconnect_reason, uint64_t timestamp_ms) { std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_session_lock_); if (pimpl_->bluetooth_session_ == nullptr) { return; Loading @@ -322,9 +342,15 @@ void BluetoothMetricsLogger::LogBluetoothSessionEnd( int64_t session_duration_sec = (timestamp_ms - pimpl_->bluetooth_session_start_time_ms_) / 1000; pimpl_->bluetooth_session_->set_session_duration_sec(session_duration_sec); pimpl_->bluetooth_session_->set_disconnect_reason(disconnect_reason); pimpl_->bluetooth_session_->set_disconnect_reason_type( get_disconnect_reason_type(disconnect_reason)); pimpl_->bt_session_queue_->Enqueue(pimpl_->bluetooth_session_); pimpl_->bluetooth_session_ = nullptr; { std::lock_guard<std::recursive_mutex> log_lock(pimpl_->bluetooth_log_lock_); pimpl_->bluetooth_log_->set_num_bluetooth_session( pimpl_->bluetooth_log_->num_bluetooth_session() + 1); } } void BluetoothMetricsLogger::LogBluetoothSessionDeviceInfo( Loading Loading @@ -408,7 +434,7 @@ void BluetoothMetricsLogger::CutoffSession() { new BluetoothSession(*pimpl_->bluetooth_session_); new_bt_session->clear_a2dp_session(); new_bt_session->clear_rfcomm_session(); LogBluetoothSessionEnd(global_metrics_dump, 0); LogBluetoothSessionEnd(DISCONNECT_REASON_METRICS_DUMP, 0); pimpl_->bluetooth_session_ = new_bt_session; pimpl_->bluetooth_session_start_time_ms_ = time_get_os_boottime_ms(); pimpl_->a2dp_session_metrics_ = A2dpSessionMetrics(); Loading
system/osi/src/protos/bluetooth.proto +30 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,21 @@ message BluetoothLog { // Scan event information. repeated ScanEvent scan_event = 4; // Number of bonded devices. optional int32 num_bonded_devices = 5; // Number of BluetoothSession including discarded ones beyond capacity optional int64 num_bluetooth_session = 6; // Number of PairEvent including discarded ones beyond capacity optional int64 num_pair_event = 7; // Number of WakeEvent including discarded ones beyond capacity optional int64 num_wake_event = 8; // Number of ScanEvent including discarded ones beyond capacity optional int64 num_scan_event = 9; } // The information about the device. Loading Loading @@ -59,6 +74,17 @@ message BluetoothSession { CONNECTION_TECHNOLOGY_TYPE_BREDR = 2; } enum DisconnectReasonType { UNKNOWN = 0; // A metrics dump takes a snapshot of current Bluetooth session and thus // is not a real disconnect, but a discontinuation in metrics logging. // This enum indicates this situation. METRICS_DUMP = 1; NEXT_START_WITHOUT_END_PREVIOUS = 2; } // Duration of the session. optional int64 session_duration_sec = 2; Loading @@ -66,7 +92,7 @@ message BluetoothSession { optional ConnectionTechnologyType connection_technology_type = 3; // Reason for disconnecting. optional string disconnect_reason = 4; optional string disconnect_reason = 4 [deprecated = true]; // The information about the device which it is connected to. optional DeviceInfo device_connected_to = 5; Loading @@ -76,6 +102,9 @@ message BluetoothSession { // The information about the A2DP audio session. optional A2DPSession a2dp_session = 7; // Numeric reason for disconnecting as defined in metrics.h optional DisconnectReasonType disconnect_reason_type = 8; } message RFCommSession { Loading
system/osi/src/wakelock.cc +2 −2 Original line number Diff line number Diff line Loading @@ -278,7 +278,7 @@ static void update_wakelock_acquired_stats(bt_status_t acquired_status) { wakelock_stats.last_acquired_timestamp_ms = now_ms; BluetoothMetricsLogger::GetInstance()->LogWakeEvent( system_bt_osi::WAKE_EVENT_ACQUIRED, "", WAKE_LOCK_ID, now_ms); system_bt_osi::WAKE_EVENT_ACQUIRED, "", "", now_ms); } // Loading Loading @@ -320,7 +320,7 @@ static void update_wakelock_released_stats(bt_status_t released_status) { wakelock_stats.total_acquired_interval_ms += delta_ms; BluetoothMetricsLogger::GetInstance()->LogWakeEvent( system_bt_osi::WAKE_EVENT_RELEASED, "", WAKE_LOCK_ID, now_ms); system_bt_osi::WAKE_EVENT_RELEASED, "", "", now_ms); } void wakelock_debug_dump(int fd) { Loading