1 /* Return CPU and real time used by process and its children. Hurd version.
2 Copyright (C) 2001,2002,2003,2004 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
;
36 /* Store the CPU time used by this process and all its
37 dead children (and their dead children) in BUFFER.
38 Return the elapsed real time, or (clock_t) -1 for errors.
39 All times are in CLK_TCKths of a second. */
41 __times (struct tms
*tms
)
43 struct task_basic_info bi
;
44 struct task_thread_times_info tti
;
45 mach_msg_type_number_t count
;
46 union { time_value_t tvt
; struct timeval tv
; } now
;
49 count
= TASK_BASIC_INFO_COUNT
;
50 err
= __task_info (__mach_task_self (), TASK_BASIC_INFO
,
51 (task_info_t
) &bi
, &count
);
53 return __hurd_fail (err
);
55 count
= TASK_THREAD_TIMES_INFO_COUNT
;
56 err
= __task_info (__mach_task_self (), TASK_THREAD_TIMES_INFO
,
57 (task_info_t
) &tti
, &count
);
59 return __hurd_fail (err
);
61 tms
->tms_utime
= (clock_from_time_value (&bi
.user_time
)
62 + clock_from_time_value (&tti
.user_time
));
63 tms
->tms_stime
= (clock_from_time_value (&bi
.system_time
)
64 + clock_from_time_value (&tti
.system_time
));
66 /* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be. */
67 tms
->tms_cutime
= tms
->tms_cstime
= 0;
69 if (__gettimeofday (&now
.tv
, NULL
) < 0)
72 return (clock_from_time_value (&now
.tvt
)
73 - clock_from_time_value (&bi
.creation_time
));
75 weak_alias (__times
, times
)