blob: 3efaa850a9219b49da5c1332b1262535f45bf884 [file] [log] [blame]
Yangster13fb7e42018-03-07 17:30:49 -08001// Copyright (C) 2017 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"
18#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
19#include "src/StatsLogProcessor.h"
20#include "src/logd/LogEvent.h"
tsaichristine8dca82e2020-04-07 09:40:03 -070021#include "stats_event.h"
Yangster13fb7e42018-03-07 17:30:49 -080022#include "statslog.h"
23
24namespace android {
25namespace os {
26namespace statsd {
27
28// Create AtomMatcher proto to simply match a specific atom type.
29AtomMatcher CreateSimpleAtomMatcher(const string& name, int atomId);
30
31// Create AtomMatcher proto for scheduled job state changed.
32AtomMatcher CreateScheduledJobStateChangedAtomMatcher();
33
34// Create AtomMatcher proto for starting a scheduled job.
35AtomMatcher CreateStartScheduledJobAtomMatcher();
36
37// Create AtomMatcher proto for a scheduled job is done.
38AtomMatcher CreateFinishScheduledJobAtomMatcher();
39
40// Create AtomMatcher proto for screen brightness state changed.
41AtomMatcher CreateScreenBrightnessChangedAtomMatcher();
42
43// Create AtomMatcher proto for acquiring wakelock.
44AtomMatcher CreateAcquireWakelockAtomMatcher();
45
46// Create AtomMatcher proto for releasing wakelock.
47AtomMatcher CreateReleaseWakelockAtomMatcher() ;
48
49// Create AtomMatcher proto for screen turned on.
50AtomMatcher CreateScreenTurnedOnAtomMatcher();
51
52// Create AtomMatcher proto for screen turned off.
53AtomMatcher CreateScreenTurnedOffAtomMatcher();
54
55// Create AtomMatcher proto for app sync turned on.
56AtomMatcher CreateSyncStartAtomMatcher();
57
58// Create AtomMatcher proto for app sync turned off.
59AtomMatcher CreateSyncEndAtomMatcher();
60
61// Create AtomMatcher proto for app sync moves to background.
62AtomMatcher CreateMoveToBackgroundAtomMatcher();
63
64// Create AtomMatcher proto for app sync moves to foreground.
65AtomMatcher CreateMoveToForegroundAtomMatcher();
66
67// Create Predicate proto for screen is off.
68Predicate CreateScreenIsOffPredicate();
69
70// Create Predicate proto for a running scheduled job.
71Predicate CreateScheduledJobPredicate();
72
73// Create Predicate proto for holding wakelock.
74Predicate CreateHoldingWakelockPredicate();
75
76// Create a Predicate proto for app syncing.
77Predicate CreateIsSyncingPredicate();
78
79// Create a Predicate proto for app is in background.
80Predicate CreateIsInBackgroundPredicate();
81
82// Add a predicate to the predicate combination.
83void addPredicateToPredicateCombination(const Predicate& predicate, Predicate* combination);
84
85// Create dimensions from primitive fields.
86FieldMatcher CreateDimensions(const int atomId, const std::vector<int>& fields);
87
88// Create dimensions by attribution uid and tag.
89FieldMatcher CreateAttributionUidAndTagDimensions(const int atomId,
90 const std::vector<Position>& positions);
91
92// Create dimensions by attribution uid only.
93FieldMatcher CreateAttributionUidDimensions(const int atomId,
94 const std::vector<Position>& positions);
95
tsaichristine8dca82e2020-04-07 09:40:03 -070096void writeAttribution(AStatsEvent* statsEvent, const vector<int>& attributionUids,
97 const vector<string>& attributionTags);
98
99void parseStatsEventToLogEvent(AStatsEvent* statsEvent, LogEvent* logEvent);
100
Yangster13fb7e42018-03-07 17:30:49 -0800101// Create log event for screen state changed.
102std::unique_ptr<LogEvent> CreateScreenStateChangedEvent(
tsaichristine63143252020-03-20 17:03:49 -0700103 uint64_t timestampNs, const android::view::DisplayStateEnum state);
Yangster13fb7e42018-03-07 17:30:49 -0800104
105// Create log event when scheduled job starts.
tsaichristine63143252020-03-20 17:03:49 -0700106std::unique_ptr<LogEvent> CreateStartScheduledJobEvent(uint64_t timestampNs,
107 const vector<int>& attributionUids,
108 const vector<string>& attributionTags,
109 const string& jobName);
Yangster13fb7e42018-03-07 17:30:49 -0800110
111// Create log event when scheduled job finishes.
tsaichristine63143252020-03-20 17:03:49 -0700112std::unique_ptr<LogEvent> CreateFinishScheduledJobEvent(uint64_t timestampNs,
113 const vector<int>& attributionUids,
114 const vector<string>& attributionTags,
115 const string& jobName);
Yangster13fb7e42018-03-07 17:30:49 -0800116
117// Create log event when the app sync starts.
tsaichristine63143252020-03-20 17:03:49 -0700118std::unique_ptr<LogEvent> CreateSyncStartEvent(uint64_t timestampNs,
119 const vector<int>& attributionUids,
120 const vector<string>& attributionTags,
121 const string& name);
Yangster13fb7e42018-03-07 17:30:49 -0800122
123// Create log event when the app sync ends.
tsaichristine63143252020-03-20 17:03:49 -0700124std::unique_ptr<LogEvent> CreateSyncEndEvent(uint64_t timestampNs,
125 const vector<int>& attributionUids,
126 const vector<string>& attributionTags,
127 const string& name);
Yangster13fb7e42018-03-07 17:30:49 -0800128
Yangster13fb7e42018-03-07 17:30:49 -0800129// Create a statsd log event processor upon the start time in seconds, config and key.
130sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const StatsdConfig& config,
131 const ConfigKey& key);
132
133// Util function to sort the log events by timestamp.
134void sortLogEventsByTimestamp(std::vector<std::unique_ptr<LogEvent>> *events);
135
136int64_t StringToId(const string& str);
137
138} // namespace statsd
139} // namespace os
tsaichristine63143252020-03-20 17:03:49 -0700140} // namespace android