Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 1 | /* |
| 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 Shih | 2e15aed | 2021-03-16 18:30:35 -0700 | [diff] [blame] | 30 | #include <map> |
Andy Hung | 82a074b | 2019-12-03 14:16:45 -0800 | [diff] [blame] | 31 | #include <memory> |
Robert Shih | 2e15aed | 2021-03-16 18:30:35 -0700 | [diff] [blame] | 32 | #include <string> |
| 33 | #include <vector> |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 34 | #include <string.h> |
| 35 | #include <pwd.h> |
| 36 | |
Ray Essick | 40e8e5e | 2019-12-05 20:19:40 -0800 | [diff] [blame] | 37 | #include "MediaMetricsService.h" |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 38 | #include "iface_statsd.h" |
| 39 | |
| 40 | #include <statslog.h> |
| 41 | |
| 42 | namespace android { |
| 43 | |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 44 | // set of routines that crack a mediametrics::Item |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 45 | // and send it off to statsd with the appropriate hooks |
| 46 | // |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 47 | // each mediametrics::Item type (extractor, codec, nuplayer, etc) |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 48 | // has its own routine to handle this. |
| 49 | // |
| 50 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame^] | 51 | static bool enabled_statsd = true; |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 52 | |
Robert Shih | 2e15aed | 2021-03-16 18:30:35 -0700 | [diff] [blame] | 53 | namespace { |
| 54 | template<typename Handler, typename... Args> |
| 55 | bool dump2StatsdInternal(const std::map<std::string, Handler>& handlers, |
| 56 | const std::shared_ptr<const mediametrics::Item>& item, Args... args) { |
Andy Hung | 3ab1b32 | 2020-05-18 10:47:31 -0700 | [diff] [blame] | 57 | if (item == nullptr) return false; |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 58 | |
| 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 Shih | 2e15aed | 2021-03-16 18:30:35 -0700 | [diff] [blame] | 67 | if (handlers.count(key)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame^] | 68 | return (handlers.at(key))(item, args...); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 69 | } |
| 70 | return false; |
| 71 | } |
Robert Shih | 2e15aed | 2021-03-16 18:30:35 -0700 | [diff] [blame] | 72 | } // namespace |
| 73 | |
| 74 | // give me a record, I'll look at the type and upload appropriately |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame^] | 75 | bool 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 Shih | 2e15aed | 2021-03-16 18:30:35 -0700 | [diff] [blame] | 79 | { |
| 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 Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame^] | 93 | return dump2StatsdInternal(statsd_pushers, item, statsdLog); |
Robert Shih | 2e15aed | 2021-03-16 18:30:35 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item, AStatsEventList* out) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame^] | 97 | static const std::map<std::string, statsd_puller*> statsd_pullers = |
Robert Shih | 2e15aed | 2021-03-16 18:30:35 -0700 | [diff] [blame] | 98 | { |
| 99 | { "mediadrm", statsd_mediadrm_puller }, |
| 100 | }; |
| 101 | return dump2StatsdInternal(statsd_pullers, item, out); |
| 102 | } |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 103 | |
| 104 | } // namespace android |