This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: request to add additional runtime path


> Not that this directly relates to your issue, but why would you use
> embedded-C for something like this?  Could you post a fuller 
> example?
>

In fact, I am working on a kernel event trace tool using systemTap 
which targets for performance analysis. This tool will look at some 
interesting places inside the kernel and get the relative data for 
post analysis. The places it looks at are those such as scsi layers, 
io schedulers, syscalls etc.

So I need some embedded c functions which will get the information by 
access kernel function parameters or directly calling some kernel 
functions or some other ways.

Here's one of them, and I will send out the entire codes of this trace 
tool onto mailinglist some time later:

/* when a request is retrieved from request queue */
probe addevent.ioscheduler.elv_next_request
        =  kernel.function("elv_next_request")
{
        if(filter_by_pid() == 1 )
        {
                log_tracedata_common(5)
                log_ioscheduler_tracedata_extra_elv_next($q)
        }
}

%( kernel_v == "2.6.9" %?
function log_ioscheduler_tracedata_extra_elv_next(var:long)
%{

        struct request_queue *q;
        struct request *rq;

        q = (struct request_queue *)((long)THIS->var);

        /* If there is a request in the request queue:
                elevator name|major|minor|
           if there is no request in the request queue:
                elevator name|empty|
        */
        if(list_empty(&(q->queue_head)))
        {
                _stp_printf("%s|empty|", q->elevator.elevator_name);
        }
        else  {
                rq = list_entry_rq(q->queue_head.next);
                _stp_printf("%s|%ld|%ld", q->elevator.elevator_name, 
rq->rq_disk->major, rq->rq_disk->first_minor);
        }
%}

%:
...  /* to deal with some other kernel versions, omitted ... */
%)

/* data tracing filter by pid
   return:
        1 - if continue to log the raw data
        0 - return without logging the raw data
 */
function filter_by_pid:long()
%{
        struct task_struct *cur = current;

        if(cur->tgid != _stp_pid) /* skip stapd itself */
        {
                /* to trace a specific process if we explicitly 
specify
                   which process we want to trace by:
                    1. stap -c "process_to_trace" ...
                    2. stap -x pid_to_trace ...
                   else we will trace all the processes
                 */
                if( _stp_target != 0 && cur->tgid != _stp_target)
                {
                        THIS->__retvalue = 0;
                        return;
                }

                THIS->__retvalue = 1;
        }
        else  /*skip the events generated by stap itself*/
                THIS->__retvalue = 0;
        return;
%}

/* Log the data common to all events */
function log_tracedata_common(hookID:long)
%{
        struct timeval tv;
        struct task_struct *cur = current;

        /* second|usec|pid|ppid|tid|cpuid|hoodID */

        do_gettimeofday (&tv);
        _stp_printf("\n%ld|%ld|%ld|%ld|%ld|%u|%ld|", tv.tv_sec, 
tv.tv_usec, cur->tgid, \
                cur->parent->pid, cur->pid, 
cur->thread_info->cpu,THIS->hookID);
%}

Here you can see log_tracedata_common(5), 5 is the hookID. I think 
it's better to use IOSCHED_NEXT_REQ_HOOKID instead of 5. So that it's 
easier for maintenance.

> It is undesirable for embedded C code to make direct calls to the
> runtime.  Among other reasons, this is since that API exists for the
> convenience of the translator, and thus may change frequently
>
Currently I have no need to put .c files into runtime dir.
>
>> [...] such macros appear almost in every stp files, so it's better
>> to include a .h file in each stp file [...]
>
> Assuming this were a good idea, it could be supported by adding the
> tapset source directories to the C compiler's include path.
>
Yes, in fact at present what I want is to add -I includepath when 
making the module.
>
> - FChE
>
> 




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]