blob: 6e51f7222ea8412dcb9a1a348443c9ec7037ee14 [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
Andy Hung82a074b2019-12-03 14:16:45 -080030#include <memory>
Ray Essick6ce27e52019-02-15 10:58:05 -080031#include <string.h>
32#include <pwd.h>
33
Ray Essick40e8e5e2019-12-05 20:19:40 -080034#include "MediaMetricsService.h"
Ray Essick6ce27e52019-02-15 10:58:05 -080035#include "iface_statsd.h"
36
37#include <statslog.h>
38
39namespace android {
40
Ray Essickf27e9872019-12-07 06:28:46 -080041// set of routines that crack a mediametrics::Item
Ray Essick6ce27e52019-02-15 10:58:05 -080042// and send it off to statsd with the appropriate hooks
43//
Ray Essickf27e9872019-12-07 06:28:46 -080044// each mediametrics::Item type (extractor, codec, nuplayer, etc)
Ray Essick6ce27e52019-02-15 10:58:05 -080045// has its own routine to handle this.
46//
47
48bool enabled_statsd = true;
49
50struct statsd_hooks {
51 const char *key;
Ray Essickf27e9872019-12-07 06:28:46 -080052 bool (*handler)(const mediametrics::Item *);
Ray Essick6ce27e52019-02-15 10:58:05 -080053};
54
55// keep this sorted, so we can do binary searches
Andy Hung17dbaf22019-10-11 14:06:31 -070056static constexpr struct statsd_hooks statsd_handlers[] =
Ray Essick6ce27e52019-02-15 10:58:05 -080057{
58 { "audiopolicy", statsd_audiopolicy },
59 { "audiorecord", statsd_audiorecord },
60 { "audiothread", statsd_audiothread },
61 { "audiotrack", statsd_audiotrack },
62 { "codec", statsd_codec},
63 { "drm.vendor.Google.WidevineCDM", statsd_widevineCDM },
Robert Shihaddf5ee2019-08-19 14:11:13 -070064 { "drmmanager", statsd_drmmanager },
Ray Essick6ce27e52019-02-15 10:58:05 -080065 { "extractor", statsd_extractor },
66 { "mediadrm", statsd_mediadrm },
67 { "nuplayer", statsd_nuplayer },
68 { "nuplayer2", statsd_nuplayer },
69 { "recorder", statsd_recorder },
70};
71
Ray Essick6ce27e52019-02-15 10:58:05 -080072// give me a record, i'll look at the type and upload appropriately
Ray Essickf27e9872019-12-07 06:28:46 -080073bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item) {
Andy Hung3ab1b322020-05-18 10:47:31 -070074 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -080075
76 // get the key
77 std::string key = item->getKey();
78
79 if (!enabled_statsd) {
80 ALOGV("statsd logging disabled for record key=%s", key.c_str());
81 return false;
82 }
83
Andy Hung17dbaf22019-10-11 14:06:31 -070084 for (const auto &statsd_handler : statsd_handlers) {
85 if (key == statsd_handler.key) {
Andy Hung82a074b2019-12-03 14:16:45 -080086 return statsd_handler.handler(item.get());
Ray Essick6ce27e52019-02-15 10:58:05 -080087 }
88 }
89 return false;
90}
91
92} // namespace android