blob: 282e1b2c70a037250c662a664bab3fbfee793508 [file] [log] [blame]
Yangster-mac20877162017-12-22 17:19:39 -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/statsd_config.pb.h"
18#include "statslog.h"
19#include "src/logd/LogEvent.h"
20#include "src/StatsLogProcessor.h"
21
22namespace android {
23namespace os {
24namespace statsd {
25
26// Create AtomMatcher proto for acquiring wakelock.
27AtomMatcher CreateAcquireWakelockAtomMatcher();
28
29// Create AtomMatcher proto for releasing wakelock.
30AtomMatcher CreateReleaseWakelockAtomMatcher() ;
31
32// Create AtomMatcher proto for screen turned on.
33AtomMatcher CreateScreenTurnedOnAtomMatcher();
34
35// Create AtomMatcher proto for screen turned off.
36AtomMatcher CreateScreenTurnedOffAtomMatcher();
37
38// Create AtomMatcher proto for app sync turned on.
39AtomMatcher CreateSyncStartAtomMatcher();
40
41// Create AtomMatcher proto for app sync turned off.
42AtomMatcher CreateSyncEndAtomMatcher();
43
44// Create AtomMatcher proto for app sync moves to background.
45AtomMatcher CreateMoveToBackgroundAtomMatcher();
46
47// Create AtomMatcher proto for app sync moves to foreground.
48AtomMatcher CreateMoveToForegroundAtomMatcher();
49
50// Create AtomMatcher proto for process crashes
51AtomMatcher CreateProcessCrashAtomMatcher() ;
52
53// Create Predicate proto for screen is on.
54Predicate CreateScreenIsOnPredicate();
55
56// Create Predicate proto for screen is off.
57Predicate CreateScreenIsOffPredicate();
58
59// Create Predicate proto for holding wakelock.
60Predicate CreateHoldingWakelockPredicate();
61
62// Create a Predicate proto for app syncing.
63Predicate CreateIsSyncingPredicate();
64
65// Create a Predicate proto for app is in background.
66Predicate CreateIsInBackgroundPredicate();
67
68// Add a predicate to the predicate combination.
69void addPredicateToPredicateCombination(const Predicate& predicate, Predicate* combination);
70
71// Create dimensions from primitive fields.
72FieldMatcher CreateDimensions(const int atomId, const std::vector<int>& fields);
73
74// Create dimensions by attribution uid and tag.
75FieldMatcher CreateAttributionUidAndTagDimensions(const int atomId,
76 const std::vector<Position>& positions);
77
78// Create dimensions by attribution uid only.
79FieldMatcher CreateAttributionUidDimensions(const int atomId,
80 const std::vector<Position>& positions);
81
82// Create log event for screen state changed.
83std::unique_ptr<LogEvent> CreateScreenStateChangedEvent(
84 const ScreenStateChanged::State state, uint64_t timestampNs);
85
86// Create log event for app moving to background.
87std::unique_ptr<LogEvent> CreateMoveToBackgroundEvent(const int uid, uint64_t timestampNs);
88
89// Create log event for app moving to foreground.
90std::unique_ptr<LogEvent> CreateMoveToForegroundEvent(const int uid, uint64_t timestampNs);
91
92// Create log event when the app sync starts.
93std::unique_ptr<LogEvent> CreateSyncStartEvent(
94 const int uid, const string& name, uint64_t timestampNs);
95
96// Create log event when the app sync ends.
97std::unique_ptr<LogEvent> CreateSyncEndEvent(
98 const int uid, const string& name, uint64_t timestampNs);
99
100// Create log event when the app sync ends.
101std::unique_ptr<LogEvent> CreateAppCrashEvent(
102 const int uid, uint64_t timestampNs);
103
104// Create log event for acquiring wakelock.
105std::unique_ptr<LogEvent> CreateAcquireWakelockEvent(
106 const std::vector<AttributionNode>& attributions,
107 const string& wakelockName, uint64_t timestampNs);
108
109// Create log event for releasing wakelock.
110std::unique_ptr<LogEvent> CreateReleaseWakelockEvent(
111 const std::vector<AttributionNode>& attributions,
112 const string& wakelockName, uint64_t timestampNs);
113
114// Helper function to create an AttributionNode proto.
115AttributionNode CreateAttribution(const int& uid, const string& tag);
116
117// Create a statsd log event processor upon the start time in seconds, config and key.
118sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const StatsdConfig& config,
119 const ConfigKey& key);
120
121// Util function to sort the log events by timestamp.
122void sortLogEventsByTimestamp(std::vector<std::unique_ptr<LogEvent>> *events);
123
124} // namespace statsd
125} // namespace os
126} // namespace android