2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/db/binlog/Binlog.h"
|
|
|
|
|
2019-10-22 19:01:15 +02:00
|
|
|
#include "td/db/DbKey.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/format.h"
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
if (argc < 2) {
|
|
|
|
std::fprintf(stderr, "Usage: binlog_dump <binlog_file_name>\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Info {
|
|
|
|
std::size_t full_size = 0;
|
|
|
|
std::size_t compressed_size = 0;
|
|
|
|
};
|
|
|
|
std::map<td::uint64, Info> info;
|
|
|
|
|
|
|
|
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
|
|
|
|
td::Binlog binlog;
|
|
|
|
binlog
|
2019-09-28 04:14:21 +02:00
|
|
|
.init(
|
|
|
|
argv[1],
|
|
|
|
[&](auto &event) {
|
|
|
|
info[0].compressed_size += event.raw_event_.size();
|
|
|
|
info[event.type_].compressed_size += event.raw_event_.size();
|
|
|
|
},
|
|
|
|
td::DbKey::raw_key("cucumber"), td::DbKey::empty(), -1,
|
|
|
|
[&](auto &event) mutable {
|
|
|
|
info[0].full_size += event.raw_event_.size();
|
|
|
|
info[event.type_].full_size += event.raw_event_.size();
|
|
|
|
LOG(PLAIN) << "LogEvent[" << td::tag("id", td::format::as_hex(event.id_)) << td::tag("type", event.type_)
|
|
|
|
<< td::tag("flags", event.flags_) << td::tag("size", event.data_.size())
|
|
|
|
<< td::tag("data", td::format::escaped(event.data_)) << "]\n";
|
|
|
|
})
|
2018-12-31 20:04:05 +01:00
|
|
|
.ensure();
|
|
|
|
|
|
|
|
for (auto &it : info) {
|
|
|
|
LOG(ERROR) << td::tag("handler", td::format::as_hex(it.first))
|
|
|
|
<< td::tag("full_size", td::format::as_size(it.second.full_size))
|
|
|
|
<< td::tag("compressed_size", td::format::as_size(it.second.compressed_size));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|