root/libswish3/trunk/src/libswish3/getruntime.c

Revision 2103, 2.9 kB (checked in by karpet, 8 months ago)

whitespace only. again.

I am now using gnu indent rather than the original bsd version. My opts are below:

--no-blank-lines-after-declarations
--blank-lines-after-procedures
--no-blank-lines-after-commas
--break-before-boolean-operator
//--break-function-decl-args
//--break-function-decl-args-end
// long options above do not work. use short below instead.
-bfda
-bfde
--braces-on-if-line
--brace-indent4
--braces-after-struct-decl-line
--dont-cuddle-else
--comment-delimiters-on-blank-lines
--else-endif-column1
--no-space-after-casts
--declaration-indentation4
--paren-indentation4
--dont-format-first-column-comments
--dont-format-comments
--ignore-newlines

--line-length80
--indent-level4
--parameter-indentation5
--continue-at-parentheses
--no-space-after-function-call-names
--no-space-after-parentheses
--procnames-start-lines
--space-after-for
--space-after-if
--space-after-while
--dont-star-comments
--swallow-optional-blank-lines
--no-tabs

-TxmlChar?
-Tswish_ParserData
-Tswish_Config
-Tswish_3
-Tswish_Analyzer
-Tswish_Parser
-Tswish_DocInfo
-Tswish_TagStack
-Tswish_MetaName
-Tswish_Property

Line 
1 /* Return time used so far, in microseconds.
2    Copyright (C) 1994, 1999 Free Software Foundation, Inc.
3
4 This file is part of the libiberty library.
5 Libiberty is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 Libiberty 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with libiberty; see the file COPYING.LIB.  If
17 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21 #include "acconfig.h"
22
23 /* For testing */
24 //
25 #undef HAVE_GETRUSAGE
26 //
27 #undef HAVE_SYS_RESOURCE_H
28 //
29 #undef HAVE_TIMES
30
31 /* There are several ways to get elapsed execution time; unfortunately no
32    single way is available for all host systems, nor are there reliable
33    ways to find out which way is correct for a given host. */
34
35 #include "getruntime.h"
36 #include <time.h>
37
38 #if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
39 #include <sys/time.h>
40 #include <sys/resource.h>
41 #endif
42
43 #ifdef HAVE_TIMES
44 #ifdef HAVE_SYS_PARAM_H
45 #include <sys/param.h>
46 #endif
47 #include <sys/times.h>
48 #endif
49
50 #ifdef HAVE_UNISTD_H
51 #include <unistd.h>
52 #endif
53
54 /* This is a fallback; if wrong, it will likely make obviously wrong
55    results. */
56
57 #ifndef CLOCKS_PER_SEC
58 #define CLOCKS_PER_SEC 1
59 #endif
60
61 #ifdef _SC_CLK_TCK
62 #define GNU_HZ  sysconf(_SC_CLK_TCK)
63 #else
64 #ifdef HZ
65 #define GNU_HZ  HZ
66 #else
67 #ifdef CLOCKS_PER_SEC
68 #define GNU_HZ  CLOCKS_PER_SEC
69 #endif
70 #endif
71 #endif
72
73 cpu_seconds
74 get_cpu_secs(
75 )
76 {
77 #if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
78     struct rusage rusage;
79     cpu_seconds secs;
80
81     getrusage(0, &rusage);
82     secs = (cpu_seconds) (rusage.ru_utime.tv_sec + rusage.ru_stime.tv_sec);
83
84     if (rusage.ru_utime.tv_usec > 500000)
85         secs++;
86     if (rusage.ru_stime.tv_usec > 500000)
87         secs++;
88
89     return secs;
90
91 #else /* ! HAVE_GETRUSAGE */
92 #ifdef HAVE_TIMES
93
94 /* This returns number of clock "ticks" since: */
95 /* In linux since boot, in BSD since 1/1/1970 */
96 /* Again, these are clock_t, which may overflow, but under linux it's 1/100 second so about 6000 hours */
97
98     struct tms tms;
99
100     times(&tms);
101
102     return (cpu_seconds) ((tms.tms_utime + tms.tms_stime) / GNU_HZ);
103
104 #else /* ! HAVE_TIMES */
105 /* Fall back on clock and hope it's correctly implemented. */
106 /* clock() returns clock_t, which seems to be a long.  On Linux CLOCKS_PER_SEC is 10^6 */
107 /* so expect an overflow at about 35 minutes. */
108
109     clock_t t = clock();
110     if (t < 0)
111         t = 0;
112
113     return (cpu_seconds) (t / CLOCKS_PER_SEC);
114
115 #endif /* HAVE_TIMES */
116 #endif /* HAVE_GETRUSAGE */
117 }
Note: See TracBrowser for help on using the browser.