瀏覽代碼

Add numStoppedTotal key to aria2.getGlobalStat() RPC method response

It shows the number of stopped downloads in the current session and
not capped by --max-download-result option. On the other hand, the
existing numStopped key also shows the number of stopped downloads,
but it is capped by --max-download-result option.
Tatsuhiro Tsujikawa 11 年之前
父節點
當前提交
1462d6536a
共有 4 個文件被更改,包括 20 次插入2 次删除
  1. 6 1
      doc/manual-src/en/aria2c.rst
  2. 3 1
      src/RequestGroupMan.cc
  3. 9 0
      src/RequestGroupMan.h
  4. 2 0
      src/RpcMethodImpl.cc

+ 6 - 1
doc/manual-src/en/aria2c.rst

@@ -3047,7 +3047,12 @@ For *secret* parameter, see :ref:`rpc_auth`.
     The number of waiting downloads.
 
   ``numStopped``
-    The number of stopped downloads.
+    The number of stopped downloads in the current session. This value
+    is capped by :option:`--max-download-result` option.
+
+  ``numStoppedTotal``
+    The number of stopped downloads in the current session and not
+    capped by :option:`--max-download-result` option.
 
   **JSON-RPC Example**
   ::

+ 3 - 1
src/RequestGroupMan.cc

@@ -115,7 +115,8 @@ RequestGroupMan::RequestGroupMan
     removedLastErrorResult_(error_code::FINISHED),
     maxDownloadResult_(option->getAsInt(PREF_MAX_DOWNLOAD_RESULT)),
     wrDiskCache_(nullptr),
-    numOpenFile_(0)
+    numOpenFile_(0),
+    numStoppedTotal_(0)
 {
   appendReservedGroup(reservedGroups_,
                       requestGroups.begin(), requestGroups.end());
@@ -832,6 +833,7 @@ bool RequestGroupMan::removeDownloadResult(a2_gid_t gid)
 
 void RequestGroupMan::addDownloadResult(const std::shared_ptr<DownloadResult>& dr)
 {
+  ++numStoppedTotal_;
   bool rv = downloadResults_.push_back(dr->gid->getNumericId(), dr);
   assert(rv);
   while(downloadResults_.size() > maxDownloadResult_){

+ 9 - 0
src/RequestGroupMan.h

@@ -106,6 +106,10 @@ private:
 
   size_t numOpenFile_;
 
+  // The number of stopped downloads so far in total, including
+  // evicted DownloadResults.
+  size_t numStoppedTotal_;
+
   void formatDownloadResultFull
   (OutputFile& out,
    const char* status,
@@ -359,6 +363,11 @@ public:
   void ensureMaxOpenFileLimit(size_t numNewFile);
   // Reduces the number of open files managed by this object.
   void reduceNumOfOpenedFile(size_t numCloseFile);
+
+  size_t getNumStoppedTotal() const
+  {
+    return numStoppedTotal_;
+  }
 };
 
 } // namespace aria2

+ 2 - 0
src/RpcMethodImpl.cc

@@ -142,6 +142,7 @@ const char KEY_SERVERS[] = "servers";
 const char KEY_NUM_WAITING[] = "numWaiting";
 const char KEY_NUM_STOPPED[] = "numStopped";
 const char KEY_NUM_ACTIVE[] = "numActive";
+const char KEY_NUM_STOPPED_TOTAL[] = "numStoppedTotal";
 } // namespace
 
 namespace {
@@ -1341,6 +1342,7 @@ std::unique_ptr<ValueBase> GetGlobalStatRpcMethod::process
   res->put(KEY_UPLOAD_SPEED, util::itos(ts.uploadSpeed));
   res->put(KEY_NUM_WAITING, util::uitos(rgman->getReservedGroups().size()));
   res->put(KEY_NUM_STOPPED, util::uitos(rgman->getDownloadResults().size()));
+  res->put(KEY_NUM_STOPPED_TOTAL, util::uitos(rgman->getNumStoppedTotal()));
   res->put(KEY_NUM_ACTIVE, util::uitos(rgman->getRequestGroups().size()));
   return std::move(res);
 }