Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(999)

Side by Side Diff: base/process/process_metrics_linux.cc

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Fix review notes. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/process_metrics.h" 5 #include "base/process/process_metrics.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 const size_t kDiskWriteTime = 10; 528 const size_t kDiskWriteTime = 10;
529 const size_t kDiskIO = 11; 529 const size_t kDiskIO = 11;
530 const size_t kDiskIOTime = 12; 530 const size_t kDiskIOTime = 12;
531 const size_t kDiskWeightedIOTime = 13; 531 const size_t kDiskWeightedIOTime = 13;
532 532
533 } // namespace 533 } // namespace
534 534
535 SystemMemoryInfoKB::SystemMemoryInfoKB() { 535 SystemMemoryInfoKB::SystemMemoryInfoKB() {
536 total = 0; 536 total = 0;
537 free = 0; 537 free = 0;
538 #if defined(OS_LINUX)
539 available = 0; 538 available = 0;
540 #endif
541 buffers = 0; 539 buffers = 0;
542 cached = 0; 540 cached = 0;
543 active_anon = 0; 541 active_anon = 0;
544 inactive_anon = 0; 542 inactive_anon = 0;
545 active_file = 0; 543 active_file = 0;
546 inactive_file = 0; 544 inactive_file = 0;
547 swap_total = 0; 545 swap_total = 0;
548 swap_free = 0; 546 swap_free = 0;
549 dirty = 0; 547 dirty = 0;
548 reclaimable = 0;
550 549
551 pswpin = 0; 550 pswpin = 0;
552 pswpout = 0; 551 pswpout = 0;
553 pgmajfault = 0; 552 pgmajfault = 0;
554 553
555 #ifdef OS_CHROMEOS 554 #ifdef OS_CHROMEOS
556 shmem = 0; 555 shmem = 0;
557 slab = 0; 556 slab = 0;
558 gem_objects = -1; 557 gem_objects = -1;
559 gem_size = -1; 558 gem_size = -1;
560 #endif 559 #endif
561 } 560 }
562 561
563 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = 562 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) =
564 default; 563 default;
565 564
566 std::unique_ptr<Value> SystemMemoryInfoKB::ToValue() const { 565 std::unique_ptr<Value> SystemMemoryInfoKB::ToValue() const {
567 std::unique_ptr<DictionaryValue> res(new DictionaryValue()); 566 std::unique_ptr<DictionaryValue> res(new DictionaryValue());
568 567
569 res->SetInteger("total", total); 568 res->SetInteger("total", total);
570 res->SetInteger("free", free); 569 res->SetInteger("free", free);
571 #if defined(OS_LINUX)
572 res->SetInteger("available", available); 570 res->SetInteger("available", available);
573 #endif
574 res->SetInteger("buffers", buffers); 571 res->SetInteger("buffers", buffers);
575 res->SetInteger("cached", cached); 572 res->SetInteger("cached", cached);
576 res->SetInteger("active_anon", active_anon); 573 res->SetInteger("active_anon", active_anon);
577 res->SetInteger("inactive_anon", inactive_anon); 574 res->SetInteger("inactive_anon", inactive_anon);
578 res->SetInteger("active_file", active_file); 575 res->SetInteger("active_file", active_file);
579 res->SetInteger("inactive_file", inactive_file); 576 res->SetInteger("inactive_file", inactive_file);
580 res->SetInteger("swap_total", swap_total); 577 res->SetInteger("swap_total", swap_total);
581 res->SetInteger("swap_free", swap_free); 578 res->SetInteger("swap_free", swap_free);
582 res->SetInteger("swap_used", swap_total - swap_free); 579 res->SetInteger("swap_used", swap_total - swap_free);
583 res->SetInteger("dirty", dirty); 580 res->SetInteger("dirty", dirty);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 DLOG(WARNING) << "meminfo: tokens: " << tokens.size() 618 DLOG(WARNING) << "meminfo: tokens: " << tokens.size()
622 << " malformed line: " << line.as_string(); 619 << " malformed line: " << line.as_string();
623 continue; 620 continue;
624 } 621 }
625 622
626 int* target = NULL; 623 int* target = NULL;
627 if (tokens[0] == "MemTotal:") 624 if (tokens[0] == "MemTotal:")
628 target = &meminfo->total; 625 target = &meminfo->total;
629 else if (tokens[0] == "MemFree:") 626 else if (tokens[0] == "MemFree:")
630 target = &meminfo->free; 627 target = &meminfo->free;
631 #if defined(OS_LINUX)
632 else if (tokens[0] == "MemAvailable:") 628 else if (tokens[0] == "MemAvailable:")
633 target = &meminfo->available; 629 target = &meminfo->available;
634 #endif
635 else if (tokens[0] == "Buffers:") 630 else if (tokens[0] == "Buffers:")
636 target = &meminfo->buffers; 631 target = &meminfo->buffers;
637 else if (tokens[0] == "Cached:") 632 else if (tokens[0] == "Cached:")
638 target = &meminfo->cached; 633 target = &meminfo->cached;
639 else if (tokens[0] == "Active(anon):") 634 else if (tokens[0] == "Active(anon):")
640 target = &meminfo->active_anon; 635 target = &meminfo->active_anon;
641 else if (tokens[0] == "Inactive(anon):") 636 else if (tokens[0] == "Inactive(anon):")
642 target = &meminfo->inactive_anon; 637 target = &meminfo->inactive_anon;
643 else if (tokens[0] == "Active(file):") 638 else if (tokens[0] == "Active(file):")
644 target = &meminfo->active_file; 639 target = &meminfo->active_file;
645 else if (tokens[0] == "Inactive(file):") 640 else if (tokens[0] == "Inactive(file):")
646 target = &meminfo->inactive_file; 641 target = &meminfo->inactive_file;
647 else if (tokens[0] == "SwapTotal:") 642 else if (tokens[0] == "SwapTotal:")
648 target = &meminfo->swap_total; 643 target = &meminfo->swap_total;
649 else if (tokens[0] == "SwapFree:") 644 else if (tokens[0] == "SwapFree:")
650 target = &meminfo->swap_free; 645 target = &meminfo->swap_free;
651 else if (tokens[0] == "Dirty:") 646 else if (tokens[0] == "Dirty:")
652 target = &meminfo->dirty; 647 target = &meminfo->dirty;
648 else if (tokens[0] == "SReclaimable:")
649 target = &meminfo->reclaimable;
653 #if defined(OS_CHROMEOS) 650 #if defined(OS_CHROMEOS)
654 // Chrome OS has a tweaked kernel that allows us to query Shmem, which is 651 // Chrome OS has a tweaked kernel that allows us to query Shmem, which is
655 // usually video memory otherwise invisible to the OS. 652 // usually video memory otherwise invisible to the OS.
656 else if (tokens[0] == "Shmem:") 653 else if (tokens[0] == "Shmem:")
657 target = &meminfo->shmem; 654 target = &meminfo->shmem;
658 else if (tokens[0] == "Slab:") 655 else if (tokens[0] == "Slab:")
659 target = &meminfo->slab; 656 target = &meminfo->slab;
660 #endif 657 #endif
661 if (target) 658 if (target)
662 StringToInt(tokens[1], target); 659 StringToInt(tokens[1], target);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 #if defined(OS_LINUX) 963 #if defined(OS_LINUX)
967 int ProcessMetrics::GetIdleWakeupsPerSecond() { 964 int ProcessMetrics::GetIdleWakeupsPerSecond() {
968 uint64_t wake_ups; 965 uint64_t wake_ups;
969 const char kWakeupStat[] = "se.statistics.nr_wakeups"; 966 const char kWakeupStat[] = "se.statistics.nr_wakeups";
970 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? 967 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ?
971 CalculateIdleWakeupsPerSecond(wake_ups) : 0; 968 CalculateIdleWakeupsPerSecond(wake_ups) : 0;
972 } 969 }
973 #endif // defined(OS_LINUX) 970 #endif // defined(OS_LINUX)
974 971
975 } // namespace base 972 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698