Loading system/btif/src/btif_a2dp_source.cc +9 −2 Original line number Diff line number Diff line Loading @@ -895,8 +895,15 @@ static void btif_a2dp_source_audio_tx_stop_event(void) { static void btif_a2dp_source_audio_handle_timer(void) { if (btif_av_is_a2dp_offload_running()) return; #ifndef TARGET_FLOSS uint64_t timestamp_us = bluetooth::common::time_get_os_boottime_us(); log_tstamps_us("A2DP Source tx timer", timestamp_us); uint64_t stats_timestamp_us = timestamp_us; #else uint64_t timestamp_us = bluetooth::common::time_get_os_monotonic_raw_us(); uint64_t stats_timestamp_us = bluetooth::common::time_get_os_boottime_us(); #endif log_tstamps_us("A2DP Source tx scheduling timer", timestamp_us); if (!btif_a2dp_source_cb.media_alarm.IsScheduled()) { LOG_ERROR("%s: ERROR Media task Scheduled after Suspend", __func__); Loading @@ -916,7 +923,7 @@ static void btif_a2dp_source_audio_handle_timer(void) { btif_a2dp_source_cb.encoder_interface->send_frames(timestamp_us); bta_av_ci_src_data_ready(BTA_AV_CHNL_AUDIO); update_scheduling_stats(&btif_a2dp_source_cb.stats.tx_queue_enqueue_stats, timestamp_us, stats_timestamp_us, btif_a2dp_source_cb.encoder_interval_ms * 1000); } Loading system/common/time_util.cc +8 −1 Original line number Diff line number Diff line Loading @@ -42,6 +42,13 @@ uint64_t time_gettimeofday_us() { static_cast<uint64_t>(tv.tv_usec); } uint64_t time_get_os_monotonic_raw_us() { struct timespec ts_now = {}; clock_gettime(CLOCK_MONOTONIC_RAW, &ts_now); return ((uint64_t)ts_now.tv_sec * 1000000L) + ((uint64_t)ts_now.tv_nsec / 1000); } } // namespace common } // namespace bluetooth system/common/time_util.h +2 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ uint64_t time_get_os_boottime_us(); // Get the current wall clock time in microseconds. uint64_t time_gettimeofday_us(); // Get the OS monotonic raw time in microseconds. uint64_t time_get_os_monotonic_raw_us(); } // namespace common } // namespace bluetooth system/common/time_util_unittest.cc +44 −2 Original line number Diff line number Diff line Loading @@ -41,9 +41,18 @@ TEST(TimeTest, test_time_get_os_boottime_us_not_zero) { ASSERT_GT(t1, uint64_t(0)); } // // Test that the return value of // bluetooth::common::time_get_os_monotonic_raw_us() is not zero. // TEST(TimeTest, test_time_get_os_monotonic_raw_us_not_zero) { uint64_t t1 = bluetooth::common::time_get_os_monotonic_raw_us(); ASSERT_GT(t1, uint64_t(0)); } // // Test that the return value of bluetooth::common::time_get_os_boottime_ms() // is monotonically increasing within reasonable boundries. // is monotonically increasing within reasonable boundaries. // TEST(TimeTest, test_time_get_os_boottime_ms_increases_upper_bound) { uint64_t t1 = bluetooth::common::time_get_os_boottime_ms(); Loading @@ -53,7 +62,7 @@ TEST(TimeTest, test_time_get_os_boottime_ms_increases_upper_bound) { // // Test that the return value of bluetooth::common::time_get_os_boottime_us() // is monotonically increasing within reasonable boundries. // is monotonically increasing within reasonable boundaries. // TEST(TimeTest, test_time_get_os_boottime_us_increases_upper_bound) { uint64_t t1 = bluetooth::common::time_get_os_boottime_us(); Loading @@ -61,6 +70,17 @@ TEST(TimeTest, test_time_get_os_boottime_us_increases_upper_bound) { ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000); } // // Test that the return value of // bluetooth::common::time_get_os_monotonic_raw_us() is monotonically increasing // within reasonable boundaries. // TEST(TimeTest, test_time_get_os_monotonic_raw_time_us_increases_upper_bound) { uint64_t t1 = bluetooth::common::time_get_os_monotonic_raw_us(); uint64_t t2 = bluetooth::common::time_get_os_monotonic_raw_us(); ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000); } // // Test that the return value of bluetooth::common::time_get_os_boottime_ms() // is increasing. Loading Loading @@ -104,6 +124,28 @@ TEST(TimeTest, test_time_get_os_boottime_us_increases_lower_bound) { ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000); } // // Test that the return value of // bluetooth::common::time_get_os_monotonic_raw_us() is increasing. // TEST(TimeTest, test_time_get_os_monotonic_raw_us_increases_lower_bound) { static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000; struct timespec delay = {}; delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000); delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000)); // Take two timestamps with sleep in-between uint64_t t1 = bluetooth::common::time_get_os_monotonic_raw_us(); int err = nanosleep(&delay, &delay); uint64_t t2 = bluetooth::common::time_get_os_monotonic_raw_us(); ASSERT_EQ(err, 0); ASSERT_GT(t2, t1); ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US); ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000); } // // Test that the return value of bluetooth::common::time_gettimeofday_us() is // not zero. Loading system/test/mock/mock_common_time_util.cc +4 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,10 @@ uint64_t time_gettimeofday_us() { mock_function_count_map[__func__]++; return 0; } uint64_t time_get_os_monotonic_raw_us() { mock_function_count_map[__func__]++; return 0; } } // namespace common } // namespace bluetooth Loading
system/btif/src/btif_a2dp_source.cc +9 −2 Original line number Diff line number Diff line Loading @@ -895,8 +895,15 @@ static void btif_a2dp_source_audio_tx_stop_event(void) { static void btif_a2dp_source_audio_handle_timer(void) { if (btif_av_is_a2dp_offload_running()) return; #ifndef TARGET_FLOSS uint64_t timestamp_us = bluetooth::common::time_get_os_boottime_us(); log_tstamps_us("A2DP Source tx timer", timestamp_us); uint64_t stats_timestamp_us = timestamp_us; #else uint64_t timestamp_us = bluetooth::common::time_get_os_monotonic_raw_us(); uint64_t stats_timestamp_us = bluetooth::common::time_get_os_boottime_us(); #endif log_tstamps_us("A2DP Source tx scheduling timer", timestamp_us); if (!btif_a2dp_source_cb.media_alarm.IsScheduled()) { LOG_ERROR("%s: ERROR Media task Scheduled after Suspend", __func__); Loading @@ -916,7 +923,7 @@ static void btif_a2dp_source_audio_handle_timer(void) { btif_a2dp_source_cb.encoder_interface->send_frames(timestamp_us); bta_av_ci_src_data_ready(BTA_AV_CHNL_AUDIO); update_scheduling_stats(&btif_a2dp_source_cb.stats.tx_queue_enqueue_stats, timestamp_us, stats_timestamp_us, btif_a2dp_source_cb.encoder_interval_ms * 1000); } Loading
system/common/time_util.cc +8 −1 Original line number Diff line number Diff line Loading @@ -42,6 +42,13 @@ uint64_t time_gettimeofday_us() { static_cast<uint64_t>(tv.tv_usec); } uint64_t time_get_os_monotonic_raw_us() { struct timespec ts_now = {}; clock_gettime(CLOCK_MONOTONIC_RAW, &ts_now); return ((uint64_t)ts_now.tv_sec * 1000000L) + ((uint64_t)ts_now.tv_nsec / 1000); } } // namespace common } // namespace bluetooth
system/common/time_util.h +2 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ uint64_t time_get_os_boottime_us(); // Get the current wall clock time in microseconds. uint64_t time_gettimeofday_us(); // Get the OS monotonic raw time in microseconds. uint64_t time_get_os_monotonic_raw_us(); } // namespace common } // namespace bluetooth
system/common/time_util_unittest.cc +44 −2 Original line number Diff line number Diff line Loading @@ -41,9 +41,18 @@ TEST(TimeTest, test_time_get_os_boottime_us_not_zero) { ASSERT_GT(t1, uint64_t(0)); } // // Test that the return value of // bluetooth::common::time_get_os_monotonic_raw_us() is not zero. // TEST(TimeTest, test_time_get_os_monotonic_raw_us_not_zero) { uint64_t t1 = bluetooth::common::time_get_os_monotonic_raw_us(); ASSERT_GT(t1, uint64_t(0)); } // // Test that the return value of bluetooth::common::time_get_os_boottime_ms() // is monotonically increasing within reasonable boundries. // is monotonically increasing within reasonable boundaries. // TEST(TimeTest, test_time_get_os_boottime_ms_increases_upper_bound) { uint64_t t1 = bluetooth::common::time_get_os_boottime_ms(); Loading @@ -53,7 +62,7 @@ TEST(TimeTest, test_time_get_os_boottime_ms_increases_upper_bound) { // // Test that the return value of bluetooth::common::time_get_os_boottime_us() // is monotonically increasing within reasonable boundries. // is monotonically increasing within reasonable boundaries. // TEST(TimeTest, test_time_get_os_boottime_us_increases_upper_bound) { uint64_t t1 = bluetooth::common::time_get_os_boottime_us(); Loading @@ -61,6 +70,17 @@ TEST(TimeTest, test_time_get_os_boottime_us_increases_upper_bound) { ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000); } // // Test that the return value of // bluetooth::common::time_get_os_monotonic_raw_us() is monotonically increasing // within reasonable boundaries. // TEST(TimeTest, test_time_get_os_monotonic_raw_time_us_increases_upper_bound) { uint64_t t1 = bluetooth::common::time_get_os_monotonic_raw_us(); uint64_t t2 = bluetooth::common::time_get_os_monotonic_raw_us(); ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000); } // // Test that the return value of bluetooth::common::time_get_os_boottime_ms() // is increasing. Loading Loading @@ -104,6 +124,28 @@ TEST(TimeTest, test_time_get_os_boottime_us_increases_lower_bound) { ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000); } // // Test that the return value of // bluetooth::common::time_get_os_monotonic_raw_us() is increasing. // TEST(TimeTest, test_time_get_os_monotonic_raw_us_increases_lower_bound) { static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000; struct timespec delay = {}; delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000); delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000)); // Take two timestamps with sleep in-between uint64_t t1 = bluetooth::common::time_get_os_monotonic_raw_us(); int err = nanosleep(&delay, &delay); uint64_t t2 = bluetooth::common::time_get_os_monotonic_raw_us(); ASSERT_EQ(err, 0); ASSERT_GT(t2, t1); ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US); ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000); } // // Test that the return value of bluetooth::common::time_gettimeofday_us() is // not zero. Loading
system/test/mock/mock_common_time_util.cc +4 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,10 @@ uint64_t time_gettimeofday_us() { mock_function_count_map[__func__]++; return 0; } uint64_t time_get_os_monotonic_raw_us() { mock_function_count_map[__func__]++; return 0; } } // namespace common } // namespace bluetooth