xref: /Universal-ctags/main/stats.c (revision 288a2fd5bcfd4c89f5015b2d1736160485504fb8)
1 /*
2 *   Copyright (c) 1996-2003, Darren Hiebert
3 *
4 *   Author: Darren Hiebert <dhiebert@users.sourceforge.net>
5 *           http://ctags.sourceforge.net
6 *
7 *   This source code is released for free distribution under the terms of the
8 *   GNU General Public License version 2 or (at your option) any later version.
9 *   It is provided on an as-is basis and no responsibility is accepted for its
10 *   failure to perform as expected.
11 */
12 
13 /*
14 *   INCLUDE FILES
15 */
16 #include "general.h"  /* must always come first */
17 
18 #include <stdio.h>
19 
20 #include "entry_p.h"
21 #include "options_p.h"
22 #include "stats_p.h"
23 
24 /*
25 *   MACROS
26 */
27 #define plural(value)  (((unsigned long)(value) == 1L) ? "" : "s")
28 
29 /*
30 *   DATA DEFINITIONS
31 */
32 static struct { long files, lines, bytes; } Totals = { 0, 0, 0 };
33 
34 
35 /*
36 *   FUNCTION DEFINITIONS
37 */
addTotals(const unsigned int files,const long unsigned int lines,const long unsigned int bytes)38 extern void addTotals (
39 		const unsigned int files, const long unsigned int lines,
40 		const long unsigned int bytes)
41 {
42 	Totals.files += files;
43 	Totals.lines += lines;
44 	Totals.bytes += bytes;
45 }
46 
printTotals(const clock_t * const timeStamps,bool append,sortType sorted)47 extern void printTotals (const clock_t *const timeStamps, bool append, sortType sorted)
48 {
49 	const unsigned long totalTags = numTagsTotal();
50 	const unsigned long addedTags = numTagsAdded();
51 
52 	fprintf (stderr, "%ld file%s, %ld line%s (%ld kB) scanned",
53 			Totals.files, plural (Totals.files),
54 			Totals.lines, plural (Totals.lines),
55 			Totals.bytes/1024L);
56 
57 	const double interval = ((double) (timeStamps [1] - timeStamps [0])) /
58 							CLOCKS_PER_SEC;
59 
60 	fprintf (stderr, " in %.01f seconds", interval);
61 	if (interval != (double) 0.0)
62 		fprintf (stderr, " (%lu kB/s)",
63 				(unsigned long) (Totals.bytes / interval) / 1024L);
64 
65 	fputc ('\n', stderr);
66 
67 	fprintf (stderr, "%lu tag%s added to tag file",
68 			addedTags, plural(addedTags));
69 	if (append)
70 		fprintf (stderr, " (now %lu tags)", totalTags);
71 	fputc ('\n', stderr);
72 
73 	if (totalTags > 0  &&  sorted != SO_UNSORTED)
74 	{
75 		fprintf (stderr, "%lu tag%s sorted", totalTags, plural (totalTags));
76 		fprintf (stderr, " in %.02f seconds",
77 				((double) (timeStamps [2] - timeStamps [1])) / CLOCKS_PER_SEC);
78 		fputc ('\n', stderr);
79 	}
80 
81 #ifdef DEBUG
82 	fprintf (stderr, "longest tag line = %lu\n",
83 		 (unsigned long) maxTagsLine ());
84 #endif
85 }
86