blob: 16204deef09baf86be50bdf3cc972d01e73a1d42 [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 },
Santiago Seifert71b5dbf2020-08-11 17:58:41 +010067 { "mediaparser", statsd_mediaparser },
Ray Essick6ce27e52019-02-15 10:58:05 -080068 { "nuplayer", statsd_nuplayer },
69 { "nuplayer2", statsd_nuplayer },
70 { "recorder", statsd_recorder },
71};
72
Ray Essick6ce27e52019-02-15 10:58:05 -080073// give me a record, i'll look at the type and upload appropriately
Ray Essickf27e9872019-12-07 06:28:46 -080074bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item) {
Andy Hung3ab1b322020-05-18 10:47:31 -070075 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -080076
77 // get the key
78 std::string key = item->getKey();
79
80 if (!enabled_statsd) {
81 ALOGV("statsd logging disabled for record key=%s", key.c_str());
82 return false;
83 }
84
Andy Hung17dbaf22019-10-11 14:06:31 -070085 for (const auto &statsd_handler : statsd_handlers) {
86 if (key == statsd_handler.key) {
Andy Hung82a074b2019-12-03 14:16:45 -080087 return statsd_handler.handler(item.get());
Ray Essick6ce27e52019-02-15 10:58:05 -080088 }
89 }
90 return false;
91}
92
93} // namespace android