From 02256e17cc5b9b585340c7ae9a8c97943f5507df Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 14 Jun 2013 01:37:25 -0700 Subject: gras: tweaks to dot code + dead lock dot print --- lib/top_block.cpp | 17 +++++++++++++++++ lib/top_block_query.cpp | 23 ++++++++++++++++------- query/__init__.py | 4 ++-- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/top_block.cpp b/lib/top_block.cpp index cf0fdaa..ee3f0e8 100644 --- a/lib/top_block.cpp +++ b/lib/top_block.cpp @@ -98,10 +98,27 @@ void TopBlock::wait(void) //however, thread group cant be joined twice and this breaks some qa code //(*this)->thread_group->join_all(); + boost::system_time check_done_time = boost::get_system_time(); + bool has_a_done = false; + //wait for all blocks to release the token while (not (*this)->token.unique()) { wait_thread_yield(); + if (boost::get_system_time() > check_done_time) + { + if (has_a_done) + { + std::cerr << this->query("{\"path\":\"/topology.dot\"}") << std::endl; + check_done_time += boost::posix_time::seconds(2); + } + BOOST_FOREACH(Apology::Worker *w, (*this)->executor->get_workers()) + { + BlockActor *actor = dynamic_cast(w->get_actor()); + if (actor->data->block_state == BLOCK_STATE_DONE) has_a_done = true; + } + check_done_time += boost::posix_time::seconds(1); + } } } diff --git a/lib/top_block_query.cpp b/lib/top_block_query.cpp index 1a5a408..b8bc7c2 100644 --- a/lib/top_block_query.cpp +++ b/lib/top_block_query.cpp @@ -200,7 +200,7 @@ static ptree query_props(ElementImpl *self, const ptree &query) return root; } -static std::string query_flows(ElementImpl *self, const ptree &query) +static std::string query_topology(ElementImpl *self, const ptree &query) { std::string buff; buff += "digraph flat_flows {\n"; @@ -223,17 +223,26 @@ static std::string query_flows(ElementImpl *self, const ptree &query) out_ports_str += str(boost::format(" %u") % i % i); } if (out_ports_str.size()) out_ports_str = " | {" + out_ports_str + "}"; - buff += str(boost::format("%s [shape=record, label=\"{ %s %s %s }\", style=filled];\n") - % actor->GetAddress().AsString() % in_ports_str % actor->data->block->to_string() % out_ports_str + std::string color; + switch (actor->data->block_state) + { + case BLOCK_STATE_INIT: color = "white"; break; + case BLOCK_STATE_LIVE: color = "azure"; break; + case BLOCK_STATE_DONE: color = "grey"; break; + } + buff += str(boost::format("%u [shape=record, label=\"{ %s %s %s }\", style=filled, fillcolor=%s];\n") + % actor->GetAddress().AsInteger() % in_ports_str + % actor->data->block->to_string() % out_ports_str + % color ); } BOOST_FOREACH(const Apology::Flow &flow, self->executor->get_flat_flows()) { - buff += str(boost::format("%s:out%u -> %s:in%u;\n") - % dynamic_cast(flow.src.elem)->get_actor()->GetAddress().AsString() + buff += str(boost::format("%u:out%u -> %u:in%u;\n") + % dynamic_cast(flow.src.elem)->get_actor()->GetAddress().AsInteger() % flow.src.index - % dynamic_cast(flow.dst.elem)->get_actor()->GetAddress().AsString() + % dynamic_cast(flow.dst.elem)->get_actor()->GetAddress().AsInteger() % flow.dst.index ); } @@ -250,7 +259,7 @@ std::string TopBlock::query(const std::string &args) //dispatch based on path arg std::string path = query.get("path"); ptree result; - if (path == "/flows.dot") return query_flows(this->get(), query); + if (path == "/topology.dot") return query_topology(this->get(), query); if (path == "/blocks.json") result = query_blocks(this->get(), query); if (path == "/stats.json") result = query_stats(this->get(), query); if (path == "/props.json") result = query_props(this->get(), query); diff --git a/query/__init__.py b/query/__init__.py index 40c645b..cca8354 100644 --- a/query/__init__.py +++ b/query/__init__.py @@ -26,11 +26,11 @@ class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): args = server_registry[s.server] path = o.path - if path == "/flow.png": + if path == "/topology.png": s.send_response(200) s.send_header("Content-type", "image/png") s.end_headers() - dot = args['top_block'].query(json.dumps(dict(path='/flows.dot'))) + dot = args['top_block'].query(json.dumps(dict(path='/topology.dot'))) import subprocess p = subprocess.Popen(args=["dot", "-T", "png"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = p.communicate(input=dot) -- cgit