Browse Source

Cache reporting in AZ.

cl-refactor
Gav Wood 10 years ago
parent
commit
8d6cb82083
  1. 34
      alethzero/MainWin.cpp
  2. 7
      libethereum/Client.cpp

34
alethzero/MainWin.cpp

@ -1141,10 +1141,42 @@ void Main::on_refresh_triggered()
refreshAll(); refreshAll();
} }
static std::string niceUsed(unsigned _n)
{
static const vector<std::string> c_units = { "bytes", "KB", "MB", "GB", "TB", "PB" };
unsigned u = 0;
while (_n > 10240)
{
_n /= 1024;
u++;
}
if (_n > 1000)
return toString(_n / 1000) + "." + toString((min<unsigned>(949, _n % 1000) + 50) / 100) + " " + c_units[u + 1];
else
return toString(_n) + " " + c_units[u];
}
void Main::refreshCache() void Main::refreshCache()
{ {
BlockChain::Statistics s = ethereum()->blockChain().usage(); BlockChain::Statistics s = ethereum()->blockChain().usage();
ui->cacheUsage->setText(QString("%1 bytes used").arg(s.memTotal())); QString t;
auto f = [&](unsigned n, QString l)
{
t += ("%1 " + l).arg(QString::fromStdString(niceUsed(n)));
};
f(s.memTotal(), "total");
t += " (";
f(s.memBlocks, "blocks");
t += ", ";
f(s.memReceipts, "receipts");
t += ", ";
f(s.memLogBlooms, "blooms");
t += ", ";
f(s.memBlockHashes + s.memTransactionAddresses, "hashes");
t += ", ";
f(s.memDetails, "family");
t += ")";
ui->cacheUsage->setText(t);
} }
void Main::timerEvent(QTimerEvent*) void Main::timerEvent(QTimerEvent*)

7
libethereum/Client.cpp

@ -614,7 +614,7 @@ void Client::doWork()
this_thread::sleep_for(chrono::milliseconds(100)); this_thread::sleep_for(chrono::milliseconds(100));
if (chrono::system_clock::now() - m_lastGarbageCollection > chrono::seconds(5)) if (chrono::system_clock::now() - m_lastGarbageCollection > chrono::seconds(5))
{ {
// garbage collect on watches // watches garbage collection
vector<unsigned> toUninstall; vector<unsigned> toUninstall;
{ {
Guard l(m_filterLock); Guard l(m_filterLock);
@ -627,9 +627,12 @@ void Client::doWork()
} }
for (auto i: toUninstall) for (auto i: toUninstall)
uninstallWatch(i); uninstallWatch(i);
// blockchain GC
m_bc.garbageCollect();
m_lastGarbageCollection = chrono::system_clock::now(); m_lastGarbageCollection = chrono::system_clock::now();
} }
m_bc.garbageCollect();
} }
unsigned Client::numberOf(int _n) const unsigned Client::numberOf(int _n) const

Loading…
Cancel
Save