ConsoleStatCalc.cc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "ConsoleStatCalc.h"
  36. #include "RequestGroupMan.h"
  37. #include "RequestGroup.h"
  38. #include "FileAllocationMan.h"
  39. #include "FileAllocationEntry.h"
  40. #include "CheckIntegrityMan.h"
  41. #include "CheckIntegrityEntry.h"
  42. #include "Util.h"
  43. #ifdef ENABLE_BITTORRENT
  44. # include "BtContext.h"
  45. #endif // ENABLE_BITTORRENT
  46. #include <iomanip>
  47. #include <iostream>
  48. namespace aria2 {
  49. void
  50. ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan,
  51. const FileAllocationManHandle& fileAllocationMan,
  52. const CheckIntegrityManHandle& checkIntegrityMan)
  53. {
  54. if(!_cp.elapsed(1)) {
  55. return;
  56. }
  57. _cp.reset();
  58. std::cout << "\r ";
  59. std::cout << "\r";
  60. if(requestGroupMan->countRequestGroup() > 0) {
  61. RequestGroupHandle firstRequestGroup = requestGroupMan->getRequestGroup(0);
  62. TransferStat stat = firstRequestGroup->calculateStat();
  63. int32_t eta = 0;
  64. if(firstRequestGroup->getTotalLength() > 0 && stat.getDownloadSpeed() > 0) {
  65. eta = (firstRequestGroup->getTotalLength()-firstRequestGroup->getCompletedLength())/stat.getDownloadSpeed();
  66. }
  67. std::cout << "["
  68. << "#" << firstRequestGroup->getGID() << " ";
  69. #ifdef ENABLE_BITTORRENT
  70. if(firstRequestGroup->downloadFinished() &&
  71. !BtContextHandle(firstRequestGroup->getDownloadContext()).isNull()) {
  72. std::cout << "SEEDING" << "(" << "ratio:"
  73. << std::fixed << std::setprecision(1)
  74. << ((stat.getAllTimeUploadLength()*10)/firstRequestGroup->getCompletedLength())/10.0
  75. << ")";
  76. } else
  77. #endif // ENABLE_BITTORRENT
  78. {
  79. std::cout << "SIZE:"
  80. << Util::abbrevSize(firstRequestGroup->getCompletedLength())
  81. << "B"
  82. << "/"
  83. << Util::abbrevSize(firstRequestGroup->getTotalLength())
  84. << "B";
  85. if(firstRequestGroup->getTotalLength() > 0) {
  86. std::cout << "("
  87. << 100*firstRequestGroup->getCompletedLength()/firstRequestGroup->getTotalLength()
  88. << "%)";
  89. }
  90. }
  91. std::cout << " "
  92. << "CN:"
  93. << firstRequestGroup->getNumConnection();
  94. if(!firstRequestGroup->downloadFinished()) {
  95. std::cout << " "
  96. << "SPD:"
  97. << std::fixed << std::setprecision(2) << stat.getDownloadSpeed()/1024.0 << "KiB/s";
  98. }
  99. if(stat.getSessionUploadLength() > 0) {
  100. std::cout << " "
  101. << "UP:"
  102. << std::fixed << std::setprecision(2) << stat.getUploadSpeed()/1024.0 << "KiB/s"
  103. << "(" << Util::abbrevSize(stat.getAllTimeUploadLength()) << "B)";
  104. }
  105. if(eta > 0) {
  106. std::cout << " "
  107. << "ETA:"
  108. << Util::secfmt(eta);
  109. }
  110. std::cout << "]";
  111. if(requestGroupMan->countRequestGroup() > 1) {
  112. std::cout << "("
  113. << requestGroupMan->countRequestGroup()-1
  114. << "more...)";
  115. }
  116. }
  117. if(requestGroupMan->countRequestGroup() > 1 &&
  118. !requestGroupMan->downloadFinished()) {
  119. TransferStat stat = requestGroupMan->calculateStat();
  120. std::cout << " "
  121. << "[TOTAL SPD:"
  122. << std::fixed << std::setprecision(2) << stat.getDownloadSpeed()/1024.0 << "KiB/s" << "]";
  123. }
  124. {
  125. FileAllocationEntryHandle entry = fileAllocationMan->getCurrentFileAllocationEntry();
  126. if(!entry.isNull()) {
  127. std::cout << " "
  128. << "[FileAlloc:"
  129. << "#" << entry->getRequestGroup()->getGID() << " "
  130. << Util::abbrevSize(entry->getCurrentLength())
  131. << "B"
  132. << "/"
  133. << Util::abbrevSize(entry->getTotalLength())
  134. << "B"
  135. << "(";
  136. if(entry->getTotalLength() > 0) {
  137. std::cout << 100*entry->getCurrentLength()/entry->getTotalLength();
  138. } else {
  139. std::cout << "--";
  140. }
  141. std::cout << "%)"
  142. << "]";
  143. if(fileAllocationMan->countFileAllocationEntryInQueue() > 0) {
  144. std::cout << "("
  145. << fileAllocationMan->countFileAllocationEntryInQueue()
  146. << "waiting...)";
  147. }
  148. }
  149. }
  150. #ifdef ENABLE_MESSAGE_DIGEST
  151. {
  152. CheckIntegrityEntryHandle entry = checkIntegrityMan->getFirstCheckIntegrityEntry();
  153. if(!entry.isNull()) {
  154. std::cout << " "
  155. << "[Checksum:"
  156. << "#" << entry->getRequestGroup()->getGID() << " "
  157. << Util::abbrevSize(entry->getCurrentLength())
  158. << "B"
  159. << "/"
  160. << Util::abbrevSize(entry->getTotalLength())
  161. << "B"
  162. << "("
  163. << 100*entry->getCurrentLength()/entry->getTotalLength()
  164. << "%)";
  165. std::cout << "]";
  166. if(checkIntegrityMan->countCheckIntegrityEntry() > 1) {
  167. std::cout << "("
  168. << checkIntegrityMan->countCheckIntegrityEntry()-1
  169. << "more...)";
  170. }
  171. }
  172. }
  173. #endif // ENABLE_MESSAGE_DIGEST
  174. std::cout << std::flush;
  175. }
  176. } // namespace aria2