[cache_dump/restore] add discards to the xml format

This commit is contained in:
Joe Thornber 2013-10-11 10:03:51 +01:00
parent 5dbaf8371c
commit 6b6f2290a7
3 changed files with 58 additions and 0 deletions

View File

@ -37,6 +37,12 @@ namespace caching {
virtual void hint(pd::block_address cblock,
std::vector<unsigned char> const &data) = 0;
virtual void begin_discards() = 0;
virtual void end_discards() = 0;
virtual void discard(pd::block_address dblock_begin,
pd::block_address dblock_end) = 0;
};
}

View File

@ -78,7 +78,22 @@ namespace {
virtual void hint(pd::block_address cblock,
vector<unsigned char> const &data) {
md_->hints_->set_hint(cblock, data);
}
virtual void begin_discards() {
// noop
}
virtual void end_discards() {
// noop
}
virtual void discard(block_address dblock, block_address dblock_e) {
while (dblock != dblock_e) {
md_->discard_bits_->set(dblock, true);
dblock++;
}
}
private:

View File

@ -88,6 +88,24 @@ namespace {
<< "/>" << endl;
}
virtual void begin_discards() {
indent();
out_ << "<discards>" << endl;
inc();
}
virtual void end_discards() {
dec();
indent();
out_ << "</discards>" << endl;
}
virtual void discard(block_address dblock_b, block_address dblock_e) {
indent();
out_ << "<discard dbegin=\"" << dblock_b << "\""
<< " dend=\"" << dblock_e << "\"/>" << endl;
}
private:
string as_truth(bool v) const {
return v ? "true" : "false";
@ -196,6 +214,12 @@ namespace {
e->hint(cblock, get<vector<unsigned char> >(doe));
}
// FIXME: why passing e by ptr?
void parse_discard(emitter *e, attributes const &attr) {
e->discard(get_attr<uint64_t>(attr, "dbegin"),
get_attr<uint64_t>(attr, "dend"));
}
void start_tag(void *data, char const *el, char const **attr) {
emitter *e = static_cast<emitter *>(data);
attributes a;
@ -217,6 +241,12 @@ namespace {
else if (!strcmp(el, "hint"))
parse_hint(e, a);
else if (!strcmp(el, "discards"))
e->begin_discards();
else if (!strcmp(el, "discard"))
parse_discard(e, a);
else
throw runtime_error("unknown tag type");
}
@ -241,6 +271,13 @@ namespace {
// do nothing
;
else if (!strcmp(el, "discards"))
e->end_discards();
else if (!strcmp(el, "discard"))
// do nothing
;
else
throw runtime_error("unknown tag close");
}