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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 // Chrome OS has a tweaked kernel that allows us to query Shmem, which is | 676 // Chrome OS has a tweaked kernel that allows us to query Shmem, which is |
677 // usually video memory otherwise invisible to the OS. Unfortunately, the | 677 // usually video memory otherwise invisible to the OS. Unfortunately, the |
678 // meminfo format varies on different hardware so we have to search for the | 678 // meminfo format varies on different hardware so we have to search for the |
679 // string. It always appears after "Cached:". | 679 // string. It always appears after "Cached:". |
680 for (size_t i = kMemCachedIndex+2; i < meminfo_fields.size(); i += 3) { | 680 for (size_t i = kMemCachedIndex+2; i < meminfo_fields.size(); i += 3) { |
681 if (meminfo_fields[i] == "Shmem:") { | 681 if (meminfo_fields[i] == "Shmem:") { |
682 StringToInt(meminfo_fields[i+1], &meminfo->shmem); | 682 StringToInt(meminfo_fields[i+1], &meminfo->shmem); |
683 break; | 683 break; |
684 } | 684 } |
685 } | 685 } |
686 #endif | |
687 | 686 |
688 // Check for graphics memory data and report if present. Synchronously | 687 // Report on Chrome OS GEM object graphics memory. /var/run/debugfs_gpu is a |
689 // reading files in /sys is fast. | 688 // bind mount into /sys/kernel/debug and synchronously reading the in-memory |
| 689 // files in /sys is fast. |
690 #if defined(ARCH_CPU_ARM_FAMILY) | 690 #if defined(ARCH_CPU_ARM_FAMILY) |
691 FilePath geminfo_file("/sys/kernel/debug/dri/0/exynos_gem_objects"); | 691 FilePath geminfo_file("/var/run/debugfs_gpu/exynos_gem_objects"); |
692 #else | 692 #else |
693 FilePath geminfo_file("/sys/kernel/debug/dri/0/i915_gem_objects"); | 693 FilePath geminfo_file("/var/run/debugfs_gpu/i915_gem_objects"); |
694 #endif | 694 #endif |
695 std::string geminfo_data; | 695 std::string geminfo_data; |
696 meminfo->gem_objects = -1; | 696 meminfo->gem_objects = -1; |
697 meminfo->gem_size = -1; | 697 meminfo->gem_size = -1; |
698 if (file_util::ReadFileToString(geminfo_file, &geminfo_data)) { | 698 if (file_util::ReadFileToString(geminfo_file, &geminfo_data)) { |
699 int gem_objects = -1; | 699 int gem_objects = -1; |
700 long long gem_size = -1; | 700 long long gem_size = -1; |
701 int num_res = sscanf(geminfo_data.c_str(), | 701 int num_res = sscanf(geminfo_data.c_str(), |
702 "%d objects, %lld bytes", | 702 "%d objects, %lld bytes", |
703 &gem_objects, &gem_size); | 703 &gem_objects, &gem_size); |
704 if (num_res == 2) { | 704 if (num_res == 2) { |
705 meminfo->gem_objects = gem_objects; | 705 meminfo->gem_objects = gem_objects; |
706 meminfo->gem_size = gem_size; | 706 meminfo->gem_size = gem_size; |
707 } | 707 } |
708 } | 708 } |
709 | 709 |
710 #if defined(ARCH_CPU_ARM_FAMILY) | 710 #if defined(ARCH_CPU_ARM_FAMILY) |
711 // Incorporate Mali graphics memory if present. | 711 // Incorporate Mali graphics memory if present. |
712 FilePath mali_memory_file("/sys/devices/platform/mali.0/memory"); | 712 FilePath mali_memory_file("/sys/devices/platform/mali.0/memory"); |
713 std::string mali_memory_data; | 713 std::string mali_memory_data; |
714 if (file_util::ReadFileToString(mali_memory_file, &mali_memory_data)) { | 714 if (file_util::ReadFileToString(mali_memory_file, &mali_memory_data)) { |
715 long long mali_size = -1; | 715 long long mali_size = -1; |
716 int num_res = sscanf(mali_memory_data.c_str(), "%lld bytes", &mali_size); | 716 int num_res = sscanf(mali_memory_data.c_str(), "%lld bytes", &mali_size); |
717 if (num_res == 1) | 717 if (num_res == 1) |
718 meminfo->gem_size += mali_size; | 718 meminfo->gem_size += mali_size; |
719 } | 719 } |
720 #endif // defined(ARCH_CPU_ARM_FAMILY) | 720 #endif // defined(ARCH_CPU_ARM_FAMILY) |
| 721 #endif // defined(OS_CHROMEOS) |
721 | 722 |
722 return true; | 723 return true; |
723 } | 724 } |
724 | 725 |
725 size_t GetSystemCommitCharge() { | 726 size_t GetSystemCommitCharge() { |
726 SystemMemoryInfoKB meminfo; | 727 SystemMemoryInfoKB meminfo; |
727 if (!GetSystemMemoryInfo(&meminfo)) | 728 if (!GetSystemMemoryInfo(&meminfo)) |
728 return 0; | 729 return 0; |
729 return meminfo.total - meminfo.free - meminfo.buffers - meminfo.cached; | 730 return meminfo.total - meminfo.free - meminfo.buffers - meminfo.cached; |
730 } | 731 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 int score_len = static_cast<int>(score_str.length()); | 883 int score_len = static_cast<int>(score_str.length()); |
883 return (score_len == file_util::WriteFile(oom_file, | 884 return (score_len == file_util::WriteFile(oom_file, |
884 score_str.c_str(), | 885 score_str.c_str(), |
885 score_len)); | 886 score_len)); |
886 } | 887 } |
887 | 888 |
888 return false; | 889 return false; |
889 } | 890 } |
890 | 891 |
891 } // namespace base | 892 } // namespace base |
OLD | NEW |