def check_timing(self, call, ms, batch_size): """Warn if any query is slower than defined threshold.""" if ms > self.LOGGING_TRESHOLD: log.warning("[SQL][%dms] %s", ms, call) if ms > self.SLOW_QUERY_MS: out = "[SQL][%dms] %s" % (ms, call[:250]) log.warning(colorize(out))
def check_timing(cls, method, ms, batch_size): if method == 'get_block' and batch_size > 1: method = 'get_blocks_batch' per = int((ms - cls.PAR_HTTP_OVERHEAD) / batch_size) par = cls.PAR_STEEMD[method] over = per / par if over >= cls.PAR_THRESHOLD: out = ("[STEEM][%dms] %s[%d] -- %.1fx par (%d/%d)" % (ms, method, batch_size, over, per, par)) print(colorize(out))
def check_timing(self, call, ms, batch_size): """Warn if a request (accounting for batch size) is too slow.""" if call == 'get_block' and batch_size > 1: call = 'get_blocks_batch' per = int((ms - self.PAR_HTTP_OVERHEAD) / batch_size) par = self.PAR_STEEMD[call] over = per / par if over >= self.PAR_THRESHOLD: out = ("[STEEM][%dms] %s[%d] -- %.1fx par (%d/%d)" % (ms, call, batch_size, over, per, par)) log.warning(colorize(out))
def check_timing(cls, nsql, ms): if ms > cls.SLOW_QUERY_MS: print(colorize("[SQL-SLOW][%dms] %s" % (ms, nsql[:250])))
def test_colorize(): plain = 'teststr' colored = '\x1b[93mteststr\x1b[0m' assert colorize(plain, color='93') in [plain, colored] assert colorize(plain, color='93', force=True) == colored