public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* stpd and stdout
@ 2006-05-09 22:21 Hien Nguyen
  2006-05-18 17:56 ` Martin Hunt
  0 siblings, 1 reply; 4+ messages in thread
From: Hien Nguyen @ 2006-05-09 22:21 UTC (permalink / raw)
  To: Martin Hunt, SystemTAP

Hi Martin,

While working on the the systemtap GUI we run into the problem of 
getting the stdout to the gui app in a timely fashion. We does get the 
output as a blob of text once in a while (looks like data were only 
flushed out when the buffer is full). To recreate the problem you can 
try this

stap -e 'probe syscall.open{ log(filename) }' | tee

Anyway, I added one line of code to flushout the data as soon as the 
stpd gets it. It seems to solve the above problem. To avoid unnecessary 
performance issues for others, perhaps we should have that as an option. 
What do you think?

Thanks, Hien.

--- librelay.c  2006-05-09 14:49:07.000000000 -0700
+++ librelay.c.new      2006-05-09 14:34:48.000000000 -0700
@@ -789,6 +789,7 @@
                }
                case STP_REALTIME_DATA:
                        fwrite_unlocked(data, nb - sizeof(int), 1, ofp);
+                       fflush_unlocked(ofp);
                        break;
                case STP_OOB_DATA:
                        fputs ((char *)data, stderr);


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stpd and stdout
  2006-05-09 22:21 stpd and stdout Hien Nguyen
@ 2006-05-18 17:56 ` Martin Hunt
  2006-05-18 20:42   ` Hien Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Hunt @ 2006-05-18 17:56 UTC (permalink / raw)
  To: Hien Nguyen; +Cc: SystemTAP

On Tue, 2006-05-09 at 15:21 -0700, Hien Nguyen wrote:
> Hi Martin,
> 
> While working on the the systemtap GUI we run into the problem of 
> getting the stdout to the gui app in a timely fashion. We does get the 
> output as a blob of text once in a while (looks like data were only 
> flushed out when the buffer is full). To recreate the problem you can 
> try this
> 
> stap -e 'probe syscall.open{ log(filename) }' | tee
> 
> Anyway, I added one line of code to flushout the data as soon as the 
> stpd gets it. It seems to solve the above problem. To avoid unnecessary 
> performance issues for others, perhaps we should have that as an option. 
> What do you think?

I think that in this case (stdout from procfs) it should always be
line-buffered. No option is necessary.  In fact I tried it and couldn't
measure any significant performance advantage for full buffering.  I've
gone ahead and committed the following patch.  Let me know how it works.

Index: librelay.c
===================================================================
RCS file: /cvs/systemtap/src/runtime/stpd/librelay.c,v
retrieving revision 1.37
diff -u -r1.37 librelay.c
--- librelay.c  8 Apr 2006 21:59:36 -0000       1.37
+++ librelay.c  18 May 2006 17:51:31 -0000
@@ -722,6 +722,7 @@
        int type;
        FILE *ofp = stdout;

+       setvbuf(ofp, (char *)NULL, _IOLBF, 0);
        pthread_mutex_init(&processing_mutex, NULL);

        signal(SIGINT, sigproc);


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stpd and stdout
  2006-05-18 17:56 ` Martin Hunt
@ 2006-05-18 20:42   ` Hien Nguyen
  0 siblings, 0 replies; 4+ messages in thread
From: Hien Nguyen @ 2006-05-18 20:42 UTC (permalink / raw)
  To: Martin Hunt; +Cc: SystemTAP

Martin Hunt wrote:

>I think that in this case (stdout from procfs) it should always be
>line-buffered. No option is necessary.  In fact I tried it and couldn't
>measure any significant performance advantage for full buffering.  I've
>gone ahead and committed the following patch.  Let me know how it works.
>
>Index: librelay.c
>===================================================================
>RCS file: /cvs/systemtap/src/runtime/stpd/librelay.c,v
>retrieving revision 1.37
>diff -u -r1.37 librelay.c
>--- librelay.c  8 Apr 2006 21:59:36 -0000       1.37
>+++ librelay.c  18 May 2006 17:51:31 -0000
>@@ -722,6 +722,7 @@
>        int type;
>        FILE *ofp = stdout;
>
>+       setvbuf(ofp, (char *)NULL, _IOLBF, 0);
>        pthread_mutex_init(&processing_mutex, NULL);
>
>        signal(SIGINT, sigproc);
>
>
>  
>
Thanks Martin, it works.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: stpd and stdout
@ 2006-05-09 22:57 Stone, Joshua I
  0 siblings, 0 replies; 4+ messages in thread
From: Stone, Joshua I @ 2006-05-09 22:57 UTC (permalink / raw)
  To: Hien Nguyen, Martin Hunt, SystemTAP

On Tuesday, May 09, 2006 3:21 PM, Hien Nguyen wrote:
> While working on the the systemtap GUI we run into the problem of
> getting the stdout to the gui app in a timely fashion. We does get the
> output as a blob of text once in a while (looks like data were only
> flushed out when the buffer is full). To recreate the problem you can
> try this
> 
> stap -e 'probe syscall.open{ log(filename) }' | tee
> 
> Anyway, I added one line of code to flushout the data as soon as the
> stpd gets it. It seems to solve the above problem. To avoid
> unnecessary performance issues for others, perhaps we should have
> that as an option. What do you think?

I've run into this with Perl scripts before -- Perl normally
line-buffers output to STDOUT and block-buffers otherwise (e.g. to a
pipe or socket).  Their solution for this problem is an autoflush
option:
http://perldoc.perl.org/perlvar.html#HANDLE->autoflush(EXPR)

I think it would be very reasonable to support a similar command-line
option in stap/stpd.


Josh

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-05-18 20:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-09 22:21 stpd and stdout Hien Nguyen
2006-05-18 17:56 ` Martin Hunt
2006-05-18 20:42   ` Hien Nguyen
2006-05-09 22:57 Stone, Joshua I

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).