OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/process_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <malloc.h> | 8 #include <malloc.h> |
9 #include <sys/time.h> | 9 #include <sys/time.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 | 616 |
617 SystemMemoryInfoKB::SystemMemoryInfoKB() | 617 SystemMemoryInfoKB::SystemMemoryInfoKB() |
618 : total(0), | 618 : total(0), |
619 free(0), | 619 free(0), |
620 buffers(0), | 620 buffers(0), |
621 cached(0), | 621 cached(0), |
622 active_anon(0), | 622 active_anon(0), |
623 inactive_anon(0), | 623 inactive_anon(0), |
624 active_file(0), | 624 active_file(0), |
625 inactive_file(0), | 625 inactive_file(0), |
626 shmem(0) { | 626 shmem(0), |
| 627 gem_objects(-1), |
| 628 gem_size(-1) { |
627 } | 629 } |
628 | 630 |
629 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 631 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
630 // Synchronously reading files in /proc is safe. | 632 // Synchronously reading files in /proc is safe. |
631 base::ThreadRestrictions::ScopedAllowIO allow_io; | 633 base::ThreadRestrictions::ScopedAllowIO allow_io; |
632 | 634 |
633 // Used memory is: total - free - buffers - caches | 635 // Used memory is: total - free - buffers - caches |
634 FilePath meminfo_file("/proc/meminfo"); | 636 FilePath meminfo_file("/proc/meminfo"); |
635 std::string meminfo_data; | 637 std::string meminfo_data; |
636 if (!file_util::ReadFileToString(meminfo_file, &meminfo_data)) { | 638 if (!file_util::ReadFileToString(meminfo_file, &meminfo_data)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 // meminfo format varies on different hardware so we have to search for the | 673 // meminfo format varies on different hardware so we have to search for the |
672 // string. It always appears after "Cached:". | 674 // string. It always appears after "Cached:". |
673 for (size_t i = kMemCachedIndex+2; i < meminfo_fields.size(); i += 3) { | 675 for (size_t i = kMemCachedIndex+2; i < meminfo_fields.size(); i += 3) { |
674 if (meminfo_fields[i] == "Shmem:") { | 676 if (meminfo_fields[i] == "Shmem:") { |
675 base::StringToInt(meminfo_fields[i+1], &meminfo->shmem); | 677 base::StringToInt(meminfo_fields[i+1], &meminfo->shmem); |
676 break; | 678 break; |
677 } | 679 } |
678 } | 680 } |
679 #endif | 681 #endif |
680 | 682 |
681 // Check for gem data and report if present. | 683 // Check for graphics memory data and report if present. Synchronously |
| 684 // reading files in /sys is fast. |
| 685 #if defined(ARCH_CPU_ARM_FAMILY) |
| 686 FilePath geminfo_file("/sys/kernel/debug/dri/0/exynos_gem_objects"); |
| 687 #else |
682 FilePath geminfo_file("/sys/kernel/debug/dri/0/i915_gem_objects"); | 688 FilePath geminfo_file("/sys/kernel/debug/dri/0/i915_gem_objects"); |
| 689 #endif |
683 std::string geminfo_data; | 690 std::string geminfo_data; |
684 FilePath mali_memory_file("/sys/devices/platform/mali.0/memory"); | |
685 std::string mali_memory_data; | |
686 meminfo->gem_objects = -1; | 691 meminfo->gem_objects = -1; |
687 meminfo->gem_size = -1; | 692 meminfo->gem_size = -1; |
688 if (file_util::ReadFileToString(geminfo_file, &geminfo_data)) { | 693 if (file_util::ReadFileToString(geminfo_file, &geminfo_data)) { |
689 int gem_objects = -1; | 694 int gem_objects = -1; |
690 long long gem_size = -1; | 695 long long gem_size = -1; |
691 int num_res = sscanf(geminfo_data.c_str(), | 696 int num_res = sscanf(geminfo_data.c_str(), |
692 "%d objects, %lld bytes", | 697 "%d objects, %lld bytes", |
693 &gem_objects, &gem_size); | 698 &gem_objects, &gem_size); |
694 if (num_res == 2) { | 699 if (num_res == 2) { |
695 meminfo->gem_objects = gem_objects; | 700 meminfo->gem_objects = gem_objects; |
696 meminfo->gem_size = gem_size; | 701 meminfo->gem_size = gem_size; |
697 } | 702 } |
698 } else { | 703 } |
699 if (file_util::ReadFileToString(mali_memory_file, &mali_memory_data)) { | |
700 long long mali_size = -1; | |
701 int num_res = sscanf(mali_memory_data.c_str(), "%lld bytes", &mali_size); | |
702 if (num_res == 1) | |
703 meminfo->gem_size = mali_size; | |
704 } | |
705 | 704 |
| 705 #if defined(ARCH_CPU_ARM_FAMILY) |
| 706 // Incorporate Mali graphics memory if present. |
| 707 FilePath mali_memory_file("/sys/devices/platform/mali.0/memory"); |
| 708 std::string mali_memory_data; |
| 709 if (file_util::ReadFileToString(mali_memory_file, &mali_memory_data)) { |
| 710 long long mali_size = -1; |
| 711 int num_res = sscanf(mali_memory_data.c_str(), "%lld bytes", &mali_size); |
| 712 if (num_res == 1) |
| 713 meminfo->gem_size += mali_size; |
706 } | 714 } |
| 715 #endif // defined(ARCH_CPU_ARM_FAMILY) |
| 716 |
707 return true; | 717 return true; |
708 } | 718 } |
709 | 719 |
710 size_t GetSystemCommitCharge() { | 720 size_t GetSystemCommitCharge() { |
711 SystemMemoryInfoKB meminfo; | 721 SystemMemoryInfoKB meminfo; |
712 if (!GetSystemMemoryInfo(&meminfo)) | 722 if (!GetSystemMemoryInfo(&meminfo)) |
713 return 0; | 723 return 0; |
714 return meminfo.total - meminfo.free - meminfo.buffers - meminfo.cached; | 724 return meminfo.total - meminfo.free - meminfo.buffers - meminfo.cached; |
715 } | 725 } |
716 | 726 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 int score_len = static_cast<int>(score_str.length()); | 877 int score_len = static_cast<int>(score_str.length()); |
868 return (score_len == file_util::WriteFile(oom_file, | 878 return (score_len == file_util::WriteFile(oom_file, |
869 score_str.c_str(), | 879 score_str.c_str(), |
870 score_len)); | 880 score_len)); |
871 } | 881 } |
872 | 882 |
873 return false; | 883 return false; |
874 } | 884 } |
875 | 885 |
876 } // namespace base | 886 } // namespace base |
OLD | NEW |