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

Side by Side Diff: base/process_info_mac.cc

Issue 10561009: Consolidate RecordBrowserStartupTime() into one location (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Make getter thread-safe Created 8 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/process_info.h"
6
7 #include <sys/sysctl.h>
8 #include <sys/time.h>
9 #include <unistd.h>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time.h"
14
15 namespace {
16
17 using base::Time;
18
19 // Retrieve the process creation time in |process_creation_time|, returns
20 // true on success.
21 bool ProcessCreationTimeInternal(Time* process_creation_time) {
22 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
23 size_t len = 0;
24 if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) < 0)
25 return false;
26
27 scoped_ptr_malloc<struct kinfo_proc>
28 proc(static_cast<struct kinfo_proc*>(malloc(len)));
29 if (sysctl(mib, arraysize(mib), proc.get(), &len, NULL, 0) < 0)
30 return false;
31 *process_creation_time =
Mark Mentovai 2012/06/19 15:47:08 Can you clean this up and get rid of the second st
32 base::Time::FromTimeVal(proc->kp_proc.p_un.__p_starttime);
Mark Mentovai 2012/06/19 15:47:08 Is the base:: qualifier necessary, since you’re us
33 return true;
34 }
35
36 } // namespace
37
38 namespace base {
39
40 //static
41 const Time* CurrentProcessInfo::CreationTime() {
42 static Time process_creation_time;
43 static bool success = ProcessCreationTimeInternal(&process_creation_time);
Mark Mentovai 2012/06/19 15:47:08 These are the two statics I’m talking about. You o
44
45 if (!success)
46 return NULL;
47 return &process_creation_time;
48 }
49
50 } // namespace base
OLDNEW
« no previous file with comments | « base/process_info.h ('k') | base/process_info_win.cc » ('j') | base/process_info_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698