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.
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/system/sys_info.h"
12 #include "base/trace_event/base_tracing.h"
13
14 // Must come after all headers that specialize FromJniType() / ToJniType().
15 #include "base/sys_utils_jni/SysUtils_jni.h"
16
17 namespace base {
18 namespace android {
19
IsLowEndDeviceFromJni()20 bool SysUtils::IsLowEndDeviceFromJni() {
21 JNIEnv* env = AttachCurrentThread();
22 return Java_SysUtils_isLowEndDevice(env);
23 }
24
IsCurrentlyLowMemory()25 bool SysUtils::IsCurrentlyLowMemory() {
26 JNIEnv* env = AttachCurrentThread();
27 return Java_SysUtils_isCurrentlyLowMemory(env);
28 }
29
30 // static
AmountOfPhysicalMemoryKB()31 int SysUtils::AmountOfPhysicalMemoryKB() {
32 JNIEnv* env = AttachCurrentThread();
33 return Java_SysUtils_amountOfPhysicalMemoryKB(env);
34 }
35
36 // Logs the number of minor / major page faults to tracing (and also the time to
37 // collect) the metrics. Does nothing if tracing is not enabled.
JNI_SysUtils_LogPageFaultCountToTracing(JNIEnv * env)38 static void JNI_SysUtils_LogPageFaultCountToTracing(JNIEnv* env) {
39 // This is racy, but we are OK losing data, and collecting it is potentially
40 // expensive (reading and parsing a file).
41 bool enabled;
42 TRACE_EVENT_CATEGORY_GROUP_ENABLED("startup", &enabled);
43 if (!enabled)
44 return;
45 TRACE_EVENT_BEGIN2("memory", "CollectPageFaultCount", "minor", 0, "major", 0);
46 std::unique_ptr<base::ProcessMetrics> process_metrics(
47 base::ProcessMetrics::CreateProcessMetrics(
48 base::GetCurrentProcessHandle()));
49 base::PageFaultCounts counts;
50 process_metrics->GetPageFaultCounts(&counts);
51 TRACE_EVENT_END2("memory", "CollectPageFaults", "minor", counts.minor,
52 "major", counts.major);
53 }
54
55 } // namespace android
56
57 } // namespace base
58