changeset 1424:458355ee1b99

arduinonode: per-device-type timing stats Ignore-this: de560ed6044cef5dacbf5d9b6334df99 darcs-hash:c0164f22d20b5673d1f42ffa4462ef4ed87b608d
author drewp <drewp@bigasterisk.com>
date Wed, 07 Aug 2019 20:55:00 -0700
parents ba56263fe3b2
children 75aaa0547d55
files service/arduinoNode/arduinoNode.py service/arduinoNode/devices.py service/arduinoNode/tasks.py
diffstat 3 files changed, 34 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/service/arduinoNode/arduinoNode.py	Wed Aug 07 20:23:04 2019 -0700
+++ b/service/arduinoNode/arduinoNode.py	Wed Aug 07 20:55:00 2019 -0700
@@ -178,23 +178,24 @@
         t1 = time.time()
         self.ser.write("\x60\x00") # "poll everything"
         for i in self._polledDevs:
-            try:
-                now = time.time()
-                new = i.readFromPoll(self.ser.read)
-                if isinstance(new, dict): # new style
-                    oneshot = new['oneshot']
-                    new = new['latest']
-                else:
-                    oneshot = None
+            with i._stats.poll.time():
+                try:
+                    now = time.time()
+                    new = i.readFromPoll(self.ser.read)
+                    if isinstance(new, dict): # new style
+                        oneshot = new['oneshot']
+                        new = new['latest']
+                    else:
+                        oneshot = None
 
-                self._updateMasterWithNewPollStatements(i.uri, new)
+                    self._updateMasterWithNewPollStatements(i.uri, new)
 
-                if oneshot:
-                    self._sendOneshot(oneshot)
-                self._lastPollTime[i.uri] = now
-            except:
-                log.warn('while polling %r:', i.uri)
-                raise
+                    if oneshot:
+                        self._sendOneshot(oneshot)
+                    self._lastPollTime[i.uri] = now
+                except:
+                    log.warn('while polling %r:', i.uri)
+                    raise
         #plus statements about succeeding or erroring on the last poll
         byte = self.ser.read(1)
         if byte != 'x':
@@ -249,12 +250,13 @@
                         unused.discard(stmt)
             if stmtsForDev:
                 log.info("output goes to action handler for %s" % dev.uri)
-                self.ser.write("\x60" + chr(self._devCommandNum[dev.uri]))
-                dev.sendOutput(stmtsForDev, self.ser.write, self.ser.read)
-                if self.ser.read(1) != 'k':
-                    raise ValueError(
-                        "%s sendOutput/generateActionCode didn't use "
-                        "matching output bytes" % dev.__class__)
+                with dev._stats.output.time():
+                    self.ser.write("\x60" + chr(self._devCommandNum[dev.uri]))
+                    dev.sendOutput(stmtsForDev, self.ser.write, self.ser.read)
+                    if self.ser.read(1) != 'k':
+                        raise ValueError(
+                            "%s sendOutput/generateActionCode didn't use "
+                            "matching output bytes" % dev.__class__)
                 # Dev *could* change hostStatements at any time, and
                 # we're not currently tracking that, but the usual is
                 # to change them in response to sendOutput so this
--- a/service/arduinoNode/devices.py	Wed Aug 07 20:23:04 2019 -0700
+++ b/service/arduinoNode/devices.py	Wed Aug 07 20:55:00 2019 -0700
@@ -4,7 +4,8 @@
 from rdflib import Namespace, RDF, URIRef, Literal
 import time
 
-sys.path.append('../../lib')
+from greplin import scales
+
 from devices_shared import RgbPixelsAnimation
 
 ROOM = Namespace('http://projects.bigasterisk.com/room/')
@@ -41,6 +42,11 @@
 
     # subclasses may add args to this
     def __init__(self, graph, uri, pinNumber):
+        scales.init(self, self.__class__.__name__)
+        self._stats = scales.collection(self.__class__.__name__,
+                                        scales.PmfStat('poll'),
+                                        scales.PmfStat('output'),
+        )
         self.graph, self.uri = graph, uri
         self.pinNumber = pinNumber
         self.hostStateInit()
--- a/service/arduinoNode/tasks.py	Wed Aug 07 20:23:04 2019 -0700
+++ b/service/arduinoNode/tasks.py	Wed Aug 07 20:55:00 2019 -0700
@@ -32,3 +32,7 @@
 @task
 def lightsout(ctx):
     ctx.run(rf'curl http://bang:9059/output\?s\=http://projects.bigasterisk.com/room/speakersStrips\&p\=http://projects.bigasterisk.com/room/x -XPUT -v -d 199')
+
+@task
+def lightstest(ctx):
+    ctx.run(rf'curl http://bang:9059/output\?s\=http://projects.bigasterisk.com/room/speakersStrips\&p\=http://projects.bigasterisk.com/room/x -XPUT -v -d 100; sleep 3; curl http://bang:9059/output\?s\=http://projects.bigasterisk.com/room/speakersStrips\&p\=http://projects.bigasterisk.com/room/x -XPUT -v -d 199')