sys_utils.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/android/sys_utils.h"
  5. #include <memory>
  6. #include "base/android/build_info.h"
  7. #include "base/base_jni_headers/SysUtils_jni.h"
  8. #include "base/process/process_metrics.h"
  9. #include "base/system/sys_info.h"
  10. #include "base/trace_event/base_tracing.h"
  11. namespace base {
  12. namespace android {
  13. bool SysUtils::IsLowEndDeviceFromJni() {
  14. JNIEnv* env = AttachCurrentThread();
  15. return Java_SysUtils_isLowEndDevice(env);
  16. }
  17. bool SysUtils::IsCurrentlyLowMemory() {
  18. JNIEnv* env = AttachCurrentThread();
  19. return Java_SysUtils_isCurrentlyLowMemory(env);
  20. }
  21. // static
  22. int SysUtils::AmountOfPhysicalMemoryKB() {
  23. JNIEnv* env = AttachCurrentThread();
  24. return Java_SysUtils_amountOfPhysicalMemoryKB(env);
  25. }
  26. // Logs the number of minor / major page faults to tracing (and also the time to
  27. // collect) the metrics. Does nothing if tracing is not enabled.
  28. static void JNI_SysUtils_LogPageFaultCountToTracing(JNIEnv* env) {
  29. // This is racy, but we are OK losing data, and collecting it is potentially
  30. // expensive (reading and parsing a file).
  31. bool enabled;
  32. TRACE_EVENT_CATEGORY_GROUP_ENABLED("startup", &enabled);
  33. if (!enabled)
  34. return;
  35. TRACE_EVENT_BEGIN2("memory", "CollectPageFaultCount", "minor", 0, "major", 0);
  36. std::unique_ptr<base::ProcessMetrics> process_metrics(
  37. base::ProcessMetrics::CreateProcessMetrics(
  38. base::GetCurrentProcessHandle()));
  39. base::PageFaultCounts counts;
  40. process_metrics->GetPageFaultCounts(&counts);
  41. TRACE_EVENT_END2("memory", "CollectPageFaults", "minor", counts.minor,
  42. "major", counts.major);
  43. }
  44. } // namespace android
  45. } // namespace base