• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #include "base/android/sys_utils.h"
6 
7 #include <memory>
8 
9 #include "base/android/build_info.h"
10 #include "base/process/process_metrics.h"
11 #include "base/sys_info.h"
12 #include "base/trace_event/trace_event.h"
13 #include "jni/SysUtils_jni.h"
14 
15 namespace base {
16 namespace android {
17 
IsLowEndDeviceFromJni()18 bool SysUtils::IsLowEndDeviceFromJni() {
19   JNIEnv* env = AttachCurrentThread();
20   return Java_SysUtils_isLowEndDevice(env);
21 }
22 
IsCurrentlyLowMemory()23 bool SysUtils::IsCurrentlyLowMemory() {
24   JNIEnv* env = AttachCurrentThread();
25   return Java_SysUtils_isCurrentlyLowMemory(env);
26 }
27 
28 // Logs the number of minor / major page faults to tracing (and also the time to
29 // collect) the metrics. Does nothing if tracing is not enabled.
JNI_SysUtils_LogPageFaultCountToTracing(JNIEnv * env,const base::android::JavaParamRef<jclass> & jcaller)30 static void JNI_SysUtils_LogPageFaultCountToTracing(
31     JNIEnv* env,
32     const base::android::JavaParamRef<jclass>& jcaller) {
33   // This is racy, but we are OK losing data, and collecting it is potentially
34   // expensive (reading and parsing a file).
35   bool enabled;
36   TRACE_EVENT_CATEGORY_GROUP_ENABLED("startup", &enabled);
37   if (!enabled)
38     return;
39   TRACE_EVENT_BEGIN2("memory", "CollectPageFaultCount", "minor", 0, "major", 0);
40   std::unique_ptr<base::ProcessMetrics> process_metrics(
41       base::ProcessMetrics::CreateProcessMetrics(
42           base::GetCurrentProcessHandle()));
43   base::PageFaultCounts counts;
44   process_metrics->GetPageFaultCounts(&counts);
45   TRACE_EVENT_END2("memory", "CollectPageFaults", "minor", counts.minor,
46                    "major", counts.major);
47 }
48 
49 }  // namespace android
50 
51 }  // namespace base
52