perfprofdmain.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <string.h>
  18. #include <android-base/logging.h>
  19. #include "config.h"
  20. #include "perfprofd_binder.h"
  21. #include "perfprofd_cmdline.h"
  22. #include "perfprofdcore.h"
  23. extern int perfprofd_main(int argc, char** argv, Config* config);
  24. int main(int argc, char** argv)
  25. {
  26. if (argc > 1 && strcmp(argv[1], "--binder") == 0) {
  27. return android::perfprofd::binder::Main();
  28. }
  29. struct PosixSleepConfig : public Config {
  30. void Sleep(size_t seconds) override {
  31. sleep(seconds);
  32. }
  33. bool IsProfilingEnabled() const override {
  34. //
  35. // Check for existence of semaphore file in config directory
  36. //
  37. if (access(config_directory.c_str(), F_OK) == -1) {
  38. PLOG(WARNING) << "unable to open config directory " << config_directory;
  39. return false;
  40. }
  41. // Check for existence of semaphore file
  42. std::string semaphore_filepath = config_directory
  43. + "/" + SEMAPHORE_FILENAME;
  44. if (access(semaphore_filepath.c_str(), F_OK) == -1) {
  45. return false;
  46. }
  47. return true;
  48. }
  49. };
  50. PosixSleepConfig config;
  51. return perfprofd_main(argc, argv, &config);
  52. }