process_metric.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) 2019 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_API_PROCESS_METRIC_H_
  5. #define ELECTRON_SHELL_BROWSER_API_PROCESS_METRIC_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/process/process.h"
  9. #include "base/process/process_handle.h"
  10. #include "base/process/process_metrics.h"
  11. namespace electron {
  12. #if !BUILDFLAG(IS_LINUX)
  13. struct ProcessMemoryInfo {
  14. size_t working_set_size = 0;
  15. size_t peak_working_set_size = 0;
  16. #if BUILDFLAG(IS_WIN)
  17. size_t private_bytes = 0;
  18. #endif
  19. };
  20. #endif
  21. #if BUILDFLAG(IS_WIN)
  22. enum class ProcessIntegrityLevel {
  23. kUnknown,
  24. kUntrusted,
  25. kLow,
  26. kMedium,
  27. kHigh,
  28. };
  29. #endif
  30. struct ProcessMetric {
  31. int type;
  32. base::Process process;
  33. std::unique_ptr<base::ProcessMetrics> metrics;
  34. std::string service_name;
  35. std::string name;
  36. ProcessMetric(int type,
  37. base::ProcessHandle handle,
  38. std::unique_ptr<base::ProcessMetrics> metrics,
  39. const std::string& service_name = std::string(),
  40. const std::string& name = std::string());
  41. ~ProcessMetric();
  42. #if !BUILDFLAG(IS_LINUX)
  43. ProcessMemoryInfo GetMemoryInfo() const;
  44. #endif
  45. #if BUILDFLAG(IS_WIN)
  46. ProcessIntegrityLevel GetIntegrityLevel() const;
  47. static bool IsSandboxed(ProcessIntegrityLevel integrity_level);
  48. #elif BUILDFLAG(IS_MAC)
  49. bool IsSandboxed() const;
  50. #endif
  51. };
  52. } // namespace electron
  53. #endif // ELECTRON_SHELL_BROWSER_API_PROCESS_METRIC_H_