blob: e02c9cf43a8ee7ce46318710a1c96700adee6184 [file] [log] [blame]
Ray Essick6ce27e52019-02-15 10:58:05 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "iface_statsd"
19#include <utils/Log.h>
20
21#include <stdint.h>
22#include <inttypes.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <sys/time.h>
26#include <dirent.h>
27#include <pthread.h>
28#include <unistd.h>
29
30#include <string.h>
31#include <pwd.h>
32
33#include "MediaAnalyticsService.h"
34#include "iface_statsd.h"
35
36#include <statslog.h>
37
38namespace android {
39
40// set of routines that crack a MediaAnalyticsItem
41// and send it off to statsd with the appropriate hooks
42//
43// each MediaAnalyticsItem type (extractor, codec, nuplayer, etc)
44// has its own routine to handle this.
45//
46
47bool enabled_statsd = true;
48
49struct statsd_hooks {
50 const char *key;
51 bool (*handler)(MediaAnalyticsItem *);
52};
53
54// keep this sorted, so we can do binary searches
Andy Hung17dbaf22019-10-11 14:06:31 -070055static constexpr struct statsd_hooks statsd_handlers[] =
Ray Essick6ce27e52019-02-15 10:58:05 -080056{
57 { "audiopolicy", statsd_audiopolicy },
58 { "audiorecord", statsd_audiorecord },
59 { "audiothread", statsd_audiothread },
60 { "audiotrack", statsd_audiotrack },
61 { "codec", statsd_codec},
62 { "drm.vendor.Google.WidevineCDM", statsd_widevineCDM },
Robert Shihaddf5ee2019-08-19 14:11:13 -070063 { "drmmanager", statsd_drmmanager },
Ray Essick6ce27e52019-02-15 10:58:05 -080064 { "extractor", statsd_extractor },
65 { "mediadrm", statsd_mediadrm },
66 { "nuplayer", statsd_nuplayer },
67 { "nuplayer2", statsd_nuplayer },
68 { "recorder", statsd_recorder },
69};
70
Ray Essick6ce27e52019-02-15 10:58:05 -080071// give me a record, i'll look at the type and upload appropriately
72bool dump2Statsd(MediaAnalyticsItem *item) {
73 if (item == NULL) return false;
74
75 // get the key
76 std::string key = item->getKey();
77
78 if (!enabled_statsd) {
79 ALOGV("statsd logging disabled for record key=%s", key.c_str());
80 return false;
81 }
82
Andy Hung17dbaf22019-10-11 14:06:31 -070083 for (const auto &statsd_handler : statsd_handlers) {
84 if (key == statsd_handler.key) {
85 return statsd_handler.handler(item);
Ray Essick6ce27e52019-02-15 10:58:05 -080086 }
87 }
88 return false;
89}
90
91} // namespace android