[ltt-dev] Potential lack of documentation for userspace tracing via debugfs.

Mathieu Desnoyers compudj at krystal.dyndns.org
Fri Jul 9 17:00:24 EDT 2010


* Matthew Khouzam (matthew.khouzam at ericsson.com) wrote:
> Hi,
>
> I am writing a test app to benchmark Java using LTTng. I am first trying  
> to familiarize myself with the interface, and wanted to use the  
> "write_event" file in /mnt/debugfs/ltt as detailed in the help file.
>
> I wrote some C test programs and I am getting some odd functionality.
>
> <code>
> #include <stdio.h>
> #include <time.h>
>
> int main(int argc, char* argv[])
> {
>     int i = 0;
>     for( i = 0 ; i < 10000 ; i++)
>     {
>         system("echo \"Hello world\" >/mnt/debugfs/ltt/write_event");
>         usleep(3);
>     }
>     return 0;
> }
> </code>
> or
>
> <code>
> #include <stdio.h>
> #include <time.h>
>
> int main(int argc, char* argv[])
> {
>     int i = 0;
>     for( i = 0 ; i < 10000 ; i++)
>     {
>         FILE *f;
>         f = fopen("/mnt/debugfs/ltt/write_event", "w");
>         fputs("Hello World" , f);
>         fclose(f);
>         usleep(3);
>     }
>     return 0;
> }
> </code>
>
> I would basically get an event generated rarely, containing MANY  
> hello_worlds.
> Is there a way to force the file to flush and write immediately. That  
> way the events would be in the right parts of the traces and make the  
> reading much easier.

Hi Matthew,

You should use write(2) rather than fwrite(3). The former is unbuffered,
which is what you want.

I'm surprised that
"system("echo \"Hello world\" >/mnt/debugfs/ltt/write_event");"

Behaves like your "fopen" program. The event is written whenever a '\n'
is received or when the file is closed.

Please feel free to propose any documentation addition you feel is
appropriate.

Thanks,

Mathieu

>
> Thank You,
> Matt.
>
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
>

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




More information about the lttng-dev mailing list