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 | |
| 30 | #include <string.h> |
| 31 | #include <pwd.h> |
| 32 | |
| 33 | #include "MediaAnalyticsService.h" |
| 34 | #include "iface_statsd.h" |
| 35 | |
| 36 | #include <statslog.h> |
| 37 | |
| 38 | namespace 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 | |
| 47 | bool enabled_statsd = true; |
| 48 | |
| 49 | struct statsd_hooks { |
| 50 | const char *key; |
| 51 | bool (*handler)(MediaAnalyticsItem *); |
| 52 | }; |
| 53 | |
| 54 | // keep this sorted, so we can do binary searches |
| 55 | struct statsd_hooks statsd_handlers[] = |
| 56 | { |
| 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 Shih | addf5ee | 2019-08-19 14:11:13 -0700 | [diff] [blame^] | 63 | { "drmmanager", statsd_drmmanager }, |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 64 | { "extractor", statsd_extractor }, |
| 65 | { "mediadrm", statsd_mediadrm }, |
| 66 | { "nuplayer", statsd_nuplayer }, |
| 67 | { "nuplayer2", statsd_nuplayer }, |
| 68 | { "recorder", statsd_recorder }, |
| 69 | }; |
| 70 | |
| 71 | |
| 72 | // give me a record, i'll look at the type and upload appropriately |
| 73 | bool dump2Statsd(MediaAnalyticsItem *item) { |
| 74 | if (item == NULL) return false; |
| 75 | |
| 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 | |
| 84 | int i; |
| 85 | for(i = 0;i < sizeof(statsd_handlers) / sizeof(statsd_handlers[0]) ; i++) { |
| 86 | if (key == statsd_handlers[i].key) { |
| 87 | return (*statsd_handlers[i].handler)(item); |
| 88 | } |
| 89 | } |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | } // namespace android |