1 /*
2 * Copyright (C) 2020 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 "src/android_stats/statsd_logging_helper.h"
18
19 #include <string>
20
21 #include "perfetto/base/build_config.h"
22 #include "perfetto/base/compiler.h"
23
24 #if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) && \
25 PERFETTO_BUILDFLAG(PERFETTO_ANDROID_BUILD)
26 #include "src/android_internal/lazy_library_loader.h" // nogncheck
27 #include "src/android_internal/statsd_logging.h" // nogncheck
28 #endif
29
30 namespace perfetto {
31 namespace android_stats {
32
33 // Make sure we don't accidentally log on non-Android tree build. Note that even
34 // removing this ifdef still doesn't make uploads work on OS_ANDROID.
35 // PERFETTO_LAZY_LOAD will return a nullptr on non-Android and non-in-tree
36 // builds as libperfetto_android_internal will not be available.
37 #if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) && \
38 PERFETTO_BUILDFLAG(PERFETTO_ANDROID_BUILD)
39
MaybeLogUploadEvent(PerfettoStatsdAtom atom,int64_t uuid_lsb,int64_t uuid_msb,const std::string & trigger_name)40 void MaybeLogUploadEvent(PerfettoStatsdAtom atom,
41 int64_t uuid_lsb,
42 int64_t uuid_msb,
43 const std::string& trigger_name) {
44 PERFETTO_LAZY_LOAD(android_internal::StatsdLogUploadEvent, log_event_fn);
45 if (log_event_fn) {
46 log_event_fn(atom, uuid_lsb, uuid_msb, trigger_name.c_str());
47 }
48 }
49
MaybeLogTriggerEvent(PerfettoTriggerAtom atom,const std::string & trigger_name)50 void MaybeLogTriggerEvent(PerfettoTriggerAtom atom,
51 const std::string& trigger_name) {
52 PERFETTO_LAZY_LOAD(android_internal::StatsdLogTriggerEvent, log_event_fn);
53 if (log_event_fn) {
54 log_event_fn(atom, trigger_name.c_str());
55 }
56 }
57
MaybeLogTriggerEvents(PerfettoTriggerAtom atom,const std::vector<std::string> & triggers)58 void MaybeLogTriggerEvents(PerfettoTriggerAtom atom,
59 const std::vector<std::string>& triggers) {
60 PERFETTO_LAZY_LOAD(android_internal::StatsdLogTriggerEvent, log_event_fn);
61 if (log_event_fn) {
62 for (const std::string& trigger_name : triggers) {
63 log_event_fn(atom, trigger_name.c_str());
64 }
65 }
66 }
67
68 #else
69 void MaybeLogUploadEvent(PerfettoStatsdAtom,
70 int64_t,
71 int64_t,
72 const std::string&) {}
73 void MaybeLogTriggerEvent(PerfettoTriggerAtom, const std::string&) {}
74 void MaybeLogTriggerEvents(PerfettoTriggerAtom,
75 const std::vector<std::string>&) {}
76 #endif
77
78 } // namespace android_stats
79 } // namespace perfetto
80