Csound Csound-dev Csound-tekno Search About

[Cs-dev] Unbuffered Output

Date2005-01-24 06:22
Fromsteven yi
Subject[Cs-dev] Unbuffered Output
Hi All,

For a long while with blue and csound, when running csound, output from 
csound out to stdout had been buffered in chunks.  Thus, when running 
from blue, output to the console would not be timely as it would be when 
running from the commandline.  I think the amount it buffered before 
outputing to screen from blue would be 4K worth of text, then a flush. 

In my version of csound4, I recently added:

  setbuf(stdout, NULL);

to ccsound.c.  By making stdout unbuffered, all output would now go to 
blue and out to the console in a timely manner. 

I would like to add this to both repository.  In csound4, this would be 
in csound/ccsound.c, and in csound5, I believe the change would be added 
in frontends/csound/csound_main.c. 

My question is, does anyone explicitly need stdout to be buffered?  If 
not, this does greatly improve things for me and blue (for a long time I 
thought it was an issue of something to recode in blue!), and it's a 
change I would greatly appreciate having in both repositories.

Thanks,
steven


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-01-24 09:10
Fromjpff@codemist.co.uk
SubjectRe: [Cs-dev] Unbuffered Output
Making stdout unbuffered will slow down output to the terminal
surely.  Normally it is stderr that is unbuffered, and stdout line
buffered.  I am not saying no, just suggesting caution.
==John ffitch


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-01-24 16:14
Fromsteven yi
SubjectRe: [Cs-dev] Unbuffered Output
Hi John,

Thanks for the caution.  I tried setting the buffering of stdout to use 
linebuffering instead of being unbuffered and that seems to work well 
for me in blue as well. 

Taking a look at stdio.h and then to libio.h, it seems that I was wrong 
and the default size for block buffering is 8192 bytes on my system. 

I think setting to line buffering would be good for me, and hopefully 
won't be too bad for others.  I'll wait until tonight to hear from 
others and also for me to experiment a bit more, if all is well I will 
check it in.

Thanks,
steven

jpff@codemist.co.uk wrote:

>Making stdout unbuffered will slow down output to the terminal
>surely.  Normally it is stderr that is unbuffered, and stdout line
>buffered.  I am not saying no, just suggesting caution.
>==John ffitch
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
>Tool for open source databases. Create drag-&-drop reports. Save time
>by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
>Download a FREE copy at http://www.intelliview.com/go/osdn_nl
>_______________________________________________
>Csound-devel mailing list
>Csound-devel@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>
>  
>



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-01-24 18:00
Fromjpff@codemist.co.uk
SubjectRe: [Cs-dev] Unbuffered Output
Should one not use line buffering if going to a terminal, and other
buffering if going to a pipe?  Can be done on Unix anyway using
isatty(3). 
==John ffitch


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-01-24 18:20
Fromsteven yi
SubjectRe: [Cs-dev] Unbuffered Output
Hi John,

This is all new to me, so thanks very much for letting me know about 
this.  I checked in MSDN and found this entry for _isatty:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt__isatty.asp

So it seems like there is a version of the function but with a different 
name.  I've been unable to compile csound5 on windows but have been able 
to for csound4.  I will give it a try with csound4 on win, linux, and 
osx to check do a check with isatty and if not a terminal to use 
linebuffering, otherwise don't do anything and use the default, as the 
behavior is now. If that is working, I will incorporate into csound5.

steven


jpff@codemist.co.uk wrote:
> Should one not use line buffering if going to a terminal, and other
> buffering if going to a pipe?  Can be done on Unix anyway using
> isatty(3). 
> ==John ffitch
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
> Tool for open source databases. Create drag-&-drop reports. Save time
> by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
> Download a FREE copy at http://www.intelliview.com/go/osdn_nl
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 
> 



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-01-24 20:15
Fromsteven yi
SubjectRe: [Cs-dev] Unbuffered Output
Hi All,

I tried this using MinGW and csound4:

   if(!isatty(fileno(stdout)))
   {
   	setvbuf(stdout, (char *)NULL, _IONBF, 0);
   }	

This sets it to no buffering if csound is not outputing to a terminal. 
I tried with line-buffering on windows and it seemed to have the same 
behavior as if it was fully buffered.  Setting to non-buffering worked 
as line-buffering did on Linux.

This makes me want to prefer using no buffering if going to a pipe, and 
default buffering if to terminal.

Interestingly enough, it seems that the mingw header for io.h has isatty 
and fileno defined.  I am not sure that is the case if compiled with 
Microsoft's compiler and headers though (I do not have or use them).  If 
someone could try this out on csound4 in csound/csound/ccsound.c:

#if !defined(__MACH__) || !defined(RTAUDIO)
int main(int argc, char **argv)
{

   // set stdout to non buffering if not outputing to console window
   if(!isatty(fileno(stdout)))
   {
   	setvbuf(stdout, (char *)NULL, _IONBF, 0);
   }	


   void *csound = csoundCreate(0);
   int rc = csoundPerform(csound, argc, argv);
   csoundCleanup(csound);
   csoundReset(csound);
   csoundDestroy(csound);
   return rc;
}
#endif

I would be most appreciative to see if this works and there won't have 
to be any #ifdef's.

Thanks,
steven



steven yi wrote:
> Hi John,
> 
> This is all new to me, so thanks very much for letting me know about 
> this.  I checked in MSDN and found this entry for _isatty:
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt__isatty.asp 
> 
> 
> So it seems like there is a version of the function but with a different 
> name.  I've been unable to compile csound5 on windows but have been able 
> to for csound4.  I will give it a try with csound4 on win, linux, and 
> osx to check do a check with isatty and if not a terminal to use 
> linebuffering, otherwise don't do anything and use the default, as the 
> behavior is now. If that is working, I will incorporate into csound5.
> 
> steven
> 
> 
> jpff@codemist.co.uk wrote:
> 
>> Should one not use line buffering if going to a terminal, and other
>> buffering if going to a pipe?  Can be done on Unix anyway using
>> isatty(3). ==John ffitch
>>
>>


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-01-24 21:20
FromAnthony Kozar
SubjectRe: [Cs-dev] Unbuffered Output
The MacOS 9 version of Csound already includes a commandline option for
changing the buffer size on stdout (-V or --screen-buffer).  Perhaps you
could just use this? (No reason it shouldn't work on other platforms, I
think).

Regardless, I don't think your changes to ccsound.c will affect the MacOS 9
build (i.e. it shouldn't break the existing -V option).

Anthony Kozar
anthony.kozar@utoledo.edu
http://akozar.spymac.net/


On 1/24/05 1:22 AM, steven yi  etched in stone:

> I would like to add this to both repository.  In csound4, this would be
> in csound/ccsound.c, and in csound5, I believe the change would be added
> in frontends/csound/csound_main.c.
> 
> My question is, does anyone explicitly need stdout to be buffered?  If
> not, this does greatly improve things for me and blue (for a long time I
> thought it was an issue of something to recode in blue!), and it's a
> change I would greatly appreciate having in both repositories.



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-01-25 08:15
Fromsteven yi
SubjectRe: [Cs-dev] Unbuffered Output
Hi Anthony,

Thanks for chiming in.  I would prefer not to require -V and it seems 
that if it won't affect OS9 and since it is only for cases of when 
stdout is being piped to another output besides console, then it should 
be safe for me to edit.  Since Michael also has interests in things 
being nonbuffered, I have gone ahead checked in the code.

Thanks everyone for helping out on this!
steven

Anthony Kozar wrote:

>The MacOS 9 version of Csound already includes a commandline option for
>changing the buffer size on stdout (-V or --screen-buffer).  Perhaps you
>could just use this? (No reason it shouldn't work on other platforms, I
>think).
>
>Regardless, I don't think your changes to ccsound.c will affect the MacOS 9
>build (i.e. it shouldn't break the existing -V option).
>
>Anthony Kozar
>anthony.kozar@utoledo.edu
>http://akozar.spymac.net/
>
>  
>



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-01-29 20:39
Fromramsdell@mitre.org (John D. Ramsdell)
SubjectRe: [Cs-dev] Unbuffered Output
Steven,

In Csound 4, csound/ccsound.cpp had:

    if(!isatty(fileno(stdout)))
    {
      setvbuf(stdout, (char *)NULL, _IONBF, 0);
    }	
    setlinebuf(stdout);

But I'm guessing you didn't mean to include the call to setlinebuf.
MinGW doesn't have this function, and your note leaves it out too.  I
removed it.

John

steven yi  writes:

> Hi All,
> 
> I tried this using MinGW and csound4:
> 
>    if(!isatty(fileno(stdout)))
>    {
>    	setvbuf(stdout, (char *)NULL, _IONBF, 0);
>    }	
> 
> This sets it to no buffering if csound is not outputing to a
> terminal. I tried with line-buffering on windows and it seemed to have
> the same behavior as if it was fully buffered.  Setting to
> non-buffering worked as line-buffering did on Linux.
> 
> This makes me want to prefer using no buffering if going to a pipe,
> and default buffering if to terminal.
> 
> Interestingly enough, it seems that the mingw header for io.h has
> isatty and fileno defined.  I am not sure that is the case if compiled
> with Microsoft's compiler and headers though (I do not have or use
> them).  If someone could try this out on csound4 in
> csound/csound/ccsound.c:
> 
> #if !defined(__MACH__) || !defined(RTAUDIO)
> int main(int argc, char **argv)
> {
> 
>    // set stdout to non buffering if not outputing to console window
>    if(!isatty(fileno(stdout)))
>    {
>    	setvbuf(stdout, (char *)NULL, _IONBF, 0);
>    }	
> 
> 
>    void *csound = csoundCreate(0);
>    int rc = csoundPerform(csound, argc, argv);
>    csoundCleanup(csound);
>    csoundReset(csound);
>    csoundDestroy(csound);
>    return rc;
> }
> #endif
> 
> I would be most appreciative to see if this works and there won't have
> to be any #ifdef's.
> 
> Thanks,
> steven
> 
> 
> 
> steven yi wrote:
> > Hi John,
> > This is all new to me, so thanks very much for letting me know about
> > this.  I checked in MSDN and found this entry for _isatty:
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt__isatty.asp
> > So it seems like there is a version of the function but with a
> > different name.  I've been unable to compile csound5 on windows but
> > have been able to for csound4.  I will give it a try with csound4 on
> > win, linux, and osx to check do a check with isatty and if not a
> > terminal to use linebuffering, otherwise don't do anything and use
> > the default, as the behavior is now. If that is working, I will
> > incorporate into csound5.
> > steven
> > jpff@codemist.co.uk wrote:
> >
> >> Should one not use line buffering if going to a terminal, and other
> >> buffering if going to a pipe?  Can be done on Unix anyway using
> >> isatty(3). ==John ffitch
> >>
> >>
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
> Tool for open source databases. Create drag-&-drop reports. Save time
> by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
> Download a FREE copy at http://www.intelliview.com/go/osdn_nl
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-01-30 00:54
Fromsteven yi
SubjectRe: [Cs-dev] Unbuffered Output
Hi John,

Thanks for taking that out.  I should have been more careful when 
committing.  The code that calls setvbuf is straight from the man page 
for what setlinebuf is an alias for; I ended up using the setvbuf line 
precisely because setlinebuf wasn't available with mingw.  Sorry about 
the extra code!

steven

John D. Ramsdell wrote:

>Steven,
>
>In Csound 4, csound/ccsound.cpp had:
>
>    if(!isatty(fileno(stdout)))
>    {
>      setvbuf(stdout, (char *)NULL, _IONBF, 0);
>    }	
>    setlinebuf(stdout);
>
>But I'm guessing you didn't mean to include the call to setlinebuf.
>MinGW doesn't have this function, and your note leaves it out too.  I
>removed it.
>
>John
>  
>



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net