Mercurial > code > home > repos > homeauto
comparison service/piNode/piNode.py @ 1428:56e07d3f0930
frontdoor configs; move device class timing to greplin stats
Ignore-this: f32495ae0d3b4c6f50fe1ba46c57abcd
darcs-hash:c8b6f8460b858868837dc9c98f844528531fe98c
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Thu, 08 Aug 2019 16:50:14 -0700 |
parents | 6bd36e5e109f |
children | c3f0a98fa65d |
comparison
equal
deleted
inserted
replaced
1427:6bd36e5e109f | 1428:56e07d3f0930 |
---|---|
41 CTX = ROOM['pi/%s' % hostname] | 41 CTX = ROOM['pi/%s' % hostname] |
42 | 42 |
43 STATS = scales.collection('/root', | 43 STATS = scales.collection('/root', |
44 scales.PmfStat('configReread'), | 44 scales.PmfStat('configReread'), |
45 scales.IntStat('pollException'), | 45 scales.IntStat('pollException'), |
46 scales.PmfStat('pollAll'), | |
46 scales.PmfStat('boardPoll'), | 47 scales.PmfStat('boardPoll'), |
47 scales.PmfStat('sendOneshot'), | 48 scales.PmfStat('sendOneshot'), |
48 scales.PmfStat('outputStatements'), | 49 scales.PmfStat('outputStatements'), |
49 | 50 |
50 ) | 51 ) |
151 STATS.pollException += 1 | 152 STATS.pollException += 1 |
152 log.exception("During poll:") | 153 log.exception("During poll:") |
153 | 154 |
154 | 155 |
155 @inlineCallbacks | 156 @inlineCallbacks |
156 def _pollOneDev(self, i, pollTime): | 157 def _pollOneDev(self, i): |
157 now = time.time() | 158 now = time.time() |
158 if (hasattr(i, 'pollPeriod') and | 159 if (hasattr(i, 'pollPeriod') and |
159 self._lastPollTime.get(i.uri, 0) + i.pollPeriod > now): | 160 self._lastPollTime.get(i.uri, 0) + i.pollPeriod > now): |
160 return | 161 return |
161 #need something like: | 162 with i.stats.poll.time(): |
162 # with i.pollTiming.time(): | 163 new = yield maybeDeferred(i.poll) |
163 new = yield maybeDeferred(i.poll) | 164 |
164 pollTime[i.uri] = time.time() - now | |
165 if isinstance(new, dict): # new style | 165 if isinstance(new, dict): # new style |
166 oneshot = new['oneshot'] | 166 oneshot = new['oneshot'] |
167 new = new['latest'] | 167 new = new['latest'] |
168 else: | 168 else: |
169 oneshot = None | 169 oneshot = None |
174 self._sendOneshot(oneshot) | 174 self._sendOneshot(oneshot) |
175 self._lastPollTime[i.uri] = now | 175 self._lastPollTime[i.uri] = now |
176 | 176 |
177 @inlineCallbacks | 177 @inlineCallbacks |
178 def _pollMaybeError(self): | 178 def _pollMaybeError(self): |
179 pollTime = {} # uri: sec | 179 with STATS.pollAll.time(): |
180 start = time.time() | 180 yield gatherResults([self._pollOneDev(i) |
181 yield gatherResults([self._pollOneDev(i, pollTime) | 181 for i in self._devs], consumeErrors=True) |
182 for i in self._devs], consumeErrors=True) | 182 |
183 | |
184 if log.isEnabledFor(logging.DEBUG): | |
185 log.debug('poll times:') | |
186 for u, s in sorted(pollTime.items()): | |
187 log.debug(" %.4f ms %s", s * 1000, u) | |
188 log.debug('total poll time: %f ms done in %f ms elapsed', | |
189 sum(pollTime.values()) * 1000, | |
190 (time.time() - start) * 1000) | |
191 | |
192 pollResults = map(set, self._statementsFromInputs.values()) | 183 pollResults = map(set, self._statementsFromInputs.values()) |
193 if pollResults: | 184 if pollResults: |
194 self._influx.exportToInflux(set.union(*pollResults)) | 185 self._influx.exportToInflux(set.union(*pollResults)) |
195 | 186 |
196 def _updateMasterWithNewPollStatements(self, dev, new): | 187 def _updateMasterWithNewPollStatements(self, dev, new): |
234 if stmt[:2] == pat[:2]: | 225 if stmt[:2] == pat[:2]: |
235 stmtsForDev.append(stmt) | 226 stmtsForDev.append(stmt) |
236 unused.discard(stmt) | 227 unused.discard(stmt) |
237 if stmtsForDev: | 228 if stmtsForDev: |
238 log.info("output goes to action handler for %s" % dev.uri) | 229 log.info("output goes to action handler for %s" % dev.uri) |
239 dev.sendOutput(stmtsForDev) | 230 with dev.stats.output.time(): |
231 dev.sendOutput(stmtsForDev) | |
240 | 232 |
241 # Dev *could* change hostStatements at any time, and | 233 # Dev *could* change hostStatements at any time, and |
242 # we're not currently tracking that, but the usual is | 234 # we're not currently tracking that, but the usual is |
243 # to change them in response to sendOutput so this | 235 # to change them in response to sendOutput so this |
244 # should be good enough. The right answer is to give | 236 # should be good enough. The right answer is to give |