Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| OLD | NEW |