• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2016 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #pragma once
20 
21 #include <stdint.h>
22 
23 typedef enum {
24   DEVICE_TYPE_UNKNOWN,
25   DEVICE_TYPE_BREDR,
26   DEVICE_TYPE_LE,
27   DEVICE_TYPE_DUMO,
28 } device_type_t;
29 
30 // Record a pairing event at Unix epoch time |timestamp_ms|
31 // |device_class| and |device_type| denote the type of device paired.
32 // |disconnect_reason| is the HCI reason for pairing disconnection,
33 // see stack/include/hcidefs.h
34 void metrics_pair_event(uint32_t disconnect_reason, uint64_t timestamp_ms,
35                         uint32_t device_class, device_type_t device_type);
36 
37 typedef enum {
38   WAKE_EVENT_UNKNOWN,
39   WAKE_EVENT_ACQUIRED,
40   WAKE_EVENT_RELEASED,
41 } wake_event_type_t;
42 
43 // Record a wake event at Unix epoch time |timestamp_ms|.
44 // |type| specifies whether it was acquired or relased,
45 // |requestor| if provided is the service requesting the wake lock.
46 // |name| is the name of the wake lock held.
47 void metrics_wake_event(wake_event_type_t type, const char *requestor,
48                         const char *name, uint64_t timestamp_ms);
49 
50 typedef enum {
51   SCAN_TYPE_UNKNOWN,
52   SCAN_TECH_TYPE_LE,
53   SCAN_TECH_TYPE_BREDR,
54   SCAN_TECH_TYPE_BOTH,
55 } scan_tech_t;
56 
57 // Record a scan event at Unix epoch time |timestamp_ms|.
58 // |start| is true if this is the beginning of the scan.
59 // |initiator| is a unique ID identifying the app starting the scan.
60 // |type| is whether the scan reports BR/EDR, LE, or both.
61 // |results| is the number of results to be reported.
62 void metrics_scan_event(bool start, const char *initator, scan_tech_t type,
63                         uint32_t results, uint64_t timestamp_ms);
64 
65 // Record A2DP session information.
66 // |session_duration_sec| is the session duration (in seconds).
67 // |device_class| is the device class of the paired device.
68 // |media_timer_min_ms| is the minimum scheduled time (in milliseconds)
69 // of the media timer.
70 // |media_timer_max_ms| is the maximum scheduled time (in milliseconds)
71 // of the media timer.
72 // |media_timer_avg_ms| is the average scheduled time (in milliseconds)
73 // of the media timer.
74 // |buffer_overruns_max_count| - TODO - not clear what this is.
75 // |buffer_overruns_total| is the number of times the media buffer with
76 // audio data has overrun.
77 // |buffer_underruns_average| - TODO - not clear what this is.
78 // |buffer_underruns_count| is the number of times there was no enough
79 // audio data to add to the media buffer.
80 void metrics_a2dp_session(int64_t session_duration_sec,
81                           const char *disconnect_reason,
82                           uint32_t device_class,
83                           int32_t media_timer_min_ms,
84                           int32_t media_timer_max_ms,
85                           int32_t media_timer_avg_ms,
86                           int32_t buffer_overruns_max_count,
87                           int32_t buffer_overruns_total,
88                           float buffer_underruns_average,
89                           int32_t buffer_underruns_count);
90 
91 // Writes the metrics, in packed protobuf format, into the descriptor |fd|.
92 // If |clear| is true, metrics events are cleared afterwards.
93 void metrics_write(int fd, bool clear);
94 
95 // Writes the metrics, in human-readable protobuf format, into the descriptor
96 // |fd|. If |clear| is true, metrics events are cleared afterwards.
97 void metrics_print(int fd, bool clear);
98