The first example creates the simple uncompressed trace with an integer and a float signal and writes it into a file.
The example will show you the basic steps to create a trace.
The c-language emitter of flux does not depend on any library (embedded systems). Therefor the memory for the trace and the buffer object need to be prepared.
The first step in setting up a flux trace is calculating the required memory. The required memories for buffers and tables need to be passed as arguments to the
In this example (and most others) we use the macros
to calculate the memory size for buffer and trace and define static memory chunks.
// calculate required memory for trace and buffers unsigned bufferSize = FLX_BUFFER_BYTES(MAX_ENTRY_SIZE); unsigned traceSize = FLX_TRACE_BYTES(0, MAX_ITEM_ID); // static memory unsigned char memoryBuffer[bufferSize]; unsigned char memoryTrace[traceSize];
Buffers are used to store, organize and handle the trace data. The trace information is packed into snippets (entries).
In this example, we use a simple flat buffer that writes to a file.
We use the method flxCreateSimpleBuffer. The third and fourth arguments are the 'write to file' handler and the file object.
The SimpleFileOutputBuffer class contains a simple buffer with a 'write to file' handler.
// buffer Flx.Buffer buffer = new Flx.SimpleFileOutputBuffer(MAX_ENTRY_SIZE, "traces/example01.recTr"); // trace Flx.Trace trace = new Flx.Trace(0, MAX_ITEM_ID, MAX_ENTRY_SIZE, false, buffer);
// buffer flxBuffer buffer = flxCreateSimpleBuffer(memoryBuffer, bufferSize, flxWriteToFile, out); // trace flxTrace trace = flxCreateTrace(0, MAX_ITEM_ID, MAX_ENTRY_SIZE, memoryTrace, traceSize, buffer);
# buffer buffer = Flx.SimpleFileOutputBuffer(MAX_ENTRY_SIZE, "traces/example01.recTr"); # trace trace = Flx.Trace(0, MAX_ITEM_ID, MAX_ENTRY_SIZE, False, buffer);
// buffer let buffer : Flx.Buffer = new Flx.SimpleFileOutputBuffer(Example01.MAX_ENTRY_SIZE, "traces/example01.recTr"); // trace let trace : Flx.Trace = new Flx.Trace(0, Example01.MAX_ITEM_ID, Example01.MAX_ENTRY_SIZE, false, buffer);
// buffer var buffer = new Flx.SimpleFileOutputBuffer(Example01.MAX_ENTRY_SIZE, "traces/example01.recTr"); // trace var trace = new Flx.Trace(0, Example01.MAX_ITEM_ID, Example01.MAX_ENTRY_SIZE, false, buffer);
For the trace creation we need the following arguments:
The trace object is prepared and we can start to add content. With flxAddHead/addHead we start the trace with a label and description of the following trace. The method flxAddSignal/addSignal adds a signal to the trace. The arguments are:
// head trace.addHead("example", "flux example"); // add signals // parent 0 is root trace.addSignal(1, 0, "integer", "an integer", Flx.TYPE_INTEGER, null); trace.addSignal(2, 0, "float", "a float", Flx.TYPE_FLOAT, null);
// head flxAddHead(trace, "example", "flux example"); // add signals // parent 0 is root flxAddSignal(trace, 1, 0, "integer", "an integer", FLX_TYPE_INTEGER, 0); flxAddSignal(trace, 2, 0, "float", "a float", FLX_TYPE_FLOAT, 0);
// head flxAddHead(trace, "example", "flux example"); // add signals // parent 0 is root flxAddSignal(trace, 1, 0, "integer", "an integer", FLX_TYPE_INTEGER, None); flxAddSignal(trace, 2, 0, "float", "a float", FLX_TYPE_FLOAT, None);
// head trace.addHead("example", "flux example"); // add signals // parent 0 is root trace.addSignal(1, 0, "integer", "an integer", Flx.TYPE_INTEGER, null); trace.addSignal(2, 0, "float", "a float", Flx.TYPE_FLOAT, null);
// head trace.addHead("example", "flux example"); // add signals // parent 0 is root trace.addSignal(1, 0, "integer", "an integer", Flx.TYPE_INTEGER, null); trace.addSignal(2, 0, "float", "a float", Flx.TYPE_FLOAT, null);
With flxOpen/open we start a trace sequence and finalize it with flxClose/close. Both methods are used to define the domain range and the process. The parameters of flxOpen/open are:
And flxClose/close has:
To open an item id != 0, you need to offer a larger memory space to the trace object (more complex handling). You do this by setting the first argument of FLX_TRACE_BYTES to 1.
// open trace.open(0, "ns", 0, 0); // generate example trace for (int n = 0; n < 50000; n++) { // time in ns current = n * 10; ... // close trace.close(0, current + 10);
// open flxOpen(trace, 0, "ns", 0, 0); // generate example trace for (int n = 0; n < 50000; n++) { // time in ns current = n * 10; ... // close flxClose(trace, 0, current + 10);
# open trace.open(0, "ns", 0, 0); # generate example trace for n in range(0, 50000) : # time in ns current = n * 10; ... # close trace.close(0, current + 10);
// open trace.open(0, "ns", 0, 0); // generate example trace for(let n : number = 0; n < 50000; n++){ // time in ns current = n * 10; ... // close trace.close(0, current + 10);
// open trace.open(0, "ns", 0, 0); // generate example trace for (var n = 0; n < 50000; n++) { // time in ns current = n * 10; ... // close trace.close(0, current + 10);
The flxWriteXXXAt/writeXXXAt methods are intended to add events and value changes to a signal.
The domain position (e.g. when a change occurs) can be given absolute or relative. If you choose an absolute domain position, the value must to be equal or larger than the one used in a previous write (and larger than the open position).
A relative domain position (means relative to a previous write) must be larger or equal to 0.
The parameters:
// integer iVal = n % 444; trace.writeIntAt(1, 0, current, false, iVal); // float - same time - use domain=0; isDelta=1 fVal = (n / 1000.0); trace.writeFloatAt(2, 0, 0, true, fVal);
// integer iVal = n % 444; flxWriteIntAt(trace, 1, 0, current, 0, &iVal, sizeof(int), 1); // float - same time - use domain=0; isDelta=1 fVal = (n / 1000.0); flxWriteFloatAt(trace, 2, 0, 0, 1, &fVal, sizeof(double));
// integer iVal = n % 444; trace.writeIntAt(1, 0, current, false, iVal); // float - same time - use domain=0; isDelta=1 fVal = (n / 1000.0); trace.writeFloatAt(2, 0, 0, true, fVal);
// integer iVal = n % 444; trace.writeIntAt(1, 0, current, false, iVal); // float - same time - use domain=0; isDelta=1 fVal = (n / 1000.0); trace.writeFloatAt(2, 0, 0, true, fVal);
// integer iVal = n % 444; trace.writeIntAt(1, 0, current, false, iVal); // float - same time - use domain=0; isDelta=1 fVal = (n / 1000.0); trace.writeFloatAt(2, 0, 0, true, fVal);