diff web/log.py @ 104:7f3fc0980df1

- few more web tweaks. don't fsync, it's slow.
author Matt Johnston <matt@ucc.asn.au>
date Sun, 26 Aug 2012 20:08:47 +0800
parents ef59da811986
children 397ac5c079bf
line wrap: on
line diff
--- a/web/log.py	Thu Aug 02 22:11:13 2012 +0800
+++ b/web/log.py	Sun Aug 26 20:08:47 2012 +0800
@@ -55,6 +55,8 @@
     return ''.join(["%.2x" % int(x * 256) for x in hls_to_rgb(hue, li, sat)])
 
 def graph_png(start, length):
+    os.environ['MATT_PNG_BODGE_COMPRESS'] = '4'
+    os.environ['MATT_PNG_BODGE_FILTER'] = 'paeth'
     rrds = all_sensors()
 
     graph_args = []
@@ -121,7 +123,9 @@
 #            '--right-axis-label', 'Temperature'
             ]
 
+	print>>sys.stderr, ' '.join("'%s'" % s for s in args)
     rrdtool.graph(*args)
+    #return tempf
     return tempf.read()
 
 def sensor_update(sensor_id, measurements, first_real_time, time_step):
@@ -141,12 +145,12 @@
             try:
                 rrdtool.update(rrdfile, v)
             except rrdtool.error, e:
-                print>>sys.stderr, "Bad rrdtool update '%s'" % v
+                print>>sys.stderr, "Bad rrdtool update '%s': %s" % (v, str(e))
                 traceback.print_exc(file=sys.stderr)
 
         # be paranoid
-        f = file(rrdfile)
-        os.fsync(f.fileno())
+        #f = file(rrdfile)
+        #os.fsync(f.fileno())
 
 def debug_file(mode='r'):
     return open('%s/debug.log' % config.DATA_PATH, mode)
@@ -178,6 +182,8 @@
     return val_ticks + float(val_rem) * tick_secs / tick_wake
 
 def parse(lines):
+
+    start_time = time.time()
    
     debugf = record_debug(lines)
 
@@ -229,5 +235,6 @@
         # XXX sqlite add
         sensor_update(sensor_id, measurements, first_real_time, time_step)
 
-    debugf.write("Updated %d sensors\n" % len(sensors))
+    timedelta = time.time() - start_time
+    debugf.write("Updated %d sensors in %.2f secs\n" % (len(sensors), timedelta))
     debugf.flush()