Back to index

glibc  2.9
clock.c
Go to the documentation of this file.
00001 /* Return the CPU time used by the program so far.  Hurd version.
00002    Copyright (C) 2001 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <time.h>
00021 #include <sys/time.h>
00022 #include <mach.h>
00023 #include <mach/task_info.h>
00024 #include <hurd.h>
00025 
00026 /* Return the time used by the program so far (user time + system time).  */
00027 clock_t
00028 clock (void)
00029 {
00030   struct task_basic_info bi;
00031   struct task_thread_times_info tti;
00032   mach_msg_type_number_t count;
00033   clock_t total;
00034   error_t err;
00035 
00036   count = TASK_BASIC_INFO_COUNT;
00037   err = __task_info (__mach_task_self (), TASK_BASIC_INFO,
00038                    (task_info_t) &bi, &count);
00039   if (err)
00040     return __hurd_fail (err);
00041 
00042   count = TASK_THREAD_TIMES_INFO_COUNT;
00043   err = __task_info (__mach_task_self (), TASK_THREAD_TIMES_INFO,
00044                    (task_info_t) &tti, &count);
00045   if (err)
00046     return __hurd_fail (err);
00047 
00048   total = bi.user_time.seconds * 1000000 + bi.user_time.microseconds;
00049   total += tti.user_time.seconds * 1000000 + tti.user_time.microseconds;
00050   total += bi.system_time.seconds * 1000000 + bi.system_time.microseconds;
00051   total += tti.system_time.seconds * 1000000 + tti.system_time.microseconds;
00052 
00053   return total;
00054 }