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 // Returns the process creation time, or a null time object if an error | |
| 20 // occurred. | |
| 21 Time ProcessCreationTimeInternal() { | |
| 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 Time(); | |
| 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 Time(); | |
| 31 return Time::FromTimeVal(proc->kp_proc.p_un.__p_starttime); | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 namespace base { | |
| 37 | |
| 38 //static | |
| 39 const Time* CurrentProcessInfo::CreationTime() { | |
| 40 static Time process_creation_time = ProcessCreationTimeInternal(); | |
|
Mark Mentovai
2012/06/19 16:08:00
Did “new Time()” and using the Time* interface to
| |
| 41 return &process_creation_time; | |
| 42 } | |
| 43 | |
| 44 } // namespace base | |
| OLD | NEW |