summaryrefslogtreecommitdiffstats
path: root/3rdparty/openpgm-svn-r1135/pgm/histogram.c.c89.patch
blob: a5826fd8bb19ad373b0af602cbb6efc7c607b08e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
--- histogram.c	2010-05-21 11:35:50.000000000 +0800
+++ histogram.c89	2010-08-04 11:32:46.000000000 +0800
@@ -61,10 +61,12 @@
 		value = INT_MAX - 1;
 	if (value < 0)
 		value = 0;
+	{
 	const unsigned i = bucket_index (histogram, value);
 	pgm_assert (value >= histogram->ranges[ i ]);
 	pgm_assert (value  < histogram->ranges[ i + 1 ]);
 	accumulate (histogram, value, 1, i);
+	}
 }
 
 void
@@ -74,12 +76,14 @@
 {
 	if (!pgm_histograms)
 		return;
+	{
 	pgm_slist_t* snapshot = pgm_histograms;
 	while (snapshot) {
 		pgm_histogram_t* histogram = snapshot->data;
 		pgm_histogram_write_html_graph (histogram, string);
 		snapshot = snapshot->next;
 	}
+	}
 }
 
 static
@@ -119,8 +123,11 @@
 	)
 {
 	pgm_count_t total = 0;
-	for (unsigned i = 0; i < sample_set->counts_len; i++)
+	{
+	unsigned i;
+	for (i = 0; i < sample_set->counts_len; i++)
 		total += sample_set->counts[ i ];
+	}
 	return total;
 }
 
@@ -173,12 +180,15 @@
 		double log_current = log(current);
 		log_ratio = (log_max - log_current) / (histogram->bucket_count - i);
 		log_next = log_current + log_ratio;
-		int next = floor(exp(log_next) + 0.5);
+		{
+/* force cast to ignore float to int conversion warning */
+		int next = (int)floor(exp(log_next) + 0.5);
 		if (next > current)
 			current = next;
 		else
 			current++;
 		set_bucket_range (histogram, i, current);
+		}
 	}
 	pgm_assert (histogram->bucket_count == i);
 }
@@ -192,6 +202,7 @@
 {
 	pgm_assert (histogram->ranges[0] <= value);
 	pgm_assert (histogram->ranges[ histogram->bucket_count ] > value);
+	{
 	unsigned under = 0;
 	unsigned over = histogram->bucket_count;
 	unsigned mid;
@@ -209,6 +220,7 @@
 	pgm_assert (histogram->ranges[ mid ] <= value &&
 		  histogram->ranges[ mid + 1] > value);
 	return mid;
+	}
 }
 
 static
@@ -231,19 +243,21 @@
 	pgm_string_t*	 restrict output
 	)
 {
-	pgm_count_t snapshot_counts[ histogram->sample.counts_len ];
-	pgm_sample_set_t snapshot = {
-		.counts		= snapshot_counts,
-		.counts_len	= histogram->sample.counts_len,
-		.sum		= histogram->sample.sum,
-		.square_sum	= histogram->sample.square_sum
-	};
+	pgm_count_t* snapshot_counts = pgm_newa (pgm_count_t, histogram->sample.counts_len);
+	pgm_sample_set_t snapshot;
+	snapshot.counts		= snapshot_counts;
+	snapshot.counts_len	= histogram->sample.counts_len;
+	snapshot.sum		= histogram->sample.sum;
+	snapshot.square_sum	= histogram->sample.square_sum;
+
 	memcpy (snapshot_counts, histogram->sample.counts, sizeof(pgm_count_t) * histogram->sample.counts_len);
 
+	{
 	pgm_count_t sample_count = sample_set_total_count (&snapshot);
 	write_ascii_header (histogram, &snapshot, sample_count, output);
 	pgm_string_append (output, newline);
 
+	{
 	double max_size = get_peak_bucket_size (histogram, &snapshot);
 	unsigned largest_non_empty_bucket = histogram->bucket_count - 1;
 	while (0 == snapshot.counts[ largest_non_empty_bucket ])
@@ -253,8 +267,11 @@
 		largest_non_empty_bucket--;
 	}
 
+	{
 	int print_width = 1;
-	for (unsigned i = 0; i < histogram->bucket_count; ++i)
+	{
+	unsigned i;
+	for (i = 0; i < histogram->bucket_count; ++i)
 	{
 		if (snapshot.counts[ i ]) {
 			pgm_string_t* bucket_range = get_ascii_bucket_range (histogram, i);
@@ -264,16 +281,22 @@
 				print_width = width;
 		}
 	}
+	}
 
+	{
 	int64_t remaining = sample_count;
 	int64_t past = 0;
-	for (unsigned i = 0; i < histogram->bucket_count; ++i)
+	{
+	unsigned i;
+	for (i = 0; i < histogram->bucket_count; ++i)
 	{
 		pgm_count_t current = snapshot.counts[ i ];
 		remaining -= current;
+		{
 		pgm_string_t* bucket_range = get_ascii_bucket_range (histogram, i);
 		pgm_string_append_printf (output, "%*s ", print_width, bucket_range->str);
 		pgm_string_free (bucket_range, TRUE);
+		}
 		if (0 == current &&
 		    i < histogram->bucket_count - 1 &&
 		    0 == snapshot.counts[ i + 1 ])
@@ -288,12 +311,19 @@
 			continue;
 		}
 
+		{
 		const double current_size = get_bucket_size (histogram, current, i);
 		write_ascii_bucket_graph (current_size, max_size, output);
+		}
 		write_ascii_bucket_context (past, current, remaining, i, output);
 		pgm_string_append (output, newline);
 		past += current;
 	}
+	}
+	}
+	}
+	}
+	}
 }
 
 static
@@ -310,8 +340,8 @@
 				 histogram->histogram_name ? histogram->histogram_name : "(null)",
 				 sample_count);
 	if (sample_count > 0) {
-		const double average = sample_set->sum / sample_count;
-		const double variance = sample_set->square_sum / sample_count
+		const double average = (double)sample_set->sum / sample_count;
+		const double variance = (double)sample_set->square_sum / sample_count
 				  - average * average;
 		const double standard_deviation = sqrt (variance);
 		pgm_string_append_printf (output,
@@ -329,7 +359,7 @@
 	)
 {
 	static const int k_line_length = 72;
-	int x_count = (k_line_length * (current_size / max_size) + 0.5);
+	int x_count = (int)(k_line_length * (current_size / max_size) + 0.5);
 	int x_remainder = k_line_length - x_count;
 	while (0 < x_count--)
 		pgm_string_append_c (output, '-');
@@ -375,11 +405,14 @@
 	)
 {
 	double max_size = 0;
-	for (unsigned i = 0; i < histogram->bucket_count; i++) {
+	{
+	unsigned i;
+	for (i = 0; i < histogram->bucket_count; i++) {
 		const double current_size = get_bucket_size (histogram, sample_set->counts[ i ], i);
 		if (current_size > max_size)
 			max_size = current_size;
 	}
+	}
 	return max_size;
 }
 
@@ -392,11 +425,13 @@
 	)
 {
 	pgm_assert (histogram->ranges[ i + 1 ] > histogram->ranges[ i ]);
+	{
 	static const double kTransitionWidth = 5;
 	double denominator = histogram->ranges[ i + 1 ] - histogram->ranges[ i ];
 	if (denominator > kTransitionWidth)
 		denominator = kTransitionWidth;
 	return current / denominator;
+	}
 }
 
 static