This source file includes following definitions.
- init_data
- dbgfprintf
- dbgstrerror
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #define ENABLE_DEBUGGING 0
20
21
22
23 #define SMALL_DELAY 10000
24
25
26 static unsigned char *
27 init_data (size_t data_block_size)
28 {
29 unsigned char *data;
30 unsigned int i;
31
32 data = (unsigned char *) malloc (2 * data_block_size);
33 ASSERT (data != NULL);
34
35 for (i = 0; i < 2 * data_block_size; i++)
36 data[i] = (unsigned char) (i * i + (7 * i) % 61 + 4);
37
38 return data;
39 }
40
41 #if ENABLE_DEBUGGING
42 # include <stdarg.h>
43 static int dbgfprintf (FILE *fp, const char *format, ...)
44 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3);
45 static int
46 dbgfprintf (FILE *fp, const char *format, ...)
47 {
48
49
50 char line[1024];
51 size_t line_len;
52 struct timeval current_time;
53 va_list args;
54 int ret;
55
56 line_len = 0;
57 gettimeofday (¤t_time, NULL);
58 ret = snprintf (line, sizeof (line), "%.6f ",
59 current_time.tv_sec + (double) current_time.tv_usec * 1e-6);
60 if (ret < 0)
61 return -1;
62 line_len = strlen (line);
63
64 va_start (args, format);
65 ret = vsnprintf (line + line_len, sizeof (line) - line_len, format, args);
66 va_end (args);
67 if (ret < 0)
68 return -1;
69 line_len += strlen (line + line_len);
70
71 ret = fwrite (line, 1, line_len, fp);
72
73
74
75
76 fflush (fp);
77 return ret;
78 }
79 #else
80 # define dbgfprintf if (1) ; else fprintf
81 #endif
82
83
84
85 static const char *
86 dbgstrerror (bool failed, int err)
87 {
88 static char buf[256];
89 if (failed)
90 {
91 sprintf (buf, " %d %s", err, strerror (err));
92 return buf;
93 }
94 else
95 return "";
96 }
97
98 #define TIMING_DECLS \
99 struct timeval before_time; \
100 struct timeval after_time; \
101 double spent_time;
102 #define START_TIMING \
103 gettimeofday (&before_time, NULL);
104 #define END_TIMING \
105 gettimeofday (&after_time, NULL); \
106 spent_time = \
107 (after_time.tv_sec - before_time.tv_sec) \
108 + ((double) after_time.tv_usec - (double) before_time.tv_usec) * 1e-6;