• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 #define DEBUG false  // STOPSHIP if true
18 #include "Log.h"
19 
20 #include <android/os/IStatsPullerCallback.h>
21 
22 #include "StatsCallbackPuller.h"
23 #include "logd/LogEvent.h"
24 #include "stats_log_util.h"
25 
26 using namespace android::binder;
27 
28 namespace android {
29 namespace os {
30 namespace statsd {
31 
StatsCallbackPuller(int tagId,const sp<IStatsPullerCallback> & callback)32 StatsCallbackPuller::StatsCallbackPuller(int tagId, const sp<IStatsPullerCallback>& callback) :
33         StatsPuller(tagId), mCallback(callback) {
34         VLOG("StatsCallbackPuller created for tag %d", tagId);
35 }
36 
PullInternal(vector<shared_ptr<LogEvent>> * data)37 bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) {
38     VLOG("StatsCallbackPuller called for tag %d", mTagId)
39     if(mCallback == nullptr) {
40         ALOGW("No callback registered");
41         return false;
42     }
43     int64_t wallClockTimeNs = getWallClockNs();
44     int64_t elapsedTimeNs = getElapsedRealtimeNs();
45     vector<StatsLogEventWrapper> returned_value;
46     Status status = mCallback->pullData(mTagId, elapsedTimeNs, wallClockTimeNs, &returned_value);
47     if (!status.isOk()) {
48         ALOGW("StatsCallbackPuller::pull failed for %d", mTagId);
49         return false;
50     }
51     data->clear();
52     for (const StatsLogEventWrapper& it: returned_value) {
53         LogEvent::createLogEvents(it, *data);
54     }
55     VLOG("StatsCallbackPuller::pull succeeded for %d", mTagId);
56     return true;
57 }
58 
59 }  // namespace statsd
60 }  // namespace os
61 }  // namespace android
62