Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - TraceEvent API - dynamic filter question: (9 Items)
   
TraceEvent API - dynamic filter question  
Hello,

I have been trying to use the dynamic filter to be able to measure with microsecond precision how much time is used by 
several threads in my system.

I am able to make it work and I have pretty accurate results with limited impact on my system (1-2% of CPU activity).

My only problem is that if for any reason my program exits in an abnormal way and does not call the code to remove the 
dynamic filter callback, then the kernel crashes and I can just make a power cycle on my board...

I understand why this happens (kernel attempts to call a callback that does not exist anymore), but I wonder if there is
 any way to avoid that crash in case TraceEvent(_NTO_TRACE_DELEVENTHANDLER) is not called properly?

Thank you,
Martin
Re: TraceEvent API - dynamic filter question  
I don't know how abnormal is your abnormal crash but for most crashes you can install signal handler to delete the 
handler
Re: TraceEvent API - dynamic filter question  
I have 2 common use cases where I saw this happen:

- when debugging my program and stopping it from the debugger. I don't know what signal is sent to the process in that 
case.
- when using a script that starts/stop the different system processes we launch. This script sends a SIGTERM to all 
processes, and after a timeout will send a SIGKILL to all processes that haven't exited yet.

For the second use case I read that SIGKILL cannot be ignored or catched, and this is a script used frequently as part 
of our testing framework and the process that is running the TraceEvent is relatively complex (contains real-time motion
 logic).

I am leaning towards putting that TraceEvent handling in a separate process with very basic and simple logic, and also 
not having this process started/stopped by our scripts. But this will require some inter-process communication that I 
would like to avoid if possible.

Thank you for your help!
Re: TraceEvent API - dynamic filter question  
I have an additional question about the TraceEvent API.

As I mentioned in the initial post, I am developing a way to get accurate timing data for some threads in the system, 
for this I am using dynamic filtering on thread_running events and I use the PID/TID part of the event and ClockCycles()
 calls to measure thread timings.

I have had this implementation working as part of a process that contains a lot of business intelligence, but I am 
moving it to a dedicated process that only counts thread timings.

I am now unable to start the trace in my process (TraceEvent(_NTO_TRACE_START) returns -1, errno is ECANCELED). I am 
probably missing some specific TraceEvent() calls, so far I am only doing this:

// get kernel IO privileges
ThreadCtl(_NTO_TCTL_IO, 0) - success

// static filter on just THRUNNING events
TraceEvent(_NTO_TRACE_ADDEVENT, _NTO_TRACE_THREAD, _NTO_TRACE_THRUNNING) - success

// my dynamic filter callback
TraceEvent(_NTO_TRACE_ADDEVENTHANDLER, _NTO_TRACE_THREAD, _NTO_TRACE_THRUNNING, traceEventCallback, &m_eventData) - 
success

// start the trace
TraceEvent(_NTO_TRACE_START) - fails

In particular, I do not allocate/deallocate kernel buffers: should I be doing this? It was working without it in my 
previous implementation with the exact same function calls, but for some reason it does not work anymore in a separate 
process.
AW: Re: TraceEvent API - dynamic filter question  
Tracelogger is running?

- Thomas

----- Originalnachricht -----
Von: Martin Duvanel [mailto:community-noreply@qnx.com]
Gesendet: Tuesday, December 13, 2011 03:16 AM
An: ostech-core_os <post90563@community.qnx.com>
Betreff: Re: TraceEvent API - dynamic filter question

I have an additional question about the TraceEvent API.

As I mentioned in the initial post, I am developing a way to get accurate timing data for some threads in the system, 
for this I am using dynamic filtering on thread_running events and I use the PID/TID part of the event and ClockCycles()
 calls to measure thread timings.

I have had this implementation working as part of a process that contains a lot of business intelligence, but I am 
moving it to a dedicated process that only counts thread timings.

I am now unable to start the trace in my process (TraceEvent(_NTO_TRACE_START) returns -1, errno is ECANCELED). I am 
probably missing some specific TraceEvent() calls, so far I am only doing this:

// get kernel IO privileges
ThreadCtl(_NTO_TCTL_IO, 0) - success

// static filter on just THRUNNING events
TraceEvent(_NTO_TRACE_ADDEVENT, _NTO_TRACE_THREAD, _NTO_TRACE_THRUNNING) - success

// my dynamic filter callback
TraceEvent(_NTO_TRACE_ADDEVENTHANDLER, _NTO_TRACE_THREAD, _NTO_TRACE_THRUNNING, traceEventCallback, &m_eventData) - 
success

// start the trace
TraceEvent(_NTO_TRACE_START) - fails

In particular, I do not allocate/deallocate kernel buffers: should I be doing this? It was working without it in my 
previous implementation with the exact same function calls, but for some reason it does not work anymore in a separate 
process.



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post90563
Re: AW: Re: TraceEvent API - dynamic filter question  
No, tracelogger is not running.
Is it mandatory to have tracelogger - or another hand-crafted tracelogging tool - to run to initialize the kernel 
buffers?

If so, is it possible to run it once and have initialization done once and for all? Or is it possible to redirect 
tracelogger to /dev/null in a UNIX-style?

Thank you!
RE: AW: Re: TraceEvent API - dynamic filter question  
In order to log trace events you need to run tracelogger with the instr kernel.


-----Original Message-----
From: Martin Duvanel [mailto:community-noreply@qnx.com] 
Sent: December-13-11 3:48 AM
To: ostech-core_os
Subject: Re: AW: Re: TraceEvent API - dynamic filter question

No, tracelogger is not running.
Is it mandatory to have tracelogger - or another hand-crafted tracelogging tool - to run to initialize the kernel 
buffers?

If so, is it possible to run it once and have initialization done once and for all? Or is it possible to redirect 
tracelogger to /dev/null in a UNIX-style?

Thank you!



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post90565
Re: RE: AW: Re: TraceEvent API - dynamic filter question  
Thank you for your answer Chris.

Just to stress one point - I am not interested in actually logging anything, I just want my dynamic filter callback to 
be called, all my thread accounting logic is handled in the callback. I do not read any content from the kernel buffers 
nor use tracelogger output, everything is done on-the-fly.

This is why I did not bother to start tracelogger in any way. But apparently I need to do it so that 
TraceEvent(_NTO_TRACE_START) actually works.

Hence my questions:
- is it required to have tracelogger running at the time I call TraceEvent(_NTO_TRACE_START), or could I launch it once 
before just to make some initialization?
- is it possible to redirect tracelogger output on /dev/null, to avoid generating a huge file that I don't need anyway?
RE: RE: AW: Re: TraceEvent API - dynamic filter question  
You can start tracelogger in daemon mode (tracelogger -d1 &)

-----Original Message-----
From: Martin Duvanel [mailto:community-noreply@qnx.com] 
Sent: December-13-11 9:35 AM
To: ostech-core_os
Subject: Re: RE: AW: Re: TraceEvent API - dynamic filter question

Thank you for your answer Chris.

Just to stress one point - I am not interested in actually logging anything, I just want my dynamic filter callback to 
be called, all my thread accounting logic is handled in the callback. I do not read any content from the kernel buffers 
nor use tracelogger output, everything is done on-the-fly.

This is why I did not bother to start tracelogger in any way. But apparently I need to do it so that 
TraceEvent(_NTO_TRACE_START) actually works.

Hence my questions:
- is it required to have tracelogger running at the time I call TraceEvent(_NTO_TRACE_START), or could I launch it once 
before just to make some initialization?
- is it possible to redirect tracelogger output on /dev/null, to avoid generating a huge file that I don't need anyway?



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post90579