blob: 9b28d60b38c07a0f7c282066ff129a884cef27a0 [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"
21#include "statslog.h"
22
23namespace android {
24namespace os {
25namespace statsd {
26
27// Create AtomMatcher proto to simply match a specific atom type.
28AtomMatcher CreateSimpleAtomMatcher(const string& name, int atomId);
29
30// Create AtomMatcher proto for scheduled job state changed.
31AtomMatcher CreateScheduledJobStateChangedAtomMatcher();
32
33// Create AtomMatcher proto for starting a scheduled job.
34AtomMatcher CreateStartScheduledJobAtomMatcher();
35
36// Create AtomMatcher proto for a scheduled job is done.
37AtomMatcher CreateFinishScheduledJobAtomMatcher();
38
39// Create AtomMatcher proto for screen brightness state changed.
40AtomMatcher CreateScreenBrightnessChangedAtomMatcher();
41
42// Create AtomMatcher proto for acquiring wakelock.
43AtomMatcher CreateAcquireWakelockAtomMatcher();
44
45// Create AtomMatcher proto for releasing wakelock.
46AtomMatcher CreateReleaseWakelockAtomMatcher() ;
47
48// Create AtomMatcher proto for screen turned on.
49AtomMatcher CreateScreenTurnedOnAtomMatcher();
50
51// Create AtomMatcher proto for screen turned off.
52AtomMatcher CreateScreenTurnedOffAtomMatcher();
53
54// Create AtomMatcher proto for app sync turned on.
55AtomMatcher CreateSyncStartAtomMatcher();
56
57// Create AtomMatcher proto for app sync turned off.
58AtomMatcher CreateSyncEndAtomMatcher();
59
60// Create AtomMatcher proto for app sync moves to background.
61AtomMatcher CreateMoveToBackgroundAtomMatcher();
62
63// Create AtomMatcher proto for app sync moves to foreground.
64AtomMatcher CreateMoveToForegroundAtomMatcher();
65
66// Create Predicate proto for screen is off.
67Predicate CreateScreenIsOffPredicate();
68
69// Create Predicate proto for a running scheduled job.
70Predicate CreateScheduledJobPredicate();
71
72// Create Predicate proto for holding wakelock.
73Predicate CreateHoldingWakelockPredicate();
74
75// Create a Predicate proto for app syncing.
76Predicate CreateIsSyncingPredicate();
77
78// Create a Predicate proto for app is in background.
79Predicate CreateIsInBackgroundPredicate();
80
81// Add a predicate to the predicate combination.
82void addPredicateToPredicateCombination(const Predicate& predicate, Predicate* combination);
83
84// Create dimensions from primitive fields.
85FieldMatcher CreateDimensions(const int atomId, const std::vector<int>& fields);
86
87// Create dimensions by attribution uid and tag.
88FieldMatcher CreateAttributionUidAndTagDimensions(const int atomId,
89 const std::vector<Position>& positions);
90
91// Create dimensions by attribution uid only.
92FieldMatcher CreateAttributionUidDimensions(const int atomId,
93 const std::vector<Position>& positions);
94
95// Create log event for screen state changed.
96std::unique_ptr<LogEvent> CreateScreenStateChangedEvent(
97 const android::view::DisplayStateEnum state, uint64_t timestampNs);
98
99// Create log event for screen brightness state changed.
100std::unique_ptr<LogEvent> CreateScreenBrightnessChangedEvent(
101 int level, uint64_t timestampNs);
102
103// Create log event when scheduled job starts.
104std::unique_ptr<LogEvent> CreateStartScheduledJobEvent(
105 const std::vector<AttributionNodeInternal>& attributions,
106 const string& name, uint64_t timestampNs);
107
108// Create log event when scheduled job finishes.
109std::unique_ptr<LogEvent> CreateFinishScheduledJobEvent(
110 const std::vector<AttributionNodeInternal>& attributions,
111 const string& name, uint64_t timestampNs);
112
113// Create log event for app moving to background.
114std::unique_ptr<LogEvent> CreateMoveToBackgroundEvent(const int uid, uint64_t timestampNs);
115
116// Create log event for app moving to foreground.
117std::unique_ptr<LogEvent> CreateMoveToForegroundEvent(const int uid, uint64_t timestampNs);
118
119// Create log event when the app sync starts.
120std::unique_ptr<LogEvent> CreateSyncStartEvent(
121 const std::vector<AttributionNodeInternal>& attributions, const string& name,
122 uint64_t timestampNs);
123
124// Create log event when the app sync ends.
125std::unique_ptr<LogEvent> CreateSyncEndEvent(
126 const std::vector<AttributionNodeInternal>& attributions, const string& name,
127 uint64_t timestampNs);
128
129// Create log event when the app sync ends.
130std::unique_ptr<LogEvent> CreateAppCrashEvent(
131 const int uid, uint64_t timestampNs);
132
133// Create log event for acquiring wakelock.
134std::unique_ptr<LogEvent> CreateAcquireWakelockEvent(
135 const std::vector<AttributionNodeInternal>& attributions, const string& wakelockName,
136 uint64_t timestampNs);
137
138// Create log event for releasing wakelock.
139std::unique_ptr<LogEvent> CreateReleaseWakelockEvent(
140 const std::vector<AttributionNodeInternal>& attributions, const string& wakelockName,
141 uint64_t timestampNs);
142
143// Create log event for releasing wakelock.
144std::unique_ptr<LogEvent> CreateIsolatedUidChangedEvent(
145 int isolatedUid, int hostUid, bool is_create, uint64_t timestampNs);
146
147// Helper function to create an AttributionNodeInternal proto.
148AttributionNodeInternal CreateAttribution(const int& uid, const string& tag);
149
150// Create a statsd log event processor upon the start time in seconds, config and key.
151sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const StatsdConfig& config,
152 const ConfigKey& key);
153
154// Util function to sort the log events by timestamp.
155void sortLogEventsByTimestamp(std::vector<std::unique_ptr<LogEvent>> *events);
156
157int64_t StringToId(const string& str);
158
159} // namespace statsd
160} // namespace os
161} // namespace android