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

Side by Side Diff: runtime/bin/process_linux.cc

Issue 2994223002: Restore "Add current rss and embedder name to Observatory" (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « runtime/bin/process_android.cc ('k') | runtime/include/dart_tools_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #if !defined(DART_IO_DISABLED) 5 #if !defined(DART_IO_DISABLED)
6 6
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #if defined(HOST_OS_LINUX) 8 #if defined(HOST_OS_LINUX)
9 9
10 #include "bin/process.h" 10 #include "bin/process.h"
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 } 853 }
854 854
855 void Process::TerminateExitCodeHandler() { 855 void Process::TerminateExitCodeHandler() {
856 ExitCodeHandler::TerminateExitCodeThread(); 856 ExitCodeHandler::TerminateExitCodeThread();
857 } 857 }
858 858
859 intptr_t Process::CurrentProcessId() { 859 intptr_t Process::CurrentProcessId() {
860 return static_cast<intptr_t>(getpid()); 860 return static_cast<intptr_t>(getpid());
861 } 861 }
862 862
863 static void SaveErrorAndClose(FILE* file) {
864 int actual_errno = errno;
865 fclose(file);
866 errno = actual_errno;
867 }
868
863 int64_t Process::CurrentRSS() { 869 int64_t Process::CurrentRSS() {
864 // The second value in /proc/self/statm is the current RSS in pages. 870 // The second value in /proc/self/statm is the current RSS in pages.
865 File* statm = File::Open("/proc/self/statm", File::kRead); 871 // It is not possible to use getrusage() because the interested fields are not
872 // implemented by the linux kernel.
873 FILE* statm = fopen("/proc/self/statm", "r");
866 if (statm == NULL) { 874 if (statm == NULL) {
867 return -1; 875 return -1;
868 } 876 }
869 RefCntReleaseScope<File> releaser(statm); 877 int64_t current_rss_pages = 0;
870 const intptr_t statm_length = 1 * KB; 878 int matches = fscanf(statm, "%*s%" Pd64 "", &current_rss_pages);
871 void* buffer = reinterpret_cast<void*>(Dart_ScopeAllocate(statm_length)); 879 if (matches != 1) {
872 const intptr_t statm_read = statm->Read(buffer, statm_length); 880 SaveErrorAndClose(statm);
873 if (statm_read <= 0) {
874 return -1; 881 return -1;
875 } 882 }
876 int64_t current_rss_pages = 0; 883 fclose(statm);
877 int matches = sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pd64 "",
878 &current_rss_pages);
879 if (matches != 1) {
880 return -1;
881 }
882 return current_rss_pages * getpagesize(); 884 return current_rss_pages * getpagesize();
883 } 885 }
884 886
885 int64_t Process::MaxRSS() { 887 int64_t Process::MaxRSS() {
886 struct rusage usage; 888 struct rusage usage;
887 usage.ru_maxrss = 0; 889 usage.ru_maxrss = 0;
888 int r = getrusage(RUSAGE_SELF, &usage); 890 int r = getrusage(RUSAGE_SELF, &usage);
889 if (r < 0) { 891 if (r < 0) {
890 return -1; 892 return -1;
891 } 893 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 sigaction(signal, &act, NULL); 999 sigaction(signal, &act, NULL);
998 } 1000 }
999 } 1001 }
1000 1002
1001 } // namespace bin 1003 } // namespace bin
1002 } // namespace dart 1004 } // namespace dart
1003 1005
1004 #endif // defined(HOST_OS_LINUX) 1006 #endif // defined(HOST_OS_LINUX)
1005 1007
1006 #endif // !defined(DART_IO_DISABLED) 1008 #endif // !defined(DART_IO_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/process_android.cc ('k') | runtime/include/dart_tools_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698