diff options
author | Josh Blum | 2013-06-01 14:56:00 -0700 |
---|---|---|
committer | Josh Blum | 2013-06-01 14:56:00 -0700 |
commit | 618c0467762e3610f7e2afa48016183ff3a67060 (patch) | |
tree | aaeff5d5bb51b44fbf41d2a5a8bf0a7100335ed3 | |
parent | e0de6c31bbc3d0cde7b5907beb952d9411fd2d13 (diff) | |
download | sandhi-618c0467762e3610f7e2afa48016183ff3a67060.tar.gz sandhi-618c0467762e3610f7e2afa48016183ff3a67060.tar.bz2 sandhi-618c0467762e3610f7e2afa48016183ff3a67060.zip |
props: added prop query to blocks + qa test
-rw-r--r-- | lib/top_block_query.cpp | 59 | ||||
-rw-r--r-- | query/chart_factory.js | 2 | ||||
-rw-r--r-- | query/chart_overhead_compare.js | 7 | ||||
-rw-r--r-- | query/main.html | 2 | ||||
-rw-r--r-- | query/main.js | 2 | ||||
-rw-r--r-- | tests/query_test.py | 17 |
6 files changed, 43 insertions, 46 deletions
diff --git a/lib/top_block_query.cpp b/lib/top_block_query.cpp index 3905faf..8634f20 100644 --- a/lib/top_block_query.cpp +++ b/lib/top_block_query.cpp @@ -47,9 +47,29 @@ static std::string query_blocks(ElementImpl *self, const boost::property_tree::p boost::property_tree::ptree e; BOOST_FOREACH(Apology::Worker *worker, self->executor->get_workers()) { - boost::property_tree::ptree t; - t.put_value(dynamic_cast<BlockActor *>(worker)->block_ptr->to_string()); - e.push_back(std::make_pair("", t)); + BlockActor *block = dynamic_cast<BlockActor *>(worker); + boost::property_tree::ptree prop_e; + typedef std::pair<std::string, PropertyRegistryPair> PropRegistryKVP; + BOOST_FOREACH(const PropRegistryKVP &p, block->property_registry) + { + boost::property_tree::ptree prop_attrs; + if (p.second.setter) + { + boost::property_tree::ptree type; + type.put_value(p.second.setter->type().name()); + prop_attrs.push_back(std::make_pair("setter", type)); + } + if (p.second.getter) + { + boost::property_tree::ptree type; + type.put_value(p.second.getter->type().name()); + prop_attrs.push_back(std::make_pair("getter", type)); + } + boost::property_tree::ptree block_attrs; + block_attrs.push_back(std::make_pair(p.first, prop_attrs)); + prop_e.push_back(std::make_pair("props", block_attrs)); + } + e.push_back(std::make_pair(block->block_ptr->to_string(), prop_e)); } root.push_back(std::make_pair("blocks", e)); return my_write_json(root); @@ -155,38 +175,6 @@ static std::string query_stats(ElementImpl *self, const boost::property_tree::pt return my_write_json(root); } -static std::string query_props(ElementImpl *self, const boost::property_tree::ptree &) -{ - boost::property_tree::ptree root; - boost::property_tree::ptree e; - BOOST_FOREACH(Apology::Worker *worker, self->executor->get_workers()) - { - BlockActor *block = dynamic_cast<BlockActor *>(worker); - boost::property_tree::ptree prop_e; - typedef std::pair<std::string, PropertyRegistryPair> PropRegistryKVP; - BOOST_FOREACH(const PropRegistryKVP &p, block->property_registry) - { - boost::property_tree::ptree attrs; - if (p.second.setter) - { - boost::property_tree::ptree type; - type.put_value(p.second.setter->type().name()); - attrs.push_back(std::make_pair("set_type", type)); - } - if (p.second.getter) - { - boost::property_tree::ptree type; - type.put_value(p.second.getter->type().name()); - attrs.push_back(std::make_pair("get_type", type)); - } - prop_e.push_back(std::make_pair(p.first, attrs)); - } - e.push_back(std::make_pair(block->block_ptr->to_string(), prop_e)); - } - root.push_back(std::make_pair("props", e)); - return my_write_json(root); -} - std::string TopBlock::query(const std::string &args) { //why the fuck does no OS ever patch boost when there is a bug @@ -200,6 +188,5 @@ std::string TopBlock::query(const std::string &args) std::string path = query_args_pt.get<std::string>("args.path"); if (path == "/blocks.json") return query_blocks(this->get(), query_args_pt); if (path == "/stats.json") return query_stats(this->get(), query_args_pt); - if (path == "/props.json") return query_props(this->get(), query_args_pt); return ""; } diff --git a/query/chart_factory.js b/query/chart_factory.js index 8b9656a..d55a8fd 100644 --- a/query/chart_factory.js +++ b/query/chart_factory.js @@ -251,7 +251,7 @@ function gras_chart_factory_init(registry) $.getJSON('/blocks.json', function(data) { var container = $('#chart_designer_blocks'); - $.each(data.blocks, function(index, id) + $.each(data.blocks, function(id, attrs) { registry.block_ids.push(id); var cb_id = "chart_designer_blocks " + id; diff --git a/query/chart_overhead_compare.js b/query/chart_overhead_compare.js index 0ec9070..290b15d 100644 --- a/query/chart_overhead_compare.js +++ b/query/chart_overhead_compare.js @@ -23,8 +23,11 @@ GrasChartOverheadCompare.prototype.update = function(point) data_set.push(['Task', 'Percent']); $.each(this.ids, function(index, id) { - var percents = gras_extract_percent_times(point, id); - data_set.push([id, percents['total']]); + if (id in point.blocks) //skip this ID if it didnt show up in the data + { + var percents = gras_extract_percent_times(point, id); + data_set.push([id, percents['total']]); + } }); var data = google.visualization.arrayToDataTable(data_set) diff --git a/query/main.html b/query/main.html index 3fc3508..78f9227 100644 --- a/query/main.html +++ b/query/main.html @@ -20,7 +20,7 @@ <script type="text/javascript" src="/main.js"></script> <script type="text/javascript"> google.load('visualization', '1.0', {'packages':['corechart']}); - google.setOnLoadCallback(gras_stats_main); + google.setOnLoadCallback(gras_query_main); </script> </head> diff --git a/query/main.js b/query/main.js index b17af63..116653e 100644 --- a/query/main.js +++ b/query/main.js @@ -61,7 +61,7 @@ var gras_query_stats = function(registry) /*********************************************************************** * Init **********************************************************************/ -var gras_stats_main = function() +var gras_query_main = function() { //create a new registry - storage for gui state var registry = new GrasStatsRegistry(); diff --git a/tests/query_test.py b/tests/query_test.py index 1038712..5c37bad 100644 --- a/tests/query_test.py +++ b/tests/query_test.py @@ -46,11 +46,16 @@ class QueryTest(unittest.TestCase): blocks_json = self.tb.query("<args><path>/blocks.json</path></args>") print blocks_json - json.loads(blocks_json) + blocks_python = json.loads(blocks_json) + print blocks_python + self.assertEqual(len(blocks_python['blocks']), 2) stats_json = self.tb.query("<args><path>/stats.json</path></args>") print stats_json - json.loads(stats_json) + stats_python = json.loads(stats_json) + print stats_python + self.assertTrue('tps' in stats_python) + self.assertTrue('now' in stats_python) def test_props(self): vec_source = VectorSource(numpy.uint32, [0, 9, 8, 7, 6]) @@ -59,9 +64,11 @@ class QueryTest(unittest.TestCase): self.tb.connect(vec_source, block, vec_sink) self.tb.run() - props_json = self.tb.query("<args><path>/props.json</path></args>") - print props_json - json.loads(props_json) + blocks_json = self.tb.query("<args><path>/blocks.json</path></args>") + print blocks_json + blocks_python = json.loads(blocks_json) + print blocks_python + self.assertEqual(len(blocks_python['blocks']), 3) if __name__ == '__main__': unittest.main() |