blob: df421849cc5247beda4baf08f8f10258e3d6b657 [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
Robert Shih2e15aed2021-03-16 18:30:35 -070030#include <map>
Andy Hung82a074b2019-12-03 14:16:45 -080031#include <memory>
Robert Shih2e15aed2021-03-16 18:30:35 -070032#include <string>
33#include <vector>
Ray Essick6ce27e52019-02-15 10:58:05 -080034#include <string.h>
35#include <pwd.h>
36
Ray Essick40e8e5e2019-12-05 20:19:40 -080037#include "MediaMetricsService.h"
Ray Essick6ce27e52019-02-15 10:58:05 -080038#include "iface_statsd.h"
39
40#include <statslog.h>
41
42namespace android {
43
Ray Essickf27e9872019-12-07 06:28:46 -080044// set of routines that crack a mediametrics::Item
Ray Essick6ce27e52019-02-15 10:58:05 -080045// and send it off to statsd with the appropriate hooks
46//
Ray Essickf27e9872019-12-07 06:28:46 -080047// each mediametrics::Item type (extractor, codec, nuplayer, etc)
Ray Essick6ce27e52019-02-15 10:58:05 -080048// has its own routine to handle this.
49//
50
Andy Hung5be90c82021-03-30 14:30:20 -070051static bool enabled_statsd = true;
Ray Essick6ce27e52019-02-15 10:58:05 -080052
Robert Shih2e15aed2021-03-16 18:30:35 -070053namespace {
54template<typename Handler, typename... Args>
55bool dump2StatsdInternal(const std::map<std::string, Handler>& handlers,
56 const std::shared_ptr<const mediametrics::Item>& item, Args... args) {
Andy Hung3ab1b322020-05-18 10:47:31 -070057 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -080058
59 // get the key
60 std::string key = item->getKey();
61
62 if (!enabled_statsd) {
63 ALOGV("statsd logging disabled for record key=%s", key.c_str());
64 return false;
65 }
66
Robert Shih2e15aed2021-03-16 18:30:35 -070067 if (handlers.count(key)) {
Andy Hung5be90c82021-03-30 14:30:20 -070068 return (handlers.at(key))(item, args...);
Ray Essick6ce27e52019-02-15 10:58:05 -080069 }
70 return false;
71}
Robert Shih2e15aed2021-03-16 18:30:35 -070072} // namespace
73
74// give me a record, I'll look at the type and upload appropriately
Andy Hung5be90c82021-03-30 14:30:20 -070075bool dump2Statsd(
76 const std::shared_ptr<const mediametrics::Item>& item,
77 const std::shared_ptr<mediametrics::StatsdLog>& statsdLog) {
78 static const std::map<std::string, statsd_pusher*> statsd_pushers =
Robert Shih2e15aed2021-03-16 18:30:35 -070079 {
80 { "audiopolicy", statsd_audiopolicy },
81 { "audiorecord", statsd_audiorecord },
82 { "audiothread", statsd_audiothread },
83 { "audiotrack", statsd_audiotrack },
84 { "codec", statsd_codec},
85 { "drmmanager", statsd_drmmanager },
86 { "extractor", statsd_extractor },
87 { "mediadrm", statsd_mediadrm },
88 { "mediaparser", statsd_mediaparser },
89 { "nuplayer", statsd_nuplayer },
90 { "nuplayer2", statsd_nuplayer },
91 { "recorder", statsd_recorder },
92 };
Andy Hung5be90c82021-03-30 14:30:20 -070093 return dump2StatsdInternal(statsd_pushers, item, statsdLog);
Robert Shih2e15aed2021-03-16 18:30:35 -070094}
95
96bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item, AStatsEventList* out) {
Andy Hung5be90c82021-03-30 14:30:20 -070097 static const std::map<std::string, statsd_puller*> statsd_pullers =
Robert Shih2e15aed2021-03-16 18:30:35 -070098 {
99 { "mediadrm", statsd_mediadrm_puller },
100 };
101 return dump2StatsdInternal(statsd_pullers, item, out);
102}
Ray Essick6ce27e52019-02-15 10:58:05 -0800103
104} // namespace android