| 6 |
| 7 | #include <memory> |
| 8 |
| 9 | #include "base/android/build_info.h" |
| 10 | #include "base/base_jni_headers/SysUtils_jni.h" |
| 11 | #include "base/process/process_metrics.h" |
| 12 | #include "base/system/sys_info.h" |
| 13 | #include "base/trace_event/trace_event.h" |
| 14 |
| 15 | namespace base { |
| 16 | namespace android { |
| 17 |
| 18 | bool SysUtils::IsLowEndDeviceFromJni() { |
| 19 | JNIEnv* env = AttachCurrentThread(); |
| 20 | return Java_SysUtils_isLowEndDevice(env); |
| 21 | } |
| 22 |
| 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. |
| 30 | static void JNI_SysUtils_LogPageFaultCountToTracing(JNIEnv* env) { |
| 31 | // This is racy, but we are OK losing data, and collecting it is potentially |
| 32 | // expensive (reading and parsing a file). |
| 33 | bool enabled; |
| 34 | TRACE_EVENT_CATEGORY_GROUP_ENABLED("startup", &enabled); |
| 35 | if (!enabled) |
| 36 | return; |
| 37 | TRACE_EVENT_BEGIN2("memory", "CollectPageFaultCount", "minor", 0, "major", 0); |
| 38 | std::unique_ptr<base::ProcessMetrics> process_metrics( |
| 39 | base::ProcessMetrics::CreateProcessMetrics( |
| 40 | base::GetCurrentProcessHandle())); |
| 41 | base::PageFaultCounts counts; |
| 42 | process_metrics->GetPageFaultCounts(&counts); |
| 43 | TRACE_EVENT_END2("memory", "CollectPageFaults", "minor", counts.minor, |
| 44 | "major", counts.major); |
| 45 | } |
| 46 |
| 47 | } // namespace android |
| 48 |
| 49 | } // namespace base |
| 50 |