xref: /aosp_15_r20/external/libchrome/base/process/process_info_linux.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2013 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #include "base/process/process_info.h"
6*635a8641SAndroid Build Coastguard Worker 
7*635a8641SAndroid Build Coastguard Worker #include <stdint.h>
8*635a8641SAndroid Build Coastguard Worker 
9*635a8641SAndroid Build Coastguard Worker #include "base/logging.h"
10*635a8641SAndroid Build Coastguard Worker #include "base/process/internal_linux.h"
11*635a8641SAndroid Build Coastguard Worker #include "base/process/process_handle.h"
12*635a8641SAndroid Build Coastguard Worker #include "base/time/time.h"
13*635a8641SAndroid Build Coastguard Worker 
14*635a8641SAndroid Build Coastguard Worker namespace base {
15*635a8641SAndroid Build Coastguard Worker 
16*635a8641SAndroid Build Coastguard Worker // static
CreationTime()17*635a8641SAndroid Build Coastguard Worker const Time CurrentProcessInfo::CreationTime() {
18*635a8641SAndroid Build Coastguard Worker   int64_t start_ticks =
19*635a8641SAndroid Build Coastguard Worker       internal::ReadProcSelfStatsAndGetFieldAsInt64(internal::VM_STARTTIME);
20*635a8641SAndroid Build Coastguard Worker   if (!start_ticks)
21*635a8641SAndroid Build Coastguard Worker     return Time();
22*635a8641SAndroid Build Coastguard Worker   TimeDelta start_offset = internal::ClockTicksToTimeDelta(start_ticks);
23*635a8641SAndroid Build Coastguard Worker   Time boot_time = internal::GetBootTime();
24*635a8641SAndroid Build Coastguard Worker   if (boot_time.is_null())
25*635a8641SAndroid Build Coastguard Worker     return Time();
26*635a8641SAndroid Build Coastguard Worker   return Time(boot_time + start_offset);
27*635a8641SAndroid Build Coastguard Worker }
28*635a8641SAndroid Build Coastguard Worker 
29*635a8641SAndroid Build Coastguard Worker }  // namespace base
30