1 /*
2 **
3 ** Copyright 2015, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18 #include <string.h>
19
20 #include <android-base/logging.h>
21
22 #include "config.h"
23 #include "perfprofd_binder.h"
24 #include "perfprofd_cmdline.h"
25 #include "perfprofdcore.h"
26
27 extern int perfprofd_main(int argc, char** argv, Config* config);
28
main(int argc,char ** argv)29 int main(int argc, char** argv)
30 {
31 if (argc > 1 && strcmp(argv[1], "--binder") == 0) {
32 return android::perfprofd::binder::Main();
33 }
34
35 struct PosixSleepConfig : public Config {
36 void Sleep(size_t seconds) override {
37 sleep(seconds);
38 }
39 bool IsProfilingEnabled() const override {
40 //
41 // Check for existence of semaphore file in config directory
42 //
43 if (access(config_directory.c_str(), F_OK) == -1) {
44 PLOG(WARNING) << "unable to open config directory " << config_directory;
45 return false;
46 }
47
48 // Check for existence of semaphore file
49 std::string semaphore_filepath = config_directory
50 + "/" + SEMAPHORE_FILENAME;
51 if (access(semaphore_filepath.c_str(), F_OK) == -1) {
52 return false;
53 }
54
55 return true;
56 }
57 };
58 PosixSleepConfig config;
59 return perfprofd_main(argc, argv, &config);
60 }
61