2 Gathering run-time statistics
5 /* $Id: tally.c,v 2.2 1994/06/24 10:49:19 ceriel Exp $ */
13 struct line_tally { /* one for each line */
14 long lt_cnt; /* counts entrances */
15 long lt_instr; /* counts instructions */
18 struct file_tally { /* one for each file */
19 struct file_tally *next;
20 ptr ft_fil; /* file name */
21 long ft_limit; /* size of line array */
22 struct line_tally *ft_line; /* pointer to line array */
25 PRIVATE struct file_tally *first_tally; /* start of chain */
26 PRIVATE struct file_tally *file; /* present file */
30 PRIVATE tally_newFIL();
38 if (!file || FIL != file->ft_fil) {
44 if (LIN >= file->ft_limit) {
47 file->ft_line[LIN].lt_cnt++;
50 file->ft_line[LIN].lt_instr++;
53 PRIVATE tally_newFIL(f)
56 struct file_tally **hook = &first_tally;
59 if ((*hook)->ft_fil == f)
61 hook = &(*hook)->next;
64 /* first time we see this file */
65 /* construct a new entry */
66 struct file_tally *nt = (struct file_tally *)
67 Malloc((size) sizeof (struct file_tally), "file_tally");
69 nt->next = (struct file_tally *)0;
71 nt->ft_limit = 1; /* provisional length */
72 nt->ft_line = (struct line_tally *)
73 Malloc((size) sizeof (struct line_tally),
75 nt->ft_line[0].lt_cnt = 0;
76 nt->ft_line[0].lt_instr = 0;
84 PRIVATE enlarge(ft, l)
85 struct file_tally *ft;
88 long limit = allocfrac(l < 100 ? 100 : l);
90 if (limit <= ft->ft_limit)
92 ft->ft_line = (struct line_tally *)
93 Realloc((char *)ft->ft_line,
94 (size)(limit*sizeof (struct line_tally)),
96 while (ft->ft_limit < limit) {
97 ft->ft_line[ft->ft_limit].lt_cnt = 0;
98 ft->ft_line[ft->ft_limit].lt_instr = 0;
103 PRIVATE FILE *tally_fp;
107 struct file_tally **hook = &first_tally;
112 tally_fp = fopen("int.tally", "w");
117 struct file_tally *ft = *hook;
120 fprintf(tally_fp, "%s:\n", dt_fname(ft->ft_fil));
121 for (i = 0; i < ft->ft_limit; i++) {
122 struct line_tally *lt = &ft->ft_line[i];
125 /* we visited this line */
126 fprintf(tally_fp, "\t%ld\t%ld\t%ld\n",
127 i, lt->lt_cnt, lt->lt_instr);
130 fprintf(tally_fp, "\n");
131 hook = &(*hook)->next;