0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd:Ⓜ️:events: Move file dumper to module.

This commit is contained in:
Jason Volk 2019-05-31 17:48:55 -07:00
parent ca36b44452
commit 9661db89af
3 changed files with 93 additions and 69 deletions

View file

@ -37,6 +37,9 @@ namespace ircd::m::events
bool for_each(const range &, const closure_bool &);
bool for_each(const range &, const event_filter &, const closure_bool &);
// util
void dump__file(const string_view &filename);
}
/// Range to start (inclusive) and stop (exclusive). If start is greater than

View file

@ -6176,75 +6176,7 @@ console_cmd__events__dump(opt &out, const string_view &line)
param.at(0)
};
const fs::fd file
{
filename, std::ios::out | std::ios::app
};
const unique_buffer<mutable_buffer> buf
{
size_t(events_dump_buffer_size)
};
char *pos{data(buf)};
size_t foff{0}, ecount{0}, acount{0}, errcount{0};
m::events::for_each(m::event::idx{0}, [&]
(const m::event::idx &seq, const m::event &event)
{
const auto remain
{
size_t(data(buf) + size(buf) - pos)
};
assert(remain >= m::event::MAX_SIZE && remain <= size(buf));
const mutable_buffer mb{pos, remain};
pos += json::print(mb, event);
++ecount;
if(pos + m::event::MAX_SIZE > data(buf) + size(buf))
{
const const_buffer cb{data(buf), pos};
foff += size(fs::append(file, cb));
pos = data(buf);
++acount;
const double pct
{
(seq / double(m::vm::sequence::retired)) * 100.0
};
log::info
{
"dump[%s] %lf$%c @ seq %zu of %zu; %zu events; %zu bytes; %zu writes; %zu errors",
filename,
pct,
'%', //TODO: fix gram
seq,
m::vm::sequence::retired,
ecount,
foff,
acount,
errcount
};
}
return true;
});
if(pos > data(buf))
{
const const_buffer cb{data(buf), pos};
foff += size(fs::append(file, cb));
++acount;
}
out << "Dumped " << ecount << " events"
<< " using " << foff << " bytes"
<< " in " << acount << " writes"
<< " to " << filename
<< " with " << errcount << " errors"
<< std::endl;
m::events::dump__file(filename);
return true;
}

View file

@ -8,12 +8,101 @@
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
namespace ircd::m::events
{
extern conf::item<size_t> dump_buffer_size;
}
ircd::mapi::header
IRCD_MODULE
{
"Matrix events library"
};
decltype(ircd::m::events::dump_buffer_size)
ircd::m::events::dump_buffer_size
{
{ "name", "ircd.m.events.dump.buffer_size" },
{ "default", int64_t(4_MiB) },
};
void
IRCD_MODULE_EXPORT
ircd::m::events::dump__file(const string_view &filename)
{
const fs::fd file
{
filename, std::ios::out | std::ios::app
};
const unique_buffer<mutable_buffer> buf
{
size_t(dump_buffer_size)
};
char *pos{data(buf)};
size_t foff{0}, ecount{0}, acount{0}, errcount{0};
for_each(m::event::idx{0}, [&]
(const event::idx &seq, const m::event &event)
{
const auto remain
{
size_t(data(buf) + size(buf) - pos)
};
assert(remain >= event::MAX_SIZE && remain <= size(buf));
const mutable_buffer mb{pos, remain};
pos += copy(mb, event.source);
++ecount;
if(pos + event::MAX_SIZE > data(buf) + size(buf))
{
const const_buffer cb{data(buf), pos};
foff += size(fs::append(file, cb));
pos = data(buf);
++acount;
const double pct
{
(seq / double(m::vm::sequence::retired)) * 100.0
};
log::info
{
"dump[%s] %0.2lf$%c @ seq %zu of %zu; %zu events; %zu bytes; %zu writes; %zu errors",
filename,
pct,
'%', //TODO: fix gram
seq,
m::vm::sequence::retired,
ecount,
foff,
acount,
errcount
};
}
return true;
});
if(pos > data(buf))
{
const const_buffer cb{data(buf), pos};
foff += size(fs::append(file, cb));
++acount;
}
log::notice
{
log, "dump[%s] complete events:%zu using %s in writes:%zu errors:%zu",
filename,
ecount,
pretty(iec(foff)),
acount,
errcount,
};
}
bool
IRCD_MODULE_EXPORT
ircd::m::events::for_each(const range &range,