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

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

Issue 1526253003: Linux: Correctly count the number of open file descriptors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years 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/files/dir_reader_linux.h ('k') | base/process/process_metrics_unittest.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) 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 <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/time.h> 10 #include <sys/time.h>
11 #include <sys/types.h> 11 #include <sys/types.h>
12 #include <unistd.h> 12 #include <unistd.h>
13 #include <utility> 13 #include <utility>
14 14
15 #include "base/files/dir_reader_posix.h"
15 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/process/internal_linux.h" 18 #include "base/process/internal_linux.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
20 #include "base/strings/string_tokenizer.h" 21 #include "base/strings/string_tokenizer.h"
21 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
22 #include "base/sys_info.h" 23 #include "base/sys_info.h"
23 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
24 25
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 DCHECK(converted); 285 DCHECK(converted);
285 } 286 }
286 return true; 287 return true;
287 } 288 }
288 289
289 #if defined(OS_LINUX) 290 #if defined(OS_LINUX)
290 int ProcessMetrics::GetOpenFdCount() const { 291 int ProcessMetrics::GetOpenFdCount() const {
291 // Use /proc/<pid>/fd to count the number of entries there. 292 // Use /proc/<pid>/fd to count the number of entries there.
292 FilePath fd_path = internal::GetProcPidDir(process_).Append("fd"); 293 FilePath fd_path = internal::GetProcPidDir(process_).Append("fd");
293 294
294 DIR* dir = opendir(fd_path.value().c_str()); 295 DirReaderPosix dir_reader(fd_path.value().c_str());
295 if (!dir) { 296 if (!dir_reader.IsValid())
296 DPLOG(ERROR) << "opendir(" << fd_path.value() << ")";
297 return -1; 297 return -1;
298 }
299 298
300 int total_count = 0; 299 int total_count = 0;
301 while (readdir(dir)) 300 for (; dir_reader.Next(); ) {
302 ++total_count; 301 const char* name = dir_reader.name();
303 302 if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0)
304 closedir(dir); 303 ++total_count;
304 }
305 305
306 return total_count; 306 return total_count;
307 } 307 }
308 #endif // defined(OS_LINUX) 308 #endif // defined(OS_LINUX)
309 309
310 ProcessMetrics::ProcessMetrics(ProcessHandle process) 310 ProcessMetrics::ProcessMetrics(ProcessHandle process)
311 : process_(process), 311 : process_(process),
312 last_system_time_(0), 312 last_system_time_(0),
313 #if defined(OS_LINUX) 313 #if defined(OS_LINUX)
314 last_absolute_idle_wakeups_(0), 314 last_absolute_idle_wakeups_(0),
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 #if defined(OS_LINUX) 937 #if defined(OS_LINUX)
938 int ProcessMetrics::GetIdleWakeupsPerSecond() { 938 int ProcessMetrics::GetIdleWakeupsPerSecond() {
939 uint64 wake_ups; 939 uint64 wake_ups;
940 const char kWakeupStat[] = "se.statistics.nr_wakeups"; 940 const char kWakeupStat[] = "se.statistics.nr_wakeups";
941 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? 941 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ?
942 CalculateIdleWakeupsPerSecond(wake_ups) : 0; 942 CalculateIdleWakeupsPerSecond(wake_ups) : 0;
943 } 943 }
944 #endif // defined(OS_LINUX) 944 #endif // defined(OS_LINUX)
945 945
946 } // namespace base 946 } // namespace base
OLDNEW
« no previous file with comments | « base/files/dir_reader_linux.h ('k') | base/process/process_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698