cc: Convert some LTHCommon tests from Layer->LayerImpl
[chromium-blink-merge.git] / base / process / process_info_mac.cc
blobb7cfdceda0505bd9306b4f02d5d28df76cb48a5e
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.
5 #include "base/process/process_info.h"
7 #include <sys/sysctl.h>
8 #include <sys/time.h>
9 #include <unistd.h>
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
15 namespace base {
17 //static
18 const Time CurrentProcessInfo::CreationTime() {
19 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
20 size_t len = 0;
21 if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) < 0)
22 return Time();
24 scoped_ptr<struct kinfo_proc, base::FreeDeleter>
25 proc(static_cast<struct kinfo_proc*>(malloc(len)));
26 if (sysctl(mib, arraysize(mib), proc.get(), &len, NULL, 0) < 0)
27 return Time();
28 return Time::FromTimeVal(proc->kp_proc.p_un.__p_starttime);
31 } // namespace base