Mercurial > code > home > repos > homeauto
comparison service/arduinoNode/arduinoNode.py @ 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 | 6b80a6c58907 |
comparison
equal
deleted
inserted
replaced
1423:ba56263fe3b2 | 1424:458355ee1b99 |
---|---|
176 | 176 |
177 def _pollWork(self): | 177 def _pollWork(self): |
178 t1 = time.time() | 178 t1 = time.time() |
179 self.ser.write("\x60\x00") # "poll everything" | 179 self.ser.write("\x60\x00") # "poll everything" |
180 for i in self._polledDevs: | 180 for i in self._polledDevs: |
181 try: | 181 with i._stats.poll.time(): |
182 now = time.time() | 182 try: |
183 new = i.readFromPoll(self.ser.read) | 183 now = time.time() |
184 if isinstance(new, dict): # new style | 184 new = i.readFromPoll(self.ser.read) |
185 oneshot = new['oneshot'] | 185 if isinstance(new, dict): # new style |
186 new = new['latest'] | 186 oneshot = new['oneshot'] |
187 else: | 187 new = new['latest'] |
188 oneshot = None | 188 else: |
189 | 189 oneshot = None |
190 self._updateMasterWithNewPollStatements(i.uri, new) | 190 |
191 | 191 self._updateMasterWithNewPollStatements(i.uri, new) |
192 if oneshot: | 192 |
193 self._sendOneshot(oneshot) | 193 if oneshot: |
194 self._lastPollTime[i.uri] = now | 194 self._sendOneshot(oneshot) |
195 except: | 195 self._lastPollTime[i.uri] = now |
196 log.warn('while polling %r:', i.uri) | 196 except: |
197 raise | 197 log.warn('while polling %r:', i.uri) |
198 raise | |
198 #plus statements about succeeding or erroring on the last poll | 199 #plus statements about succeeding or erroring on the last poll |
199 byte = self.ser.read(1) | 200 byte = self.ser.read(1) |
200 if byte != 'x': | 201 if byte != 'x': |
201 raise ValueError("after poll, got %x instead of 'x'" % byte) | 202 raise ValueError("after poll, got %x instead of 'x'" % byte) |
202 for i in self._devs: | 203 for i in self._devs: |
247 if stmt[:2] == pat[:2]: | 248 if stmt[:2] == pat[:2]: |
248 stmtsForDev.append(stmt) | 249 stmtsForDev.append(stmt) |
249 unused.discard(stmt) | 250 unused.discard(stmt) |
250 if stmtsForDev: | 251 if stmtsForDev: |
251 log.info("output goes to action handler for %s" % dev.uri) | 252 log.info("output goes to action handler for %s" % dev.uri) |
252 self.ser.write("\x60" + chr(self._devCommandNum[dev.uri])) | 253 with dev._stats.output.time(): |
253 dev.sendOutput(stmtsForDev, self.ser.write, self.ser.read) | 254 self.ser.write("\x60" + chr(self._devCommandNum[dev.uri])) |
254 if self.ser.read(1) != 'k': | 255 dev.sendOutput(stmtsForDev, self.ser.write, self.ser.read) |
255 raise ValueError( | 256 if self.ser.read(1) != 'k': |
256 "%s sendOutput/generateActionCode didn't use " | 257 raise ValueError( |
257 "matching output bytes" % dev.__class__) | 258 "%s sendOutput/generateActionCode didn't use " |
259 "matching output bytes" % dev.__class__) | |
258 # Dev *could* change hostStatements at any time, and | 260 # Dev *could* change hostStatements at any time, and |
259 # we're not currently tracking that, but the usual is | 261 # we're not currently tracking that, but the usual is |
260 # to change them in response to sendOutput so this | 262 # to change them in response to sendOutput so this |
261 # should be good enough. The right answer is to give | 263 # should be good enough. The right answer is to give |
262 # each dev the masterGraph for it to write to. | 264 # each dev the masterGraph for it to write to. |