bin: workaround flushing issues
* bin/common_cout.cc (check_cout): Force a flush of cout if more than 20ms has elapsed since the last explicit flush. * bin/common_setup.cc (setup): Untie cin and cout if the input is not a TTY, so that cout is flush less often. * NEWS: Mention the change.
This commit is contained in:
parent
0678d1a662
commit
0c9c4be4ae
3 changed files with 44 additions and 6 deletions
8
NEWS
8
NEWS
|
|
@ -13,6 +13,14 @@ New in spot 2.1.1.dev (not yet released)
|
|||
- Fix spurious uninitialized read reported by valgrind when
|
||||
is_Kleene_star() is compiled by clang++.
|
||||
|
||||
- Using "ltlfilt some-large-file --some-costly-filter" could take
|
||||
to a lot of time before displaying the first results, because the
|
||||
output of ltlfilt is buffered: the buffer had to fill up before
|
||||
being flushed. The issue did not manifest when the input is
|
||||
standard input, because of the C++ feature that reading std::cin
|
||||
should flush std::cout; however it was well visible when reading
|
||||
from files. Flushing is now done more regularly.
|
||||
|
||||
New in spot 2.1.1 (2016-09-20)
|
||||
|
||||
Command-line tools:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2012 Laboratoire de Recherche et Développement de
|
||||
// Copyright (C) 2012, 2016 Laboratoire de Recherche et Développement de
|
||||
// l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -20,18 +20,42 @@
|
|||
#include "common_sys.hh"
|
||||
#include "common_cout.hh"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include "error.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
static std::chrono::steady_clock::time_point last_flush;
|
||||
|
||||
static void do_check_cout()
|
||||
{
|
||||
// Make sure we abort if we can't write to std::cout anymore
|
||||
// (like disk full or broken pipe with SIGPIPE ignored).
|
||||
if (!std::cout)
|
||||
error(2, 0, "error writing to standard output");
|
||||
}
|
||||
}
|
||||
|
||||
void check_cout()
|
||||
{
|
||||
// Make sure we abort if we can't write to std::cout anymore
|
||||
// (like disk full or broken pipe with SIGPIPE ignored).
|
||||
if (!std::cout)
|
||||
error(2, 0, "error writing to standard output");
|
||||
// If we haven't flushed explicitly for more than 20ms, do it now.
|
||||
// Otherwise we would have to wait for the buffer to fill up, and
|
||||
// this could take a long time.
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto ms =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(now - last_flush);
|
||||
if (ms.count() >= 20)
|
||||
{
|
||||
last_flush = now;
|
||||
std::cout.flush();
|
||||
}
|
||||
|
||||
do_check_cout();
|
||||
}
|
||||
|
||||
void flush_cout()
|
||||
{
|
||||
last_flush = std::chrono::steady_clock::now();
|
||||
std::cout.flush();
|
||||
check_cout();
|
||||
do_check_cout();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "argp.h"
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
|
|
@ -83,6 +84,11 @@ setup(char** argv)
|
|||
argp_err_exit_status = 2;
|
||||
|
||||
std::ios_base::sync_with_stdio(false);
|
||||
// Do not flush std::cout every time we read from std::cin, unless
|
||||
// we are reading from a terminal. Note that we do flush regularly
|
||||
// in check_cout().
|
||||
if (!isatty(STDIN_FILENO))
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
setup_default_output_format();
|
||||
setup_sig_handler();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue