summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2013-06-11 00:32:47 -0700
committerJosh Blum2013-06-11 00:32:47 -0700
commit41c8e89795675cd0989aee8e88647abd941c000c (patch)
tree90cb800bbada4c165cdddf9b03a5f1c4b19ebca9
parent39b7a04a8ddac19fa694abdb963e861dc6adeee2 (diff)
downloadsandhi-41c8e89795675cd0989aee8e88647abd941c000c.tar.gz
sandhi-41c8e89795675cd0989aee8e88647abd941c000c.tar.bz2
sandhi-41c8e89795675cd0989aee8e88647abd941c000c.zip
flow: added query flat flow dot format
m---------Apology0
-rw-r--r--lib/top_block_query.cpp44
-rw-r--r--query/__init__.py11
3 files changed, 55 insertions, 0 deletions
diff --git a/Apology b/Apology
-Subproject ee3ab696bd5c93281ea0f15579389c23bcdee7b
+Subproject ab6fc7615056dd5b6c737e1f4005250fe028103
diff --git a/lib/top_block_query.cpp b/lib/top_block_query.cpp
index e1ade67..5f22e21 100644
--- a/lib/top_block_query.cpp
+++ b/lib/top_block_query.cpp
@@ -3,6 +3,7 @@
#include "element_impl.hpp"
#include "gras_impl/query_common.hpp"
#include <boost/foreach.hpp>
+#include <boost/format.hpp>
#include <boost/property_tree/ptree.hpp>
#include <Theron/DefaultAllocator.h>
#include <algorithm>
@@ -199,6 +200,48 @@ static ptree query_props(ElementImpl *self, const ptree &query)
return root;
}
+static std::string query_flows(ElementImpl *self, const ptree &query)
+{
+ std::string buff;
+ buff += "digraph flat_flows {\n";
+ buff += "rankdir=LR;\n";
+ buff += "node [shape=record];\n";
+
+ BOOST_FOREACH(Apology::Worker *w, self->executor->get_workers())
+ {
+ BlockActor *actor = dynamic_cast<BlockActor *>(w->get_actor());
+ std::string in_ports_str, out_ports_str;
+ for (size_t i = 0; i < w->get_num_inputs(); i++)
+ {
+ if (i) in_ports_str += " | ";
+ in_ports_str += str(boost::format("<in%u> %u") % i % i);
+ }
+ if (in_ports_str.size()) in_ports_str = "{" + in_ports_str + "} | ";
+ for (size_t i = 0; i < w->get_num_outputs(); i++)
+ {
+ if (i) out_ports_str += " | ";
+ out_ports_str += str(boost::format("<out%u> %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 }\"];\n")
+ % actor->GetAddress().AsString() % in_ports_str % actor->data->block->get_uid() % out_ports_str
+ );
+ }
+
+ BOOST_FOREACH(const Apology::Flow &flow, self->executor->get_flat_flows())
+ {
+ buff += str(boost::format("%s:out%u -> %s:in%u;\n")
+ % dynamic_cast<const Apology::Worker *>(flow.src.elem)->get_actor()->GetAddress().AsString()
+ % flow.src.index
+ % dynamic_cast<const Apology::Worker *>(flow.dst.elem)->get_actor()->GetAddress().AsString()
+ % flow.dst.index
+ );
+ }
+
+ buff += "}\n";
+ return buff;
+}
+
std::string TopBlock::query(const std::string &args)
{
//convert json args into property tree
@@ -207,6 +250,7 @@ std::string TopBlock::query(const std::string &args)
//dispatch based on path arg
std::string path = query.get<std::string>("path");
ptree result;
+ if (path == "/flows.dot") return query_flows(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 dc3339c..28c11a4 100644
--- a/query/__init__.py
+++ b/query/__init__.py
@@ -26,6 +26,17 @@ class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
args = server_registry[s.server]
path = o.path
+ if path == "/flow.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')))
+ import subprocess
+ open("/tmp/dot.dot", 'w').write(dot)
+ subprocess.check_call(["dot", "-T", "png", "-o", "/tmp/dot.png", "/tmp/dot.dot"])
+ s.wfile.write(open("/tmp/dot.png").read())
+ return
+
#handle json requests
if path.endswith('.json'):
s.send_response(200)