-
Notifications
You must be signed in to change notification settings - Fork 31
Main
Traces is an API tracing framework for Linux C/C++ applications. One of the main bottlenecks to development productivity is debugging. The most common debugging method is to litter one's code with trace messages in the hope that once a bug is discovered, the trace messages will be sufficient to understand its root cause. Usually this is not the case and the developer must narrow down the possible source of the bug by adding additional trace messages in the code and try to reproduce the bug again. During development, this technique can take up a lot of a developer's time. A worse scenario is having a bug appear on a client-installed application and not having sufficient trace data to understand it.
Traces was written to provide rich trace information prior to the bug occurring.
- Explicit tracing through DEBUG/INFO/WARN/ERROR macros
- Automatic tracing of every function leave/entry
- Type-aware tracing. Traces display enum value names and entire structures
- Interactive and non-interactive readers for navigating and searching traces
Let's take a look at the trace output of the following code:
#include <traces/trace_user.h>
enum calculation_type {
CALCULATION_TYPE_DECREMENT,
CALCULATION_TYPE_INCREMENT,
};
int calculate(enum calculation_type e, int value) {
INFO("Calculation type:", e);
if (e == CALCULATION_TYPE_DECREMENT) {
return value - 1;
} else if (e == CALCULATION_TYPE_INCREMENT) {
return value + 1;
}
return -1;
}
static void increment_twice(int *value)
{
(*value) = calculate(CALCULATION_TYPE_INCREMENT, (*value));
(*value) = calculate(CALCULATION_TYPE_INCREMENT, (*value));
}
int main(void) {
int value = 500;
while (1) {
value = calculate(CALCULATION_TYPE_DECREMENT, value);
increment_twice(&value);
WARN("Next iteration");
usleep(100000);
}
return 0;
}
The trace output after running this code for a few iterations is this: