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

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

Issue 2715583002: base/process: Use /proc/self/stat to read startup time. (Closed)
Patch Set: 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) 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(const std::string& pid,
137 ProcStatsFields field_num) {
138 std::string stats_data;
139 FilePath stat_file = FilePath(kProcDir).Append(pid).Append(kStatFile);
140 if (!ReadProcFile(stat_file, &stats_data))
141 return 0;
142 std::vector<std::string> proc_stats;
jln (very slow on Chromium) 2017/02/22 22:37:15 A little too much code duplication here. Perhaps r
Daniele Castagna 2017/02/23 18:04:10 Done.
143 if (!ParseProcStats(stats_data, &proc_stats))
144 return 0;
145 return GetProcStatsFieldAsInt64(proc_stats, field_num);
146 }
147
136 int64_t ReadProcStatsAndGetFieldAsInt64(pid_t pid, ProcStatsFields field_num) { 148 int64_t ReadProcStatsAndGetFieldAsInt64(pid_t pid, ProcStatsFields field_num) {
137 std::string stats_data; 149 std::string stats_data;
138 if (!ReadProcStats(pid, &stats_data)) 150 if (!ReadProcStats(pid, &stats_data))
139 return 0; 151 return 0;
140 std::vector<std::string> proc_stats; 152 std::vector<std::string> proc_stats;
141 if (!ParseProcStats(stats_data, &proc_stats)) 153 if (!ParseProcStats(stats_data, &proc_stats))
142 return 0; 154 return 0;
143 return GetProcStatsFieldAsInt64(proc_stats, field_num); 155 return GetProcStatsFieldAsInt64(proc_stats, field_num);
144 } 156 }
145 157
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // which means the answer is 100. 218 // which means the answer is 100.
207 // It may be the case that this value is always 100. 219 // It may be the case that this value is always 100.
208 static const int kHertz = sysconf(_SC_CLK_TCK); 220 static const int kHertz = sysconf(_SC_CLK_TCK);
209 221
210 return TimeDelta::FromMicroseconds( 222 return TimeDelta::FromMicroseconds(
211 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); 223 Time::kMicrosecondsPerSecond * clock_ticks / kHertz);
212 } 224 }
213 225
214 } // namespace internal 226 } // namespace internal
215 } // namespace base 227 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698