From: Yan Jun Date: Tue, 25 Jul 2017 07:57:32 +0000 (+0800) Subject: osd: filter the trackedop that we needed. X-Git-Tag: v12.1.2~71^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=814de29d02912a7cd6c5e24db6d99664693b4a58;p=ceph.git osd: filter the trackedop that we needed. Signed-off-by: Yan Jun --- diff --git a/src/common/TrackedOp.cc b/src/common/TrackedOp.cc index ea3f607cfe24..bd605e54cc7c 100644 --- a/src/common/TrackedOp.cc +++ b/src/common/TrackedOp.cc @@ -68,7 +68,7 @@ void OpHistory::cleanup(utime_t now) } } -void OpHistory::dump_ops(utime_t now, Formatter *f) +void OpHistory::dump_ops(utime_t now, Formatter *f, set filters) { Mutex::Locker history_lock(ops_history_lock); cleanup(now); @@ -81,6 +81,8 @@ void OpHistory::dump_ops(utime_t now, Formatter *f) arrived.begin(); i != arrived.end(); ++i) { + if (!i->second->filter_out(filters)) + continue; f->open_object_section("op"); i->second->dump(now, f); f->close_section(); @@ -90,7 +92,7 @@ void OpHistory::dump_ops(utime_t now, Formatter *f) f->close_section(); } -void OpHistory::dump_ops_by_duration(utime_t now, Formatter *f) +void OpHistory::dump_ops_by_duration(utime_t now, Formatter *f, set filters) { Mutex::Locker history_lock(ops_history_lock); cleanup(now); @@ -107,6 +109,8 @@ void OpHistory::dump_ops_by_duration(utime_t now, Formatter *f) arrived.begin(); i != arrived.end(); ++i) { + if (!i->second->filter_out(filters)) + continue; durationvec.push_back(pair(i->second->get_duration(), i->second)); } @@ -152,7 +156,7 @@ OpTracker::~OpTracker() { } } -bool OpTracker::dump_historic_ops(Formatter *f, bool by_duration) +bool OpTracker::dump_historic_ops(Formatter *f, bool by_duration, set filters) { RWLock::RLocker l(lock); if (!tracking_enabled) @@ -160,14 +164,14 @@ bool OpTracker::dump_historic_ops(Formatter *f, bool by_duration) utime_t now = ceph_clock_now(); if (by_duration) { - history.dump_ops_by_duration(now, f); + history.dump_ops_by_duration(now, f, filters); } else { - history.dump_ops(now, f); + history.dump_ops(now, f, filters); } return true; } -void OpHistory::dump_slow_ops(utime_t now, Formatter *f) +void OpHistory::dump_slow_ops(utime_t now, Formatter *f, set filters) { Mutex::Locker history_lock(ops_history_lock); cleanup(now); @@ -180,6 +184,8 @@ void OpHistory::dump_slow_ops(utime_t now, Formatter *f) slow_op.begin(); i != slow_op.end(); ++i) { + if (!i->second->filter_out(filters)) + continue; f->open_object_section("Op"); i->second->dump(now, f); f->close_section(); @@ -189,18 +195,18 @@ void OpHistory::dump_slow_ops(utime_t now, Formatter *f) f->close_section(); } -bool OpTracker::dump_historic_slow_ops(Formatter *f) +bool OpTracker::dump_historic_slow_ops(Formatter *f, set filters) { RWLock::RLocker l(lock); if (!tracking_enabled) return false; utime_t now = ceph_clock_now(); - history.dump_slow_ops(now, f); + history.dump_slow_ops(now, f, filters); return true; } -bool OpTracker::dump_ops_in_flight(Formatter *f, bool print_only_blocked) +bool OpTracker::dump_ops_in_flight(Formatter *f, bool print_only_blocked, set filters) { RWLock::RLocker l(lock); if (!tracking_enabled) @@ -217,6 +223,8 @@ bool OpTracker::dump_ops_in_flight(Formatter *f, bool print_only_blocked) for (auto& op : sdata->ops_in_flight_sharded) { if (print_only_blocked && (now - op.get_initiated() <= complaint_time)) break; + if (!op.filter_out(filters)) + continue; f->open_object_section("op"); op.dump(now, f); f->close_section(); // this TrackedOp diff --git a/src/common/TrackedOp.h b/src/common/TrackedOp.h index 1ee81075d23f..aa8b09a4b48e 100644 --- a/src/common/TrackedOp.h +++ b/src/common/TrackedOp.h @@ -46,9 +46,9 @@ public: assert(slow_op.empty()); } void insert(utime_t now, TrackedOpRef op); - void dump_ops(utime_t now, Formatter *f); - void dump_ops_by_duration(utime_t now, Formatter *f); - void dump_slow_ops(utime_t now, Formatter *f); + void dump_ops(utime_t now, Formatter *f, set filters = {""}); + void dump_ops_by_duration(utime_t now, Formatter *f, set filters = {""}); + void dump_slow_ops(utime_t now, Formatter *f, set filters = {""}); void on_shutdown(); void set_size_and_duration(uint32_t new_size, uint32_t new_duration) { history_size = new_size; @@ -90,9 +90,9 @@ public: RWLock::WLocker l(lock); tracking_enabled = enable; } - bool dump_ops_in_flight(Formatter *f, bool print_only_blocked=false); - bool dump_historic_ops(Formatter *f, bool by_duration = false); - bool dump_historic_slow_ops(Formatter *f); + bool dump_ops_in_flight(Formatter *f, bool print_only_blocked = false, set filters = {""}); + bool dump_historic_ops(Formatter *f, bool by_duration = false, set filters = {""}); + bool dump_historic_slow_ops(Formatter *f, set filters = {""}); bool register_inflight_op(TrackedOp *i); void unregister_inflight_op(TrackedOp *i); @@ -215,6 +215,8 @@ protected: /// called when the last non-OpTracker reference is dropped virtual void _unregistered() {}; + virtual bool filter_out(const set& filters) { return true; } + public: ZTracer::Trace osd_trace; ZTracer::Trace pg_trace; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 33ee4182d185..1fafd6533271 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -2044,30 +2044,48 @@ bool OSD::asok_command(string admin_command, cmdmap_t& cmdmap, string format, } else if (admin_command == "flush_journal") { store->flush_journal(); } else if (admin_command == "dump_ops_in_flight" || - admin_command == "ops") { - if (!op_tracker.dump_ops_in_flight(f)) { - ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \ - Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards."; - } - } else if (admin_command == "dump_blocked_ops") { - if (!op_tracker.dump_ops_in_flight(f, true)) { - ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \ - Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards."; - } - } else if (admin_command == "dump_historic_ops") { - if (!op_tracker.dump_historic_ops(f, false)) { - ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \ - Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards."; - } - } else if (admin_command == "dump_historic_ops_by_duration") { - if (!op_tracker.dump_historic_ops(f, true)) { - ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \ - Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards."; - } - } else if (admin_command == "dump_historic_slow_ops") { - if (!op_tracker.dump_historic_slow_ops(f)) { - ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \ - Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards."; + admin_command == "ops" || + admin_command == "dump_blocked_ops" || + admin_command == "dump_historic_ops" || + admin_command == "dump_historic_ops_by_duration" || + admin_command == "dump_historic_slow_ops") { + + const string error_str = "op_tracker tracking is not enabled now, so no ops are tracked currently, \ +even those get stuck. Please enable \"osd_enable_op_tracker\", and the tracker \ +will start to track new ops received afterwards."; + + set filters; + vector filter_str; + if (cmd_getval(cct, cmdmap, "filterstr", filter_str)) { + copy(filter_str.begin(), filter_str.end(), + inserter(filters, filters.end())); + } + + if (admin_command == "dump_ops_in_flight" || + admin_command == "ops") { + if (!op_tracker.dump_ops_in_flight(f, false, filters)) { + ss << error_str; + } + } + if (admin_command == "dump_blocked_ops") { + if (!op_tracker.dump_ops_in_flight(f, true, filters)) { + ss << error_str; + } + } + if (admin_command == "dump_historic_ops") { + if (!op_tracker.dump_historic_ops(f, false, filters)) { + ss << error_str; + } + } + if (admin_command == "dump_historic_ops_by_duration") { + if (!op_tracker.dump_historic_ops(f, true, filters)) { + ss << error_str; + } + } + if (admin_command == "dump_historic_slow_ops") { + if (!op_tracker.dump_historic_slow_ops(f, filters)) { + ss << error_str; + } } } else if (admin_command == "dump_op_pq_state") { f->open_object_section("pq"); @@ -2684,26 +2702,38 @@ void OSD::final_init() "flush the journal to permanent store"); assert(r == 0); r = admin_socket->register_command("dump_ops_in_flight", - "dump_ops_in_flight", asok_hook, + "dump_ops_in_flight " \ + "name=filterstr,type=CephString,n=N,req=false", + asok_hook, "show the ops currently in flight"); assert(r == 0); r = admin_socket->register_command("ops", - "ops", asok_hook, + "ops " \ + "name=filterstr,type=CephString,n=N,req=false", + asok_hook, "show the ops currently in flight"); assert(r == 0); r = admin_socket->register_command("dump_blocked_ops", - "dump_blocked_ops", asok_hook, + "dump_blocked_ops " \ + "name=filterstr,type=CephString,n=N,req=false", + asok_hook, "show the blocked ops currently in flight"); assert(r == 0); - r = admin_socket->register_command("dump_historic_ops", "dump_historic_ops", + r = admin_socket->register_command("dump_historic_ops", + "dump_historic_ops " \ + "name=filterstr,type=CephString,n=N,req=false", asok_hook, "show recent ops"); assert(r == 0); - r = admin_socket->register_command("dump_historic_slow_ops", "dump_historic_slow_ops", + r = admin_socket->register_command("dump_historic_slow_ops", + "dump_historic_slow_ops " \ + "name=filterstr,type=CephString,n=N,req=false", asok_hook, "show slowest recent ops"); assert(r == 0); - r = admin_socket->register_command("dump_historic_ops_by_duration", "dump_historic_ops_by_duration", + r = admin_socket->register_command("dump_historic_ops_by_duration", + "dump_historic_ops_by_duration " \ + "name=filterstr,type=CephString,n=N,req=false", asok_hook, "show slowest recent ops, sorted by duration"); assert(r == 0); diff --git a/src/osd/OpRequest.cc b/src/osd/OpRequest.cc index 7d7f33e256a2..4a85a2c5610b 100644 --- a/src/osd/OpRequest.cc +++ b/src/osd/OpRequest.cc @@ -162,6 +162,34 @@ void OpRequest::mark_flag_point_string(uint8_t flag, const string& s) { flag, s.c_str(), old_flags, hit_flag_points); } +bool OpRequest::filter_out(const set& filters) +{ + set addrs; + for (auto it = filters.begin(); it != filters.end(); it++) { + entity_addr_t addr; + if (addr.parse((*it).c_str())) { + addrs.insert(addr); + } + } + if (addrs.empty()) + return true; + + entity_addr_t cmp_addr = req_src_inst.addr; + if (addrs.count(cmp_addr)) { + return true; + } + cmp_addr.set_nonce(0); + if (addrs.count(cmp_addr)) { + return true; + } + cmp_addr.set_port(0); + if (addrs.count(cmp_addr)) { + return true; + } + + return false; +} + ostream& operator<<(ostream& out, const OpRequest::ClassInfo& i) { out << "class " << i.name << " rd " << i.read diff --git a/src/osd/OpRequest.h b/src/osd/OpRequest.h index 8008bf08a12a..c0e77730dcb2 100644 --- a/src/osd/OpRequest.h +++ b/src/osd/OpRequest.h @@ -103,6 +103,7 @@ private: protected: void _dump_op_descriptor_unlocked(ostream& stream) const override; void _unregistered() override; + bool filter_out(const set& filters) override; public: ~OpRequest() override {