1 /*
2 * Copyright 2009, Michael Lotz, mmlr@mlotz.ch.
3 * Distributed under the terms of the MIT License.
4 */
5
6 #include "ATATracing.h"
7
8 #include <stdarg.h>
9
10 #include <algorithm>
11
12
13 static char sTraceBuffer[256];
14 static uint32 sTraceBufferOffset = 0;
15
16
17 void
ata_trace_printf(uint32 flags,const char * format,...)18 ata_trace_printf(uint32 flags, const char *format, ...)
19 {
20 if (sTraceBufferOffset < sizeof(sTraceBuffer)) {
21 va_list arguments;
22 va_start(arguments, format);
23 size_t totalBytes = vsnprintf(sTraceBuffer + sTraceBufferOffset,
24 sizeof(sTraceBuffer) - sTraceBufferOffset, format, arguments);
25 sTraceBufferOffset += std::min(totalBytes,
26 (size_t)(sizeof(sTraceBuffer) - sTraceBufferOffset - 1));
27 va_end(arguments);
28 }
29
30 if (flags & ATA_TRACE_FLUSH) {
31 #if ATA_TRACING
32 ktrace_printf(sTraceBuffer);
33 #endif
34 if (flags & ATA_TRACE_SYSLOG)
35 dprintf("%s", sTraceBuffer);
36
37 sTraceBufferOffset = 0;
38 }
39 }
40