blob: b179b20f3ae298eb683a1ae261ad60fd023cf3a3 [file] [log] [blame]
Andy Hung224f82f2022-03-22 00:00:49 -07001/*
2 * Copyright (C) 2022 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#include <mediautils/MethodStatistics.h>
18
19namespace android::mediautils {
20
21// Repository for MethodStatistics Objects
22
23std::shared_ptr<std::vector<std::string>>
24getStatisticsClassesForModule(std::string_view moduleName) {
25 static const std::map<std::string, std::shared_ptr<std::vector<std::string>>> m {
26 {
27 METHOD_STATISTICS_MODULE_NAME_AUDIO_HIDL,
28 std::shared_ptr<std::vector<std::string>>(
29 new std::vector<std::string>{
30 "DeviceHalHidl",
Andy Hung2924a292022-04-04 22:14:57 -070031 "EffectHalHidl",
Andy Hung224f82f2022-03-22 00:00:49 -070032 "StreamInHalHidl",
33 "StreamOutHalHidl",
34 })
35 },
36 };
37 auto it = m.find({moduleName.begin(), moduleName.end()});
38 if (it == m.end()) return {};
39 return it->second;
40}
41
42static void addClassesToMap(const std::shared_ptr<std::vector<std::string>> &classNames,
43 std::map<std::string, std::shared_ptr<MethodStatistics<std::string>>> &map) {
44 if (classNames) {
45 for (const auto& className : *classNames) {
46 map.emplace(className, std::make_shared<MethodStatistics<std::string>>());
47 }
48 }
49}
50
51// singleton statistics for DeviceHalHidl StreamOutHalHidl StreamInHalHidl
52std::shared_ptr<MethodStatistics<std::string>>
53getStatisticsForClass(std::string_view className) {
54 static const std::map<std::string, std::shared_ptr<MethodStatistics<std::string>>> m =
55 // copy elided initialization of map m.
56 [](){
57 std::map<std::string, std::shared_ptr<MethodStatistics<std::string>>> m;
58 addClassesToMap(
59 getStatisticsClassesForModule(METHOD_STATISTICS_MODULE_NAME_AUDIO_HIDL),
60 m);
61 return m;
62 }();
63
64 auto it = m.find({className.begin(), className.end()});
65 if (it == m.end()) return {};
66 return it->second;
67}
68
69} // android::mediautils