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