Permalink
Browse files

change port to 8008, improve efficiency by only transferring new samp…

…les. introduced a render bug, though...
  • Loading branch information...
1 parent ba99589 commit 8f77bae32e273d5cbcf8b94d71db3c305f571d79 @eastein committed Sep 17, 2012
Showing with 35 additions and 12 deletions.
  1. +23 −6 interface.html
  2. +12 −6 web.py
View
@@ -17,6 +17,19 @@
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript">
+function Boxed(type) {
+ this.type = type;
+ this.val = 0;
+}
+
+Boxed.prototype.get = function() {
+ return this.val;
+}
+
+Boxed.prototype.set = function(v) {
+ this.val = v;
+}
+
function init() {
$.ajax({
url: '/trace',
@@ -36,26 +49,30 @@
function setup_traces(tl, tracetype, tracename, id) {
var dataset = new TimeSeries();
-
+ var ts = new Boxed();
+
var rgb = ['rgba(255, 0, 0, 1)', 'rgba(0, 255, 0, 1)', 'rgba(0, 0, 255, 1)', 'rgba(220, 0, 220, 1)', 'rgba(2, 183, 98, 1)']
// Every second, get the total trace
setInterval(function() {
- update_dataset(dataset, tracetype, tracename);
+ update_dataset(dataset, ts, tracetype, tracename);
}, 1000);
tl.addTimeSeries(dataset, {strokeStyle: rgb[id], fillStyle: 'rgba(10, 10, 10, 0.1)', lineWidth: 2});
tl.streamTo(document.getElementById(tracetype), 1000);
}
-function update_dataset(dataset, tt, tn) {
+function update_dataset(dataset, ts, tt, tn) {
$.ajax({
- url: '/trace/' + tt + '/' + tn,
+ url: '/trace/' + tt + '/' + tn + '/' + ts.get(),
dataType: 'json',
success: function(data) {
- dataset.data = data['data'];
- dataset.resetBounds()
+ for (var i in data['data']) {
+ v = data['data'][i];
+ dataset.append(v[0], v[1]);
+ ts.set(v[0]);
+ }
}
});
}
View
18 web.py
@@ -44,11 +44,12 @@ def __init__(self, sock, sample_cap=3600) :
def stop(self) :
self.ok = False
- def get_trace(self, a, b) :
+ def get_trace(self, a, b, gt) :
r = []
for samp in self.samples :
ts, sample = samp
- r.append((ts, sample[a][b]))
+ if ts > gt :
+ r.append((ts, sample[a][b]))
return r
def run(self) :
@@ -152,15 +153,20 @@ def process_request(self):
return dict([(k,i[k].keys()) for k in i])
class TraceHandler(JSONHandler):
- def process_request(self, tracetype, tracename):
- return self.application.__traces__.get_trace(tracetype, tracename)
+ def process_request(self, tracetype, tracename, *a):
+ try :
+ gt = long(a[0])
+ except :
+ gt = 0
+
+ return self.application.__traces__.get_trace(tracetype, tracename, gt)
if __name__ == '__main__' :
handler_set = [
(r"/$", InterfaceHandler),
(r"/([a-z0-9\.\-]+\.js)$", JSHandler),
(r"/trace$", TraceListHandler),
- (r"/trace/([a-z0-9\.\-]+)/([a-z0-9\.\-]+)$", TraceHandler)
+ (r"/trace/([a-z0-9\.\-]+)/([a-z0-9\.\-]+)/([0-9]+)$", TraceHandler)
]
sock = zmqsub.JSONZMQSub(sys.argv[1])
@@ -172,7 +178,7 @@ def process_request(self, tracetype, tracename):
application.__traces__ = traces
application.__interface__ = open('interface.html').read()
- application.listen(8000)
+ application.listen(8008)
application.__io_instance__ = tornado.ioloop.IOLoop.instance()

0 comments on commit 8f77bae

Please sign in to comment.