1 /* Return CPU and real time used by process and its children. Hurd version.
2 Copyright (C) 2001,02 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <sys/resource.h>
23 #include <sys/times.h>
27 #include <mach/task_info.h>
31 clock_from_time_value (const time_value_t
*t
)
33 return t
->seconds
* 1000000 + t
->microseconds
;
37 static time_value_t startup_time
;
38 static void times_init (void) __attribute__ ((unused
));
42 __gettimeofday ((struct timeval
*) &startup_time
, NULL
);
44 text_set_element (__libc_subinit
, times_init
);
47 /* Store the CPU time used by this process and all its
48 dead children (and their dead children) in BUFFER.
49 Return the elapsed real time, or (clock_t) -1 for errors.
50 All times are in CLK_TCKths of a second. */
52 __times (struct tms
*tms
)
54 struct task_basic_info bi
;
55 struct task_thread_times_info tti
;
56 mach_msg_type_number_t count
;
60 count
= TASK_BASIC_INFO_COUNT
;
61 err
= __task_info (__mach_task_self (), TASK_BASIC_INFO
,
62 (task_info_t
) &bi
, &count
);
64 return __hurd_fail (err
);
66 count
= TASK_THREAD_TIMES_INFO_COUNT
;
67 err
= __task_info (__mach_task_self (), TASK_THREAD_TIMES_INFO
,
68 (task_info_t
) &tti
, &count
);
70 return __hurd_fail (err
);
72 tms
->tms_utime
= (clock_from_time_value (&bi
.user_time
)
73 + clock_from_time_value (&tti
.user_time
));
74 tms
->tms_stime
= (clock_from_time_value (&bi
.system_time
)
75 + clock_from_time_value (&tti
.system_time
));
77 /* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be. */
78 tms
->tms_cutime
= tms
->tms_cstime
= 0;
80 if (__gettimeofday ((struct timeval
*) &now
, NULL
) < 0)
84 # define our_creation_time startup_time
86 # define our_creation_time bi.startup_time
88 return (clock_from_time_value (&now
)
89 - clock_from_time_value (&our_creation_time
));
91 weak_alias (__times
, times
)