Merge branch 'master' into develop
[jack2.git] / common / timestamps.c
blobd8a2cda98da22b6406499b80f232606356f9d91f
1 /*
2 Copyright (C) 2002-2003 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <stdlib.h>
21 #include <string.h>
22 #include <inttypes.h>
23 #include "timestamps.h"
24 #include "JackTime.h"
26 typedef struct {
27 jack_time_t when;
28 const char *what;
29 } jack_timestamp_t;
31 static jack_timestamp_t *timestamps = 0;
32 static unsigned long timestamp_cnt = 0;
33 static unsigned long timestamp_index;
35 void
36 jack_init_timestamps (unsigned long howmany)
38 if (timestamps) {
39 free (timestamps);
41 timestamps = (jack_timestamp_t *)
42 malloc (howmany * sizeof(jack_timestamp_t));
43 timestamp_cnt = howmany;
44 memset (timestamps, 0, sizeof(jack_timestamp_t) * howmany);
45 timestamp_index = 0;
48 void
49 jack_timestamp (const char *what)
51 if (timestamp_index < timestamp_cnt) {
52 timestamps[timestamp_index].when = GetMicroSeconds();
53 timestamps[timestamp_index].what = what;
54 ++timestamp_index;
58 void
59 jack_dump_timestamps (FILE *out)
61 unsigned long i;
63 for (i = 0; i < timestamp_index; ++i) {
64 fprintf (out, "%-.32s %" PRIu64 " %" PRIu64,
65 timestamps[i].what, timestamps[i].when,
66 timestamps[i].when - timestamps[0].when);
67 if (i > 0) {
68 fprintf (out, " %" PRIu64,
69 timestamps[i].when - timestamps[i-1].when);
71 fputc ('\n', out);
75 void
76 jack_reset_timestamps ()
78 timestamp_index = 0;