Than McIntosh | 7e2f4e9 | 2015-03-05 11:05:02 -0500 | [diff] [blame] | 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 | |
Andreas Gampe | ddf6ea2 | 2017-12-21 11:37:21 -0800 | [diff] [blame] | 18 | #include <string.h> |
| 19 | |
Andreas Gampe | a349850 | 2017-12-27 11:23:41 -0800 | [diff] [blame] | 20 | #include <android-base/logging.h> |
| 21 | |
Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 22 | #include "config.h" |
Andreas Gampe | ddf6ea2 | 2017-12-21 11:37:21 -0800 | [diff] [blame] | 23 | #include "perfprofd_binder.h" |
Andreas Gampe | 04672dd | 2018-03-28 14:28:18 -0700 | [diff] [blame^] | 24 | #include "perfprofd_cmdline.h" |
Andreas Gampe | a349850 | 2017-12-27 11:23:41 -0800 | [diff] [blame] | 25 | #include "perfprofdcore.h" |
Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 26 | |
| 27 | extern int perfprofd_main(int argc, char** argv, Config* config); |
Than McIntosh | 7e2f4e9 | 2015-03-05 11:05:02 -0500 | [diff] [blame] | 28 | |
| 29 | int main(int argc, char** argv) |
| 30 | { |
Andreas Gampe | ddf6ea2 | 2017-12-21 11:37:21 -0800 | [diff] [blame] | 31 | if (argc > 1 && strcmp(argv[1], "--binder") == 0) { |
Andreas Gampe | c445aff | 2017-12-27 10:44:42 -0800 | [diff] [blame] | 32 | return android::perfprofd::binder::Main(); |
Andreas Gampe | ddf6ea2 | 2017-12-21 11:37:21 -0800 | [diff] [blame] | 33 | } |
| 34 | |
Andreas Gampe | 517f4e9 | 2017-12-21 10:26:36 -0800 | [diff] [blame] | 35 | struct PosixSleepConfig : public Config { |
| 36 | void Sleep(size_t seconds) override { |
| 37 | sleep(seconds); |
| 38 | } |
Andreas Gampe | a349850 | 2017-12-27 11:23:41 -0800 | [diff] [blame] | 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 | } |
Andreas Gampe | 517f4e9 | 2017-12-21 10:26:36 -0800 | [diff] [blame] | 57 | }; |
| 58 | PosixSleepConfig config; |
Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 59 | return perfprofd_main(argc, argv, &config); |
Than McIntosh | 7e2f4e9 | 2015-03-05 11:05:02 -0500 | [diff] [blame] | 60 | } |