summaryrefslogtreecommitdiffstats
path: root/base/process_info_mac.cc
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-19 17:43:31 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-19 17:43:31 +0000
commit843bc46d19e445e0f29abdd8113988b52e6f5990 (patch)
tree1e5c86d00420ffb71289da31e3832ea867b321ed /base/process_info_mac.cc
parent9782f9a248619b96df51b833e4b542146659b442 (diff)
downloadchromium_src-843bc46d19e445e0f29abdd8113988b52e6f5990.zip
chromium_src-843bc46d19e445e0f29abdd8113988b52e6f5990.tar.gz
chromium_src-843bc46d19e445e0f29abdd8113988b52e6f5990.tar.bz2
Consolidate RecordBrowserStartupTime() into one location
* Create a CurrentProcessInfo class as a central storage place for information about the current process. For now store the process creation time there. * Move RecordBrowserStartupTime() int browser_main.cc. The motivation for this is that we will want to add some more UMA measurements which require knowledge of the process startup time. BUG=None Test=Chrome should continue to compile on all platforms. TEST= Review URL: https://chromiumcodereview.appspot.com/10561009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142984 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_info_mac.cc')
-rw-r--r--base/process_info_mac.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/base/process_info_mac.cc b/base/process_info_mac.cc
new file mode 100644
index 0000000..247a144
--- /dev/null
+++ b/base/process_info_mac.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/process_info.h"
+
+#include <sys/sysctl.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time.h"
+
+namespace {
+
+using base::Time;
+
+// Returns the process creation time, or NULL if an error occurred.
+Time* ProcessCreationTimeInternal() {
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
+ size_t len = 0;
+ if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) < 0)
+ return NULL;
+
+ scoped_ptr_malloc<struct kinfo_proc>
+ proc(static_cast<struct kinfo_proc*>(malloc(len)));
+ if (sysctl(mib, arraysize(mib), proc.get(), &len, NULL, 0) < 0)
+ return NULL;
+ return new Time(Time::FromTimeVal(proc->kp_proc.p_un.__p_starttime));
+}
+
+} // namespace
+
+namespace base {
+
+//static
+const Time* CurrentProcessInfo::CreationTime() {
+ static Time* process_creation_time = ProcessCreationTimeInternal();
+ return process_creation_time;
+}
+
+} // namespace base