Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49832d8b authored by Marie Janssen's avatar Marie Janssen
Browse files

osi: add metrics API

Add a metrics API, which supports creating events which are eventually
passed up to the clearcut logging to track pairings and other events.

Connect this to the dumpsys call when it is called.

Change-Id: Idcf75541fd18b0413cc843d6c7e23a5f08a634a5
parent 47fbdbde
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@
#include "osi/include/allocation_tracker.h"
#include "osi/include/alarm.h"
#include "osi/include/log.h"
#include "osi/include/metrics.h"
#include "osi/include/osi.h"
#include "osi/include/wakelock.h"
#include "stack_manager.h"
@@ -323,8 +324,18 @@ static int read_energy_info()
    return BT_STATUS_SUCCESS;
}

static void dump(int fd, UNUSED_ATTR const char **arguments)
static void dump(int fd, const char **arguments)
{
    if (arguments != NULL && arguments[0] != NULL) {
      if (strncmp(arguments[0], "--proto-text", 11) == 0) {
        metrics_print(fd, true);
        return;
      }
      if (strncmp(arguments[0], "--proto-bin", 10) == 0) {
        metrics_write(fd, true);
        return;
      }
    }
    btif_debug_conn_dump(fd);
    btif_debug_a2dp_dump(fd);
    wakelock_debug_dump(fd);
+2 −2
Original line number Diff line number Diff line
@@ -67,8 +67,8 @@ LOCAL_SRC_FILES := \
LOCAL_CFLAGS := -Wall -Werror $(bdroid_CFLAGS)
LOCAL_MODULE := net_test_hci
LOCAL_MODULE_TAGS := tests
LOCAL_SHARED_LIBRARIES := liblog libdl
LOCAL_STATIC_LIBRARIES := libbt-hci libosi libcutils libbtcore
LOCAL_SHARED_LIBRARIES := liblog libdl libprotobuf-cpp-full
LOCAL_STATIC_LIBRARIES := libbt-hci libosi libcutils libbtcore libbt-protos

include $(BUILD_NATIVE_TEST)
endif # SANITIZE_TARGET
+2 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ LOCAL_SHARED_LIBRARIES := \
    liblog \
    libz \
    libpower \
    libprotobuf-cpp-full \
    libmedia \
    libutils

@@ -88,6 +89,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES := \
    libbtdevice \
    libbtif \
    libbt-hci \
    libbt-protos \
    libbt-stack \
    libbt-utils \
    libbtcore \
+28 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ btosiCommonSrc := \
    ./src/hash_map.c \
    ./src/hash_map_utils.c \
    ./src/list.c \
    ./src/metrics.cpp \
    ./src/mutex.c \
    ./src/reactor.c \
    ./src/ringbuffer.c \
@@ -79,6 +80,27 @@ btosiCommonIncludes := \
btosiCommonCFlags := -std=c99 -Wall -Werror -UNDEBUG -fvisibility=hidden \
    $(bdroid_CFLAGS)


# protobuf library for bluetooth
# ========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libbt-protos
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
generated_sources_dir := $(call local-generated-sources-dir)
LOCAL_EXPORT_C_INCLUDE_DIRS += \
    $(generated_sources_dir)/proto/packages/modules/Bluetooth/system
LOCAL_SRC_FILES := $(call all-proto-files-under,src/protos/)
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libbt-protos
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
generated_sources_dir := $(call local-generated-sources-dir)
LOCAL_EXPORT_C_INCLUDE_DIRS += \
    $(generated_sources_dir)/proto/packages/modules/Bluetooth/system
LOCAL_SRC_FILES := $(call all-proto-files-under,src/protos/)
include $(BUILD_HOST_STATIC_LIBRARY)

# libosi static library for target
# ========================================================
include $(CLEAR_VARS)
@@ -90,6 +112,7 @@ LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
LOCAL_MODULE := libosi
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libc liblog
LOCAL_STATIC_LIBRARIES := libbt-protos
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
include $(BUILD_STATIC_LIBRARY)

@@ -110,6 +133,7 @@ LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
LOCAL_MODULE := libosi-host
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_STATIC_LIBRARIES := libbt-protos
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
include $(BUILD_HOST_STATIC_LIBRARY)
endif
@@ -125,8 +149,8 @@ LOCAL_SRC_FILES := $(btosiCommonTestSrc)
LOCAL_CFLAGS := -Wall -UNDEBUG
LOCAL_MODULE := net_test_osi
LOCAL_MODULE_TAGS := tests
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_STATIC_LIBRARIES := libosi
LOCAL_SHARED_LIBRARIES := liblog libprotobuf-cpp-full
LOCAL_STATIC_LIBRARIES := libosi libbt-protos
include $(BUILD_NATIVE_TEST)

# libosi unit tests for host
@@ -139,7 +163,7 @@ LOCAL_CFLAGS := -Wall -UNDEBUG
LOCAL_LDLIBS := -lrt -lpthread
LOCAL_MODULE := net_test_osi
LOCAL_MODULE_TAGS := tests
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_STATIC_LIBRARIES := libosi-host
LOCAL_SHARED_LIBRARIES := liblog libprotobuf-cpp-full
LOCAL_STATIC_LIBRARIES := libosi-host libbt-protos
include $(BUILD_HOST_NATIVE_TEST)
endif
+71 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2016 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.
 *
 ******************************************************************************/

#pragma once

#include <stdint.h>

typedef enum {
  DEVICE_TYPE_UNKNOWN,
  DEVICE_TYPE_BREDR,
  DEVICE_TYPE_LE,
  DEVICE_TYPE_DUMO,
} device_type_t;

// Record a pairing event at Unix epoch time |timestamp_ms|
// |device_class| and |device_type| denote the type of device paired.
// |disconnect_reason| is the HCI reason for pairing disconnection,
// see stack/include/hcidefs.h
void metrics_pair_event(uint32_t disconnect_reason, uint64_t timestamp_ms,
                        uint32_t device_class, device_type_t device_type);

typedef enum {
  WAKE_EVENT_UNKNOWN,
  WAKE_EVENT_ACQUIRED,
  WAKE_EVENT_RELEASED,
} wake_event_type_t;

// Record a wake event at Unix epoch time |timestamp_ms|.
// |type| specifies whether it was acquired or relased,
// |requestor| if provided is the service requesting the wake lock.
// |name| is the name of the wake lock held.
void metrics_wake_event(wake_event_type_t type, const char *requestor,
                        const char *name, uint64_t timestamp_ms);

typedef enum {
  SCAN_TYPE_UNKNOWN,
  SCAN_TECH_TYPE_LE,
  SCAN_TECH_TYPE_BREDR,
  SCAN_TECH_TYPE_BOTH,
} scan_tech_t;

// Record a scan event at Unix epoch time |timestamp_ms|.
// |start| is true if this is the beginning of the scan.
// |initiator| is a unique ID identifying the app starting the scan.
// |type| is whether the scan reports BR/EDR, LE, or both.
// |results| is the number of results to be reported.
void metrics_scan_event(bool start, const char *initator, scan_tech_t type,
                        uint32_t results, uint64_t timestamp_ms);

// Writes the metrics, in packed protobuf format, into the descriptor |fd|.
// If |clear| is true, metrics events are cleared afterwards.
void metrics_write(int fd, bool clear);

// Writes the metrics, in human-readable protobuf format, into the descriptor
// |fd|. If |clear| is true, metrics events are cleared afterwards.
void metrics_print(int fd, bool clear);
Loading