blob: 0f9f53e92f4af5d97afa61eb8a58502153ea692a [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 Gampe04672dd2018-03-28 14:28:18 -070024#include "perfprofd_cmdline.h"
Andreas Gampea3498502017-12-27 11:23:41 -080025#include "perfprofdcore.h"
Andreas Gampee44ae142017-12-21 10:02:23 -080026
27extern int perfprofd_main(int argc, char** argv, Config* config);
Than McIntosh7e2f4e92015-03-05 11:05:02 -050028
29int main(int argc, char** argv)
30{
Andreas Gampeddf6ea22017-12-21 11:37:21 -080031 if (argc > 1 && strcmp(argv[1], "--binder") == 0) {
Andreas Gampec445aff2017-12-27 10:44:42 -080032 return android::perfprofd::binder::Main();
Andreas Gampeddf6ea22017-12-21 11:37:21 -080033 }
34
Andreas Gampe517f4e92017-12-21 10:26:36 -080035 struct PosixSleepConfig : public Config {
36 void Sleep(size_t seconds) override {
37 sleep(seconds);
38 }
Andreas Gampea3498502017-12-27 11:23:41 -080039 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 }
Andreas Gampe517f4e92017-12-21 10:26:36 -080057 };
58 PosixSleepConfig config;
Andreas Gampee44ae142017-12-21 10:02:23 -080059 return perfprofd_main(argc, argv, &config);
Than McIntosh7e2f4e92015-03-05 11:05:02 -050060}