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

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

Issue 2715583002: base/process: Use /proc/self/stat to read startup time. (Closed)
Patch Set: Address jln comments. 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
« no previous file with comments | « base/process/internal_linux.h ('k') | base/process/process_info_linux.cc » ('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 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/internal_linux.h" 5 #include "base/process/internal_linux.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 size_t GetProcStatsFieldAsSizeT(const std::vector<std::string>& proc_stats, 127 size_t GetProcStatsFieldAsSizeT(const std::vector<std::string>& proc_stats,
128 ProcStatsFields field_num) { 128 ProcStatsFields field_num) {
129 DCHECK_GE(field_num, VM_PPID); 129 DCHECK_GE(field_num, VM_PPID);
130 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); 130 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size());
131 131
132 size_t value; 132 size_t value;
133 return StringToSizeT(proc_stats[field_num], &value) ? value : 0; 133 return StringToSizeT(proc_stats[field_num], &value) ? value : 0;
134 } 134 }
135 135
136 int64_t ReadProcStatsAndGetFieldAsInt64(pid_t pid, ProcStatsFields field_num) { 136 int64_t ReadStatFileAndGetFieldAsInt64(const FilePath& stat_file,
137 ProcStatsFields field_num) {
137 std::string stats_data; 138 std::string stats_data;
138 if (!ReadProcStats(pid, &stats_data)) 139 if (!ReadProcFile(stat_file, &stats_data))
139 return 0; 140 return 0;
140 std::vector<std::string> proc_stats; 141 std::vector<std::string> proc_stats;
141 if (!ParseProcStats(stats_data, &proc_stats)) 142 if (!ParseProcStats(stats_data, &proc_stats))
142 return 0; 143 return 0;
143 return GetProcStatsFieldAsInt64(proc_stats, field_num); 144 return GetProcStatsFieldAsInt64(proc_stats, field_num);
144 } 145 }
145 146
147 int64_t ReadProcStatsAndGetFieldAsInt64(pid_t pid, ProcStatsFields field_num) {
148 FilePath stat_file = internal::GetProcPidDir(pid).Append(kStatFile);
149 return ReadStatFileAndGetFieldAsInt64(stat_file, field_num);
150 }
151
152 int64_t ReadProcSelfStatsAndGetFieldAsInt64(ProcStatsFields field_num) {
153 FilePath stat_file = FilePath(kProcDir).Append("self").Append(kStatFile);
154 return ReadStatFileAndGetFieldAsInt64(stat_file, field_num);
155 }
156
146 size_t ReadProcStatsAndGetFieldAsSizeT(pid_t pid, 157 size_t ReadProcStatsAndGetFieldAsSizeT(pid_t pid,
147 ProcStatsFields field_num) { 158 ProcStatsFields field_num) {
148 std::string stats_data; 159 std::string stats_data;
149 if (!ReadProcStats(pid, &stats_data)) 160 if (!ReadProcStats(pid, &stats_data))
150 return 0; 161 return 0;
151 std::vector<std::string> proc_stats; 162 std::vector<std::string> proc_stats;
152 if (!ParseProcStats(stats_data, &proc_stats)) 163 if (!ParseProcStats(stats_data, &proc_stats))
153 return 0; 164 return 0;
154 return GetProcStatsFieldAsSizeT(proc_stats, field_num); 165 return GetProcStatsFieldAsSizeT(proc_stats, field_num);
155 } 166 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // which means the answer is 100. 217 // which means the answer is 100.
207 // It may be the case that this value is always 100. 218 // It may be the case that this value is always 100.
208 static const int kHertz = sysconf(_SC_CLK_TCK); 219 static const int kHertz = sysconf(_SC_CLK_TCK);
209 220
210 return TimeDelta::FromMicroseconds( 221 return TimeDelta::FromMicroseconds(
211 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); 222 Time::kMicrosecondsPerSecond * clock_ticks / kHertz);
212 } 223 }
213 224
214 } // namespace internal 225 } // namespace internal
215 } // namespace base 226 } // namespace base
OLDNEW
« no previous file with comments | « base/process/internal_linux.h ('k') | base/process/process_info_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698