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