Petr Onderka has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/78835


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/win/exec-stream-helpers.cpp
M libexecstream/win/exec-stream-helpers.h
M main.cpp
5 files changed, 44 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/dumps/incremental 
refs/changes/35/78835/1

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..e3a2604 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();
+}
+
 // stream  classes
 
 class exec_istream_t : public std::istream {
diff --git a/libexecstream/win/exec-stream-helpers.cpp 
b/libexecstream/win/exec-stream-helpers.cpp
index ac624fe..69ef136 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()
+{
+    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..ab3dbc2 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();
     
     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: newchange
Gerrit-Change-Id: I137e0e488e3eb461393aa85c5fe6ff9e9cdbc6ff
Gerrit-PatchSet: 1
Gerrit-Project: operations/dumps/incremental
Gerrit-Branch: gsoc
Gerrit-Owner: Petr Onderka <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to