• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 #include "Perfprofd.h"
18 
19 #define DEBUG false  // STOPSHIP if true
20 #include "config/ConfigKey.h"
21 #include "Log.h"
22 
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <sys/types.h>
26 #include <sys/wait.h>
27 #include <unistd.h>
28 
29 #include <string>
30 
31 #include <binder/IServiceManager.h>
32 
33 #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"  // Alert
34 
35 #include "android/os/IPerfProfd.h"
36 
37 namespace android {
38 namespace os {
39 namespace statsd {
40 
CollectPerfprofdTraceAndUploadToDropbox(const PerfprofdDetails & config,int64_t alert_id,const ConfigKey & configKey)41 bool CollectPerfprofdTraceAndUploadToDropbox(const PerfprofdDetails& config,
42                                              int64_t alert_id,
43                                              const ConfigKey& configKey) {
44     VLOG("Starting trace collection through perfprofd");
45 
46     if (!config.has_perfprofd_config()) {
47       ALOGE("The perfprofd trace config is empty, aborting");
48       return false;
49     }
50 
51     sp<IPerfProfd> service = interface_cast<IPerfProfd>(
52         defaultServiceManager()->getService(android::String16("perfprofd")));
53     if (service == NULL) {
54       ALOGE("Could not find perfprofd service");
55       return false;
56     }
57 
58     auto* data = reinterpret_cast<const uint8_t*>(config.perfprofd_config().data());
59     std::vector<uint8_t> proto_serialized(data, data + config.perfprofd_config().size());
60 
61     // TODO: alert-id etc?
62 
63     binder::Status status = service->startProfilingProtobuf(proto_serialized);
64     if (status.isOk()) {
65       return true;
66     }
67 
68     ALOGE("Error starting perfprofd profiling: %s", status.toString8().c_str());
69     return false;
70 }
71 
72 }  // namespace statsd
73 }  // namespace os
74 }  // namespace android
75