Using TinyTracer in your application

As an example lets take the Oscilloscope Application in TinyOS 2.x . This is a simple application that bunches the sensor readings and broadcasts them over the radio whenever the Timer used in the application fires.

Index ============================================================================= SECTION -I : Wiring TinyTracer to your TinyOS Application To make use of TinyTracer, we must make the following changes to the application: 1. change the OscilloscopeC.nc file by adding a few new interfaces in the “uses” declaration. uses{ //..... //The SplitControl interface provided by TinyTracer interface SplitControl as TraceControl; //The CFTrace interface which contains the recordLabel() command interface CFTrace; } 2. Add a dummy call to the recordLabel command in the event Boot.booted(). This is crucial since this starts the tracing process. Also start the SplitControl interface used by the application (aliased previously as TraceControl) Add events to handle the callbacks/events caused by the SplitControl (TraceControl) interface.

event void Boot.booted() { call CFTrace.recordLabel(0, 0, 0); //.... //.... call TraceControl.start(); } event void TraceControl.startDone(error_t error){} event void TraceControl.stopDone(error_t error){} 3. The OscilloscopeAppC.nc file must be changed to additionally include the following lines: components TestTracerAppC; //initialize the TestTracerAppC configuration //wire the Interfaces used by the application to the Provider, TestTracerAppC OscilloscopeC.TraceControl -> TestTracerAppC.SplitControl; OscilloscopeC.CFTrace -> TestTracerAppC.CFTrace; Back to Index ============================================================================= Section-II : Compiling your application 4. Compile the code for your target platform. For this example we use mica2. make mica2 5.make a new file called “oscil.config” , and include the names of the components/procedures you would like to trace in the application, (one component/procedure in each line) OscilloscopeC__Timer__fired LedsP OscilloscopeC__Read__readDone (take care with the two underscores, and all components/procedures to be traced must be specified completely) Notice that the first line is an event , the second line is a module, and the last line is again an event. Take care that there are no blank lines before, after or in between this description. Also no comments can be included. 6. Run the CIL engine. The CIL engine takes as input the app.c file generated by the mica2 make process in TinyOS 2.x and generates a new exe file , oscilexe, which includes the instrumentation that enables tracing. It also gives as output a procedure map , oscil.pm, that contains the procedure IDs assigned to all the functions traced within the application. Redirect the output to a dummy file oscilout. m2cillys --nescconfigs=oscil.config --tracerfuncs=CFTracerC__CFTrace__recordLabel --procmaps=oscil.pm -o oscilexe build/mica2/app.c > oscilout Back to Index ============================================================================= Section-III : Simulating your application to collect TinyTracer's traces 7. If you wish to use a simulator such as avrora, make sure that the TinyTracer file is sending the traces over the Radio, by appropriately modifying the TestTracerAppC to use the SerialAMSender interface and making sure that the flag responsible for sending the generated trace packets over serial , is set to TRUE. for sending trace packets over serial,modify the TestTracerAppC configuration file. components SerialActiveMessageC as AM; CFTracerC.SendTraceControl -> AM; CFTracerC.AMSend -> AM.AMSend[43]; if you would rather store traces in Flash memory, modify the TestTracerAppC file as below, //include the header file #include "StorageVolumes.h" components new LogStorageC(VOLUME_LOGTEST, TRUE); CFTracerC.LogRead -> LogStorageC.LogRead; CFTracerC.LogWrite -> LogStorageC.LogWrite; 8. For Demonstration purposes lets send the trace packets over a serial connection in avrora to another terminal on the same machine. We assume that you have AVRORA installed on your machine AVRORA Documentation for downloading AVRORA , refer to their sourceforge code repository AVRORA Code Repository Open a new terminal and type in the commands below. cp oscilexe oscil.elf //since AVRORA expects elf avrora -platform=mica2 -seconds=10 -monitors=serial,packet -update-node-id -stagger-start=1234 -port=0:0:2390 -nodecount=1 oscil.elf This opens up a serial connection on port 2390 on the local host. The “serial” monitor allows the serial port (UART) of a node in the simulation to be connected to a socket so that data from the program running in the simulation can be outputted, and external data can be fed into the serial port of the simulated node. open a seperate terminal, and Listen on port 2390 and redirect the trace packets received over the serial link to a file “oscil.log” java net.tinyos.tools.Listen -comm network@localhost:2390 > oscil.log 8*. We could also install the instrumented executable, oscilexe (which we obtained as output from the m2cilly engine in step 6 tos-set-symbols oscilexe rcl.exe-15 TOS_NODE_ID=15 //set TOS_NODE_ID uisp -dprog=mib510 -dserial=/dev/ttyUSB0 --wr_fuse_h=0xd9 -dpart=ATmega128 --wr_fuse_e=ff --erase --upload if=rcl.exe-15 --verify Now connect your mib510/mib520 board with the mica2/micaz, to the PC , and open up a serial connection to the data communication port of the mib520. (mib520 for eg : shows up as 2 ports the first port is for installation , and the other is for serial communication. java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB1:micaz > node0.log Back to Index ============================================================================= Section-IV : Parsing the traces obtained 9.use the TTprettytrace.py file to strip the serial stack headers from the received packets in oscil.log. This script converts the ascii log file to a binary file which can then be used for pretty-printed trace output. python TTprettytrace.py oscil.log 10. supply the obtained bin output file to parsetr2.py for the final pretty printed trace. python parsetr2.py [procmap] > dummyout Example: python parsetr2.py in_tr.bin out_tr.txt oscil.pm the procmap is the “oscil.pm” file generated earlier in the CIL engine step. The outfile you provided contains the trace of the program, with the “start” and “end” of each procedure clearly highlighted. The number listed next to the “end” statement tells you about the control flow path ID taken in the procedure during the execution. Back to Index =============================================================================