Add test about issue with no commit on a branch
[cvsps-hv.git] / stats.c
blob0276a50e196dbf8ac4d481800cd84214eff161ea
1 /*
2 * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
3 * See COPYING file for license information
4 */
6 #include <stdio.h>
7 #include <string.h>
8 #include <search.h>
9 #include <cbtcommon/hash.h>
11 #include "cvsps_types.h"
12 #include "cvsps.h"
14 static unsigned int num_patch_sets = 0;
15 static unsigned int num_ps_member = 0, max_ps_member_in_ps = 0;
16 static unsigned int num_authors = 0, max_author_len = 0, total_author_len = 0;
17 static unsigned int max_descr_len = 0, total_descr_len = 0;
18 struct hash_table *author_hash;
20 static void count_hash(struct hash_table *hash, unsigned int *total,
21 unsigned int *max_val)
23 int counter = 0;
24 struct hash_entry *fh;
26 reset_hash_iterator(hash);
27 while ((fh = next_hash_entry(hash)))
28 counter++;
30 *total += counter;
31 *max_val= MAX(*max_val, counter);
34 static void stat_ps_tree_node(const void * nodep, const VISIT which, const int depth)
36 int desc_len;
37 PatchSet * ps;
38 struct list_head * next;
39 int counter;
40 void * old;
42 /* Make sure we have it if we do statistics */
43 if (!author_hash)
44 author_hash = create_hash_table(1023);
46 switch(which)
48 case postorder:
49 case leaf:
50 ps = *(PatchSet**)nodep;
51 num_patch_sets++;
53 old = NULL;
55 /* Author statistics */
56 if (put_hash_object_ex(author_hash, ps->author, ps->author, HT_NO_KEYCOPY, NULL, &old) >= 0 && !old)
58 int len = strlen(ps->author);
59 num_authors++;
60 max_author_len = MAX(max_author_len, len);
61 total_author_len += len;
64 /* Log message statistics */
65 desc_len = strlen(ps->descr);
66 max_descr_len = MAX(max_descr_len, desc_len);
67 total_descr_len += desc_len;
69 /* PatchSet member statistics */
70 counter = 0;
71 next = ps->members.next;
72 while (next != &ps->members)
74 counter++;
75 next = next->next;
78 num_ps_member += counter;
79 max_ps_member_in_ps = MAX(max_ps_member_in_ps, counter);
80 break;
82 default:
83 break;
87 void print_statistics(void * ps_tree)
89 /* Statistics data */
90 unsigned int num_files = 0, max_file_len = 0, total_file_len = 0;
91 unsigned int total_revisions = 0, max_revisions_for_file = 0;
92 unsigned int total_branches = 0, max_branches_for_file = 0;
93 unsigned int total_branches_sym = 0, max_branches_sym_for_file = 0;
95 /* Other vars */
96 struct hash_entry *he;
98 printf("Statistics:\n");
99 fflush(stdout);
101 /* Gather file statistics */
102 reset_hash_iterator(file_hash);
103 while ((he=next_hash_entry(file_hash)))
105 int len = strlen(he->he_key);
106 CvsFile *file = (CvsFile *)he->he_obj;
108 num_files++;
109 max_file_len = MAX(max_file_len, len);
110 total_file_len += len;
112 count_hash(file->revisions, &total_revisions, &max_revisions_for_file);
113 count_hash(file->branches, &total_branches, &max_branches_for_file);
114 count_hash(file->branches_sym, &total_branches_sym,
115 &max_branches_sym_for_file);
118 /* Print file statistics */
119 printf("Num files: %d\nMax filename len: %d, Average filename len: %.2f\n",
120 num_files, max_file_len, (float)total_file_len/num_files);
122 printf("Max revisions for file: %d, Average revisions for file: %.2f\n",
123 max_revisions_for_file, (float)total_revisions/num_files);
124 printf("Max branches for file: %d, Average branches for file: %.2f\n",
125 max_branches_for_file, (float)total_branches/num_files);
126 printf("Max branches_sym for file: %d, Average branches_sym for file: %.2f\n",
127 max_branches_sym_for_file, (float)total_branches_sym/num_files);
129 /* Gather patchset statistics */
130 twalk(ps_tree, stat_ps_tree_node);
132 /* Print patchset statistics */
133 printf("Num patchsets: %d\n", num_patch_sets);
134 printf("Max PS members in PS: %d\nAverage PS members in PS: %.2f\n",
135 max_ps_member_in_ps, (float)num_ps_member/num_patch_sets);
136 printf("Num authors: %d, Max author len: %d, Avg. author len: %.2f\n",
137 num_authors, max_author_len, (float)total_author_len/num_authors);
138 printf("Max desc len: %d, Avg. desc len: %.2f\n",
139 max_descr_len, (float)total_descr_len/num_patch_sets);