| OLD | NEW |
| 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/process_info.h" | 5 #include "base/process/process_info.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <sys/sysctl.h> | 8 #include <sys/sysctl.h> |
| 9 #include <sys/time.h> | 9 #include <sys/time.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/free_deleter.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 | 18 |
| 18 // static | 19 // static |
| 19 const Time CurrentProcessInfo::CreationTime() { | 20 const Time CurrentProcessInfo::CreationTime() { |
| 20 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() }; | 21 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() }; |
| 21 size_t len = 0; | 22 size_t len = 0; |
| 22 if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) < 0) | 23 if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) < 0) |
| 23 return Time(); | 24 return Time(); |
| 24 | 25 |
| 25 scoped_ptr<struct kinfo_proc, base::FreeDeleter> | 26 scoped_ptr<struct kinfo_proc, base::FreeDeleter> |
| 26 proc(static_cast<struct kinfo_proc*>(malloc(len))); | 27 proc(static_cast<struct kinfo_proc*>(malloc(len))); |
| 27 if (sysctl(mib, arraysize(mib), proc.get(), &len, NULL, 0) < 0) | 28 if (sysctl(mib, arraysize(mib), proc.get(), &len, NULL, 0) < 0) |
| 28 return Time(); | 29 return Time(); |
| 29 return Time::FromTimeVal(proc->kp_proc.p_un.__p_starttime); | 30 return Time::FromTimeVal(proc->kp_proc.p_un.__p_starttime); |
| 30 } | 31 } |
| 31 | 32 |
| 32 } // namespace base | 33 } // namespace base |
| OLD | NEW |