Date:2010-11-05 14:14:26 (13 years 4 months ago)
Author:Werner Almesberger
Commit:9361f148759a47820beb0eb04cfc5c587f966df6
Message:Print a frequency estimate after each burst.

- tools/cntr/cntr.c (measure, print_f): moved pretty-printing of the
frequency to a separate function
- tools/cntr/cntr.c (count_bursts): print a frequency estimate after each
burst
- tools/cntr/cntr.c (count_bursts): added comment explaining when and where
we take the various samples
Files: cntr/tools/cntr/cntr.c (4 diffs)

Change Details

cntr/tools/cntr/cntr.c
174174}
175175
176176
177/* ---- output ------------------------------------------------------------- */
178
179
180static void print_f(double f, int digits)
181{
182    char *f_exp;
183
184    if (f > 1000000.0) {
185        f /= 1000000.0;
186        f_exp = "M";
187    } else if (f > 1000.0) {
188        f /= 1000.0;
189        f_exp = "k";
190    } else {
191        f_exp = "";
192    }
193    printf("%1.*f %sHz", digits, f, f_exp);
194}
195
196
177197/* ---- burst counter ------------------------------------------------------ */
178198
179199
200/*
201 * Here is when the various samples are taken:
202 *
203 * Activity --------XXXXXXXXXXXXX-------------
204 * ^ ^ ^^
205 * | | last||
206 * start stable now
207 * |<-t(idle)->|
208 *
209 * "start" is the sample before counter activity
210 * "stable" is the first sample after counter activity
211 * "last" is the sample immediately preceding "now"
212 * "now" is the sample currently being processed
213 *
214 * The count is printed if t(idle) >= timeout.
215 */
216
180217static void count_bursts(usb_dev_handle *dev, double timeout)
181218{
182    struct sample start, stable, now;
183
219    struct sample start, stable, now, last;
220    uint64_t dc, delta_n = 0;
221    double delta_sum = 0, dt;
184222    arm_stop();
185223
186224    while (!get_sample(dev, &start));
187    stable = start;
225    stable = last = start;
188226    while (!stop) {
189227        while (!get_sample(dev, &now))
190228            if (stop)
191229                break;
230        delta_sum += now.t1-last.t1;
231        delta_n++;
232        last = now;
192233        if (stable.cntr != now.cntr) {
193234            stable = now;
194235            continue;
195236        }
196237        if (now.t0-stable.t1 < timeout)
197238            continue;
198        if (now.cntr == start.cntr)
199            continue;
200        printf("%llu\n", (unsigned long long) now.cntr-start.cntr);
239        if (now.cntr != start.cntr) {
240            dc = now.cntr-start.cntr;
241            dt = stable.t1-start.t1-delta_sum/delta_n;
242            printf("%llu ~ ", (unsigned long long) dc);
243            if (dt > 0)
244                print_f(dc/dt, 3);
245            printf("\n");
246            fflush(stdout);
247        }
201248        start = now;
202249    }
203250}
...... 
211258    struct sample start, now;
212259    uint64_t dc;
213260    double dt, f, error;
214    char *f_exp, *error_exp;
261    char *error_exp;
215262    int i;
216263
217264    arm_stop();
...... 
239286        dc = now.cntr-start.cntr;
240287        dt = (now.t0+now.t1)/2.0-(start.t0+start.t1)/2.0;
241288        f = dc/dt;
242        if (f > 1000000.0) {
243            f /= 1000000.0;
244            f_exp = "M";
245        } else if (f > 1000.0) {
246            f /= 1000.0;
247            f_exp = "k";
248        } else {
249            f_exp = "";
250        }
251289        if (dc)
252290            error = 1.0/dc; /* one count */
253291        else
...... 
274312            }
275313        }
276314
277        printf("\r%6.1f %1.9f %sHz %3.3f%s ",
278            dt, f, f_exp, error, error_exp);
315        printf("\r%6.1f ", dt);
316        print_f(f, 9);
317        printf(" %3.3f%s ", error, error_exp);
279318        fflush(stdout);
280319    }
281320    printf(

Archive Download the corresponding diff file



interactive