Petr Onderka has submitted this change and it was merged.
Change subject: Progress reporting on standard error stream
......................................................................
Progress reporting on standard error stream
Change-Id: I137e0e488e3eb461393aa85c5fe6ff9e9cdbc6ff
---
M XmlInput/WrapperInputStream.h
M libexecstream/exec-stream.cpp
M libexecstream/posix/exec-stream-helpers.cpp
M libexecstream/posix/exec-stream-helpers.h
M libexecstream/win/exec-stream-helpers.cpp
M libexecstream/win/exec-stream-helpers.h
M main.cpp
7 files changed, 54 insertions(+), 11 deletions(-)
Approvals:
Petr Onderka: Verified; Looks good to me, approved
diff --git a/XmlInput/WrapperInputStream.h b/XmlInput/WrapperInputStream.h
index 9637428..fd1df61 100644
--- a/XmlInput/WrapperInputStream.h
+++ b/XmlInput/WrapperInputStream.h
@@ -1,17 +1,22 @@
#include <iostream>
+#include <functional>
#include "../XML/xmlfile.h"
class WrapperInputStream : public XML::InputStream
{
private:
std::istream &wrapped;
+ std::function<void()> sideAction;
public:
- WrapperInputStream(std::istream &wrapped)
- : wrapped(wrapped)
+ WrapperInputStream(std::istream &wrapped, std::function<void()> sideAction
= nullptr)
+ : wrapped(wrapped), sideAction(sideAction)
{}
virtual int read(XML_Char *buf, size_t bufLen) override
{
+ if (sideAction != nullptr)
+ sideAction();
+
wrapped.read(buf, bufLen);
return wrapped.gcount();
}
diff --git a/libexecstream/exec-stream.cpp b/libexecstream/exec-stream.cpp
index 5f28b2e..06d3379 100644
--- a/libexecstream/exec-stream.cpp
+++ b/libexecstream/exec-stream.cpp
@@ -81,6 +81,7 @@
bool empty();
bool full( std::size_t limit ); // limit==0 -> no limit
+ std::size_t size();
void clear();
@@ -198,6 +199,11 @@
return limit!=0 && m_total_size>=limit;
}
+std::size_t buffer_list_t::size()
+{
+ return m_total_size;
+}
+
void buffer_list_t::clear()
{
for( buffers_t::iterator i=m_buffers.begin(); i!=m_buffers.end(); ++i ) {
@@ -230,9 +236,10 @@
void clear();
protected:
- virtual int_type underflow();
- virtual int_type overflow( int_type c );
- virtual int sync();
+ virtual int_type underflow() override;
+ virtual int_type overflow( int_type c ) override;
+ virtual int sync() override;
+ virtual std::streamsize showmanyc() override;
private:
bool send_buffer();
@@ -330,6 +337,11 @@
return 0;
}
+std::streamsize exec_stream_buffer_t::showmanyc()
+{
+ return m_thread_buffer.size( m_kind );
+}
+
// stream classes
class exec_istream_t : public std::istream {
diff --git a/libexecstream/posix/exec-stream-helpers.cpp
b/libexecstream/posix/exec-stream-helpers.cpp
index a1c07b7..963dce7 100644
--- a/libexecstream/posix/exec-stream-helpers.cpp
+++ b/libexecstream/posix/exec-stream-helpers.cpp
@@ -302,9 +302,9 @@
m_in_bad=false;
m_error_prefix="";
m_error_code=0;
- m_in_wait_timeout=2000;
- m_out_wait_timeout=2000;
- m_err_wait_timeout=2000;
+ m_in_wait_timeout=100000;
+ m_out_wait_timeout=100000;
+ m_err_wait_timeout=100000;
m_thread_termination_timeout=1000;
m_in_buffer_limit=0;
m_out_buffer_limit=0;
@@ -840,3 +840,9 @@
pthread_cleanup_pop( 0 );
return 0;
}
+
+std::size_t thread_buffer_t::size( exec_stream_t::stream_kind_t kind )
+{
+ buffer_list_t & buffer= kind==exec_stream_t::s_out ? m_out_buffer :
m_err_buffer;
+ return buffer.size();
+}
\ No newline at end of file
diff --git a/libexecstream/posix/exec-stream-helpers.h
b/libexecstream/posix/exec-stream-helpers.h
index 13f1eaa..5b196c4 100644
--- a/libexecstream/posix/exec-stream-helpers.h
+++ b/libexecstream/posix/exec-stream-helpers.h
@@ -192,6 +192,7 @@
void get( exec_stream_t::stream_kind_t kind, char * dst, std::size_t &
size, bool & no_more );
void put( char * src, std::size_t & size, bool & no_more );
+ std::size_t size( exec_stream_t::stream_kind_t kind );
void close_in();
bool stop_thread();
diff --git a/libexecstream/win/exec-stream-helpers.cpp
b/libexecstream/win/exec-stream-helpers.cpp
index ac624fe..85eb61f 100644
--- a/libexecstream/win/exec-stream-helpers.cpp
+++ b/libexecstream/win/exec-stream-helpers.cpp
@@ -290,7 +290,7 @@
m_error_code=ERROR_SUCCESS;
m_error_message="";
- m_wait_timeout=10000;
+ m_wait_timeout=100000;
m_buffer_limit=0;
m_read_buffer_size=4096;
@@ -725,3 +725,7 @@
m_error_message=error_message;
}
+std::size_t thread_buffer_t::size( exec_stream_t::stream_kind_t )
+{
+ return m_buffer_list.size();
+}
\ No newline at end of file
diff --git a/libexecstream/win/exec-stream-helpers.h
b/libexecstream/win/exec-stream-helpers.h
index 3cd1759..51a2931 100644
--- a/libexecstream/win/exec-stream-helpers.h
+++ b/libexecstream/win/exec-stream-helpers.h
@@ -145,6 +145,7 @@
void get( exec_stream_t::stream_kind_t kind, char * dst, std::size_t &
size, bool & no_more ); // may be called only after start_reader_thread
void put( char * const src, std::size_t & size, bool & no_more );// may be
called only after start_writer_thread
+ std::size_t size( exec_stream_t::stream_kind_t kind );
bool stop_thread();
bool abort_thread();
diff --git a/main.cpp b/main.cpp
index 5927eff..5288871 100644
--- a/main.cpp
+++ b/main.cpp
@@ -137,8 +137,22 @@
writer.SetDumpKind(DumpKind::None);
- exec_stream_t dumpBackupProcess(phpPath, dumpBackupParameters);
- WrapperInputStream dumpBackupStream(dumpBackupProcess.out());
+ exec_stream_t dumpBackupProcess;
+ dumpBackupProcess.set_buffer_limit(exec_stream_t::s_out, 8192);
+ dumpBackupProcess.start(phpPath, dumpBackupParameters);
+
+ WrapperInputStream dumpBackupStream(dumpBackupProcess.out(),
+ [&]()
+ {
+ auto &stream = dumpBackupProcess.err();
+ char buffer[1024];
+ std::streamsize count = 0;
+ do
+ {
+ count = stream.readsome(buffer, 1024);
+ std::cerr.write(buffer, count);
+ } while (count != 0);
+ });
XmlMediawikiProcessor::Process(&writer, dumpBackupStream);
--
To view, visit https://gerrit.wikimedia.org/r/78835
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I137e0e488e3eb461393aa85c5fe6ff9e9cdbc6ff
Gerrit-PatchSet: 2
Gerrit-Project: operations/dumps/incremental
Gerrit-Branch: gsoc
Gerrit-Owner: Petr Onderka <[email protected]>
Gerrit-Reviewer: Petr Onderka <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits