blob: 403e02532a9d6f75f061322d4d90204462568717 [file] [log] [blame]
Than McIntosh7e2f4e92015-03-05 11:05:02 -05001/*
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
Andreas Gampeddf6ea22017-12-21 11:37:21 -080018#include <string.h>
19
Andreas Gampea3498502017-12-27 11:23:41 -080020#include <android-base/logging.h>
21
Andreas Gampee44ae142017-12-21 10:02:23 -080022#include "config.h"
Andreas Gampeddf6ea22017-12-21 11:37:21 -080023#include "perfprofd_binder.h"
Andreas Gampea3498502017-12-27 11:23:41 -080024#include "perfprofdcore.h"
Andreas Gampee44ae142017-12-21 10:02:23 -080025
26extern int perfprofd_main(int argc, char** argv, Config* config);
Than McIntosh7e2f4e92015-03-05 11:05:02 -050027
28int main(int argc, char** argv)
29{
Andreas Gampeddf6ea22017-12-21 11:37:21 -080030 if (argc > 1 && strcmp(argv[1], "--binder") == 0) {
Andreas Gampec445aff2017-12-27 10:44:42 -080031 return android::perfprofd::binder::Main();
Andreas Gampeddf6ea22017-12-21 11:37:21 -080032 }
33
Andreas Gampe517f4e92017-12-21 10:26:36 -080034 struct PosixSleepConfig : public Config {
35 void Sleep(size_t seconds) override {
36 sleep(seconds);
37 }
Andreas Gampea3498502017-12-27 11:23:41 -080038 bool IsProfilingEnabled() const override {
39 //
40 // Check for existence of semaphore file in config directory
41 //
42 if (access(config_directory.c_str(), F_OK) == -1) {
43 PLOG(WARNING) << "unable to open config directory " << config_directory;
44 return false;
45 }
46
47 // Check for existence of semaphore file
48 std::string semaphore_filepath = config_directory
49 + "/" + SEMAPHORE_FILENAME;
50 if (access(semaphore_filepath.c_str(), F_OK) == -1) {
51 return false;
52 }
53
54 return true;
55 }
Andreas Gampe517f4e92017-12-21 10:26:36 -080056 };
57 PosixSleepConfig config;
Andreas Gampee44ae142017-12-21 10:02:23 -080058 return perfprofd_main(argc, argv, &config);
Than McIntosh7e2f4e92015-03-05 11:05:02 -050059}