1 /* @(#)vedstats.c	1.9 18/09/19 Copyright 2000-2018 J. Schilling */
2 #include <schily/mconfig.h>
3 #ifndef lint
4 static	UConst char sccsid[] =
5 	"@(#)vedstats.c	1.9 18/09/19 Copyright 2000-2018 J. Schilling";
6 #endif
7 /*
8  *	Statistics module for VED (Visual EDitor)
9  *
10  *	Copyright (c) 2000-2018 J. Schilling
11  */
12 /*
13  * The contents of this file are subject to the terms of the
14  * Common Development and Distribution License, Version 1.0 only
15  * (the "License").  You may not use this file except in compliance
16  * with the License.
17  *
18  * See the file CDDL.Schily.txt in this distribution for details.
19  * A copy of the CDDL is also available via the Internet at
20  * http://www.opensource.org/licenses/cddl1.txt
21  *
22  * When distributing Covered Code, include this CDDL HEADER in each
23  * file and include the License file CDDL.Schily.txt from this distribution.
24  */
25 
26 #include "ved.h"
27 #include <schily/signal.h>
28 #include <schily/setjmp.h>
29 #include <schily/jmpdefs.h>
30 
31 EXPORT	long	charstyped;
32 
33 EXPORT	void	vedstartstats	__PR((void));
34 EXPORT	void	vedstopstats	__PR((void));
35 EXPORT	void	vedstatistics	__PR((void));
36 
37 #ifdef	VED_STATS
38 
39 #include <schily/limits.h>
40 #include <schily/time.h>
41 /*
42  * Make sure to include schily/time.h before, because of a Next Step bug.
43  */
44 /*#ifdef	HAVE_SYS_TIMES_H*/
45 #include <schily/times.h>
46 /*#endif*/
47 
48 #ifndef	CLK_TCK
49 #define	CLK_TCK	60
50 #endif
51 
52 #ifdef	HAVE_TIMES
53 LOCAL	struct tms	stms;
54 LOCAL	struct tms	etms;
55 #endif
56 
57 EXPORT void
vedstartstats()58 vedstartstats()
59 {
60 #ifdef	HAVE_TIMES
61 	times(&stms);
62 #endif
63 }
64 
65 EXPORT void
vedstopstats()66 vedstopstats()
67 {
68 #ifdef	HAVE_TIMES
69 	times(&etms);
70 #endif
71 }
72 
73 EXPORT void
vedstatistics()74 vedstatistics()
75 {
76 #ifdef	HAVE_TIMES
77 	struct tms	tms;
78 	long		usecs;
79 #endif
80 
81 	if (getenv("VED_STATISTICS") == NULL)
82 		return;
83 
84 #ifdef	HAVE_TIMES
85 	times(&tms);
86 
87 	error("input chars %ld\n", charstyped);
88 	usecs = 1000000 / CLK_TCK;
89 	usecs *= tms.tms_utime;
90 	error("user time %8ld �s %5ld �s/char\n",
91 		usecs, usecs/charstyped);
92 	usecs = 1000000 / CLK_TCK;
93 	usecs *= tms.tms_stime;
94 	error("sys  time %8ld �s %5ld �s/char\n",
95 		usecs, usecs/charstyped);
96 	usecs = 1000000 / CLK_TCK;
97 	usecs *= (tms.tms_utime + tms.tms_stime);
98 	error("sum  time %8ld �s %5ld �s/char\n",
99 		usecs, usecs/charstyped);
100 
101 	error("without load time:\n");
102 	tms.tms_utime -= stms.tms_utime;
103 	tms.tms_stime -= stms.tms_stime;
104 
105 	usecs = 1000000 / CLK_TCK;
106 	usecs *= tms.tms_utime;
107 	error("user time %8ld �s %5ld �s/char\n",
108 		usecs, usecs/charstyped);
109 	usecs = 1000000 / CLK_TCK;
110 	usecs *= tms.tms_stime;
111 	error("sys  time %8ld �s %5ld �s/char\n",
112 		usecs, usecs/charstyped);
113 	usecs = 1000000 / CLK_TCK;
114 	usecs *= (tms.tms_utime + tms.tms_stime);
115 	error("sum  time %8ld �s %5ld �s/char\n",
116 		usecs, usecs/charstyped);
117 
118 	error("without load/save time:\n");
119 	tms.tms_utime = etms.tms_utime - stms.tms_utime;
120 	tms.tms_stime = etms.tms_stime - stms.tms_stime;
121 
122 	usecs = 1000000 / CLK_TCK;
123 	usecs *= tms.tms_utime;
124 	error("user time %8ld �s %5ld �s/char\n",
125 		usecs, usecs/charstyped);
126 	usecs = 1000000 / CLK_TCK;
127 	usecs *= tms.tms_stime;
128 	error("sys  time %8ld �s %5ld �s/char\n",
129 		usecs, usecs/charstyped);
130 	usecs = 1000000 / CLK_TCK;
131 	usecs *= (tms.tms_utime + tms.tms_stime);
132 	error("sum  time %8ld �s %5ld �s/char\n",
133 		usecs, usecs/charstyped);
134 #endif
135 }
136 
137 #else
138 
139 EXPORT void
vedstartstats()140 vedstartstats()
141 {
142 }
143 
144 EXPORT void
vedstopstats()145 vedstopstats()
146 {
147 }
148 
149 EXPORT void
vedstatistics()150 vedstatistics()
151 {
152 }
153 
154 #endif	/* VED_STATS */
155