In general, flush in caller of dump worker rather than worker

This allows easier refactoring of workers (no dual flushes when code
changes).

Signed-off-by: Dan Mick <dan.mick@inktank.com>
This commit is contained in:
Dan Mick 2013-07-23 17:24:52 -07:00
parent c7c4c23e5f
commit ba6ca5829a
7 changed files with 15 additions and 19 deletions

View File

@ -170,11 +170,11 @@ void CephContext::do_command(std::string command, std::string args,
lgeneric_dout(this, 1) << "do_command '" << command << "' '" << args << "'" << dendl;
if (command == "perfcounters_dump" || command == "1" ||
command == "perf dump") {
_perf_counters_collection->dump_formatted(f, *out, false);
_perf_counters_collection->dump_formatted(f, false);
}
else if (command == "perfcounters_schema" || command == "2" ||
command == "perf schema") {
_perf_counters_collection->dump_formatted(f, *out, true);
_perf_counters_collection->dump_formatted(f, true);
}
else {
f->open_object_section(command.c_str());
@ -221,8 +221,8 @@ void CephContext::do_command(std::string command, std::string args,
assert(0 == "registered under wrong command?");
}
f->close_section();
f->flush(*out);
}
f->flush(*out);
delete f;
lgeneric_dout(this, 1) << "do_command '" << command << "' '" << args << "' result is " << out->length() << " bytes" << dendl;
};

View File

@ -73,8 +73,7 @@ void PerfCountersCollection::clear()
}
}
void PerfCountersCollection::dump_formatted(Formatter *f, bufferlist &bl,
bool schema)
void PerfCountersCollection::dump_formatted(Formatter *f, bool schema)
{
Mutex::Locker lck(m_lock);
f->open_object_section("perfcounter_collection");
@ -88,7 +87,6 @@ void PerfCountersCollection::dump_formatted(Formatter *f, bufferlist &bl,
}
}
f->close_section();
f->flush(bl);
}
// ---------------------------

View File

@ -136,7 +136,7 @@ public:
void add(class PerfCounters *l);
void remove(class PerfCounters *l);
void clear();
void dump_formatted(ceph::Formatter *f, bufferlist &bl, bool schema);
void dump_formatted(ceph::Formatter *f, bool schema);
private:
CephContext *m_cct;

View File

@ -1012,14 +1012,13 @@ bool OSD::asok_command(string command, string args, string format, ostream& ss)
format = "json-pretty";
Formatter *f = new_formatter(format);
if (command == "dump_ops_in_flight") {
op_tracker.dump_ops_in_flight(f, ss);
op_tracker.dump_ops_in_flight(f);
} else if (command == "dump_historic_ops") {
op_tracker.dump_historic_ops(f, ss);
op_tracker.dump_historic_ops(f);
} else if (command == "dump_op_pq_state") {
f->open_object_section("pq");
op_wq.dump(f);
f->close_section();
f->flush(ss);
} else if (command == "dump_blacklist") {
list<pair<entity_addr_t,utime_t> > bl;
OSDMapRef curmap = service.get_osdmap();
@ -1036,7 +1035,6 @@ bool OSD::asok_command(string command, string args, string format, ostream& ss)
f->close_section(); //entry
}
f->close_section(); //blacklist
f->flush(ss);
} else if (command == "dump_watchers") {
list<obj_watch_item_t> watchers;
osd_lock.Lock();
@ -1078,10 +1076,11 @@ bool OSD::asok_command(string command, string args, string format, ostream& ss)
}
f->close_section(); //watches
f->flush(ss);
} else {
assert(0 == "broken asok registration");
}
f->flush(ss);
delete f;
return true;
}

View File

@ -76,15 +76,14 @@ void OpHistory::dump_ops(utime_t now, Formatter *f)
f->close_section();
}
void OpTracker::dump_historic_ops(Formatter *f, ostream &ss)
void OpTracker::dump_historic_ops(Formatter *f)
{
Mutex::Locker locker(ops_in_flight_lock);
utime_t now = ceph_clock_now(g_ceph_context);
history.dump_ops(now, f);
f->flush(ss);
}
void OpTracker::dump_ops_in_flight(Formatter *f, ostream &ss)
void OpTracker::dump_ops_in_flight(Formatter *f)
{
Mutex::Locker locker(ops_in_flight_lock);
f->open_object_section("ops_in_flight"); // overall dump
@ -98,7 +97,6 @@ void OpTracker::dump_ops_in_flight(Formatter *f, ostream &ss)
}
f->close_section(); // list of OpRequests
f->close_section(); // overall dump
f->flush(ss);
}
void OpTracker::register_inflight_op(xlist<OpRequest*>::item *i)

View File

@ -59,8 +59,8 @@ class OpTracker {
public:
OpTracker() : seq(0), ops_in_flight_lock("OpTracker mutex") {}
void dump_ops_in_flight(Formatter *f, std::ostream& ss);
void dump_historic_ops(Formatter *f, std::ostream& ss);
void dump_ops_in_flight(Formatter *f);
void dump_historic_ops(Formatter *f);
void register_inflight_op(xlist<OpRequest*>::item *i);
void unregister_inflight_op(OpRequest *i);

View File

@ -33,7 +33,8 @@ struct MorePrinting : public DetailedStatCollector::AdditionalPrinting {
void operator()(std::ostream *out) {
bufferlist bl;
Formatter *f = new_formatter("json-pretty");
cct->get_perfcounters_collection()->dump_formatted(f, bl, 0);
cct->get_perfcounters_collection()->dump_formatted(f, 0);
f->flush(bl);
delete f;
bl.append('\0');
*out << bl.c_str() << std::endl;