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

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

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Fix comment formatting. 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) 538 #if defined(OS_LINUX) || defined(OS_ANDROID)
Primiano Tucci (use gerrit) 2017/02/15 11:18:33 i think you can ditch the ifdef at this point, can
Michael K. (Yandex Team) 2017/02/17 13:38:48 Done.
539 available = 0; 539 available = 0;
540 #endif 540 #endif
541 buffers = 0; 541 buffers = 0;
542 cached = 0; 542 cached = 0;
543 active_anon = 0; 543 active_anon = 0;
544 inactive_anon = 0; 544 inactive_anon = 0;
545 active_file = 0; 545 active_file = 0;
546 inactive_file = 0; 546 inactive_file = 0;
547 swap_total = 0; 547 swap_total = 0;
548 swap_free = 0; 548 swap_free = 0;
549 dirty = 0; 549 dirty = 0;
550 reclaimable = 0;
550 551
551 pswpin = 0; 552 pswpin = 0;
552 pswpout = 0; 553 pswpout = 0;
553 pgmajfault = 0; 554 pgmajfault = 0;
554 555
555 #ifdef OS_CHROMEOS 556 #ifdef OS_CHROMEOS
556 shmem = 0; 557 shmem = 0;
557 slab = 0; 558 slab = 0;
558 gem_objects = -1; 559 gem_objects = -1;
559 gem_size = -1; 560 gem_size = -1;
560 #endif 561 #endif
561 } 562 }
562 563
563 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = 564 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) =
564 default; 565 default;
565 566
566 std::unique_ptr<Value> SystemMemoryInfoKB::ToValue() const { 567 std::unique_ptr<Value> SystemMemoryInfoKB::ToValue() const {
567 std::unique_ptr<DictionaryValue> res(new DictionaryValue()); 568 std::unique_ptr<DictionaryValue> res(new DictionaryValue());
568 569
569 res->SetInteger("total", total); 570 res->SetInteger("total", total);
570 res->SetInteger("free", free); 571 res->SetInteger("free", free);
571 #if defined(OS_LINUX) 572 #if defined(OS_LINUX) || defined(OS_ANDROID)
Primiano Tucci (use gerrit) 2017/02/15 11:18:33 ditto, here an below
Michael K. (Yandex Team) 2017/02/17 13:38:48 Done.
572 res->SetInteger("available", available); 573 res->SetInteger("available", available);
573 #endif 574 #endif
574 res->SetInteger("buffers", buffers); 575 res->SetInteger("buffers", buffers);
575 res->SetInteger("cached", cached); 576 res->SetInteger("cached", cached);
576 res->SetInteger("active_anon", active_anon); 577 res->SetInteger("active_anon", active_anon);
577 res->SetInteger("inactive_anon", inactive_anon); 578 res->SetInteger("inactive_anon", inactive_anon);
578 res->SetInteger("active_file", active_file); 579 res->SetInteger("active_file", active_file);
579 res->SetInteger("inactive_file", inactive_file); 580 res->SetInteger("inactive_file", inactive_file);
580 res->SetInteger("swap_total", swap_total); 581 res->SetInteger("swap_total", swap_total);
581 res->SetInteger("swap_free", swap_free); 582 res->SetInteger("swap_free", swap_free);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 DLOG(WARNING) << "meminfo: tokens: " << tokens.size() 622 DLOG(WARNING) << "meminfo: tokens: " << tokens.size()
622 << " malformed line: " << line.as_string(); 623 << " malformed line: " << line.as_string();
623 continue; 624 continue;
624 } 625 }
625 626
626 int* target = NULL; 627 int* target = NULL;
627 if (tokens[0] == "MemTotal:") 628 if (tokens[0] == "MemTotal:")
628 target = &meminfo->total; 629 target = &meminfo->total;
629 else if (tokens[0] == "MemFree:") 630 else if (tokens[0] == "MemFree:")
630 target = &meminfo->free; 631 target = &meminfo->free;
631 #if defined(OS_LINUX) 632 #if defined(OS_LINUX) || defined(OS_ANDROID)
632 else if (tokens[0] == "MemAvailable:") 633 else if (tokens[0] == "MemAvailable:")
633 target = &meminfo->available; 634 target = &meminfo->available;
634 #endif 635 #endif
635 else if (tokens[0] == "Buffers:") 636 else if (tokens[0] == "Buffers:")
636 target = &meminfo->buffers; 637 target = &meminfo->buffers;
637 else if (tokens[0] == "Cached:") 638 else if (tokens[0] == "Cached:")
638 target = &meminfo->cached; 639 target = &meminfo->cached;
639 else if (tokens[0] == "Active(anon):") 640 else if (tokens[0] == "Active(anon):")
640 target = &meminfo->active_anon; 641 target = &meminfo->active_anon;
641 else if (tokens[0] == "Inactive(anon):") 642 else if (tokens[0] == "Inactive(anon):")
642 target = &meminfo->inactive_anon; 643 target = &meminfo->inactive_anon;
643 else if (tokens[0] == "Active(file):") 644 else if (tokens[0] == "Active(file):")
644 target = &meminfo->active_file; 645 target = &meminfo->active_file;
645 else if (tokens[0] == "Inactive(file):") 646 else if (tokens[0] == "Inactive(file):")
646 target = &meminfo->inactive_file; 647 target = &meminfo->inactive_file;
647 else if (tokens[0] == "SwapTotal:") 648 else if (tokens[0] == "SwapTotal:")
648 target = &meminfo->swap_total; 649 target = &meminfo->swap_total;
649 else if (tokens[0] == "SwapFree:") 650 else if (tokens[0] == "SwapFree:")
650 target = &meminfo->swap_free; 651 target = &meminfo->swap_free;
651 else if (tokens[0] == "Dirty:") 652 else if (tokens[0] == "Dirty:")
652 target = &meminfo->dirty; 653 target = &meminfo->dirty;
654 else if (tokens[0] == "SReclaimable:")
655 target = &meminfo->reclaimable;
653 #if defined(OS_CHROMEOS) 656 #if defined(OS_CHROMEOS)
654 // Chrome OS has a tweaked kernel that allows us to query Shmem, which is 657 // Chrome OS has a tweaked kernel that allows us to query Shmem, which is
655 // usually video memory otherwise invisible to the OS. 658 // usually video memory otherwise invisible to the OS.
656 else if (tokens[0] == "Shmem:") 659 else if (tokens[0] == "Shmem:")
657 target = &meminfo->shmem; 660 target = &meminfo->shmem;
658 else if (tokens[0] == "Slab:") 661 else if (tokens[0] == "Slab:")
659 target = &meminfo->slab; 662 target = &meminfo->slab;
660 #endif 663 #endif
661 if (target) 664 if (target)
662 StringToInt(tokens[1], target); 665 StringToInt(tokens[1], target);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 #if defined(OS_LINUX) 969 #if defined(OS_LINUX)
967 int ProcessMetrics::GetIdleWakeupsPerSecond() { 970 int ProcessMetrics::GetIdleWakeupsPerSecond() {
968 uint64_t wake_ups; 971 uint64_t wake_ups;
969 const char kWakeupStat[] = "se.statistics.nr_wakeups"; 972 const char kWakeupStat[] = "se.statistics.nr_wakeups";
970 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? 973 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ?
971 CalculateIdleWakeupsPerSecond(wake_ups) : 0; 974 CalculateIdleWakeupsPerSecond(wake_ups) : 0;
972 } 975 }
973 #endif // defined(OS_LINUX) 976 #endif // defined(OS_LINUX)
974 977
975 } // namespace base 978 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698