Move metrics and time library to libbt-common
* libbt-osi is being deprecated and libbt-common will replace it
* Move recently implemented metrics library to libbt-common
* Move time library from libbt-osi to libbt-common and renamed as time_util
to avoid potention name collision with system time libraries
* Need to keep time library for now because we need to use
CLOCK_BOOTTIME that include system suspension time for A2DP encoding
* Use libchrome logging methods in metrics library
* Put both metrics and time_util into bluetooth::common namespace
* Return uint64_t for time_get_os_boottime_ms and update various
receiver types
* Remove tBTM_CB.max_collision_delay and use the constant
BTM_SEC_MAX_COLLISION_DELAY instead
Bug: 111568640
Test: mm -j40, unit test, stream music
Change-Id: I8c384a810d592bb6b9eb322134e947d066489ba4
diff --git a/common/time_util.cc b/common/time_util.cc
new file mode 100644
index 0000000..273be18
--- /dev/null
+++ b/common/time_util.cc
@@ -0,0 +1,47 @@
+/******************************************************************************
+ *
+ * Copyright 2015 Google, Inc.
+ *
+ * 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 <sys/time.h>
+#include <time.h>
+
+#include "common/time_util.h"
+
+namespace bluetooth {
+
+namespace common {
+
+uint64_t time_get_os_boottime_ms() { return time_get_os_boottime_us() / 1000; }
+
+uint64_t time_get_os_boottime_us() {
+ struct timespec ts_now = {};
+ clock_gettime(CLOCK_BOOTTIME, &ts_now);
+
+ return ((uint64_t)ts_now.tv_sec * 1000000L) +
+ ((uint64_t)ts_now.tv_nsec / 1000);
+}
+
+uint64_t time_gettimeofday_us() {
+ struct timeval tv = {};
+ gettimeofday(&tv, nullptr);
+ return static_cast<uint64_t>(tv.tv_sec) * 1000000ULL +
+ static_cast<uint64_t>(tv.tv_usec);
+}
+
+} // namespace common
+
+} // namespace bluetooth
\ No newline at end of file