mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
integrating the existing state of TON Storage / TON Payments / CPS Fift development branches
This commit is contained in:
parent
040df63c98
commit
4e2624459b
153 changed files with 10760 additions and 1695 deletions
33
storage/LoadSpeed.cpp
Normal file
33
storage/LoadSpeed.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "LoadSpeed.h"
|
||||
|
||||
#include "td/utils/format.h"
|
||||
|
||||
namespace ton {
|
||||
void LoadSpeed::add(td::size_t size, td::Timestamp now) {
|
||||
total_size_ += size;
|
||||
events_.push(Event{size, now});
|
||||
update(now);
|
||||
}
|
||||
double LoadSpeed::speed(td::Timestamp now) const {
|
||||
update(now);
|
||||
return total_size_ / duration();
|
||||
}
|
||||
|
||||
td::StringBuilder &operator<<(td::StringBuilder &sb, const LoadSpeed &speed) {
|
||||
return sb << td::format::as_size(static_cast<td::uint64>(speed.speed())) << "/s";
|
||||
}
|
||||
|
||||
void LoadSpeed::update(td::Timestamp now) const {
|
||||
while (duration() > 60) {
|
||||
total_size_ -= events_.front().size;
|
||||
events_.pop();
|
||||
}
|
||||
}
|
||||
double LoadSpeed::duration() const {
|
||||
double res = 5;
|
||||
if (events_.size() > 1) {
|
||||
res = std::max(res, events_.back().at.at() - events_.front().at.at());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace ton
|
Loading…
Add table
Add a link
Reference in a new issue