def pubBeforeCommitHandler(ev): if getattr(STATS, 'stats', None) is None: init_stats() STATS.stats['time-before-commit'] = datetime.now() - STATS.stats['time-start'] # noqa try: ob = ev.request['PARENTS'][-1] conn = ob._p_jar STATS.stats['modified'] = len(conn._registered_objects) except: pass
def applyTransform(request, body=None): t1 = datetime.now() res = orig_applyTransform(request, body) try: if getattr(STATS, 'stats', None) is None: init_stats() STATS.stats['transchain'] = datetime.now() - t1 except: pass return res
def load_persistent(self, oid, klass): # Quick instance reference. We know all we need to know # to create the instance w/o hitting the db, so go for it! try: if getattr(STATS, 'stats', None) is None: init_stats() stats_cached = STATS.stats['zodb-cached'] stats_uncached = STATS.stats['zodb-uncached'] except: stats_cached = [] stats_uncached = [] t1 = datetime.now() obj = self._cache.get(oid, None) if obj is not None: stats_cached.append(datetime.now() - t1) return obj if isinstance(klass, tuple): klass = self._get_class(*klass) if issubclass(klass, Broken): # We got a broken class. We might need to make it # PersistentBroken if not issubclass(klass, broken.PersistentBroken): klass = broken.persistentBroken(klass) try: obj = klass.__new__(klass) except TypeError: # Couldn't create the instance. Maybe there's more # current data in the object's actual record! stats_uncached.append(datetime.now() - t1) return self._conn.get(oid) if has_new_ghost: self._cache.new_ghost(oid, obj) else: obj._p_oid = oid obj._p_jar = self._conn obj._p_changed = None self._cache[oid] = obj stats_uncached.append(datetime.now() - t1) return obj
def pubSucessHandler(ev): environ = ev.request.environ if getattr(STATS, 'stats', None) is None: init_stats() stats = STATS.stats stats['time-end'] = datetime.now() - stats['time-start'] total = 0 total_cached = 0 t_total = timedelta() t_cached = timedelta() t_uncached = timedelta() for td in stats['zodb-cached']: total += 1 total_cached += 1 t_total = t_total + td t_cached = t_cached + td for td in stats['zodb-uncached']: total += 1 t_total = t_total + td t_uncached = t_uncached + td loads = timedelta() for td in stats['zodb-loads']: loads = loads + td def printTD(td): s = td.seconds + td.microseconds / 1000000.0 return '%2.4f' % s rss1 = stats['memory'][0] / 1024 rss2 = process.memory_info()[0] / 1024 info = ( printTD(stats['time-end']), printTD(stats['time-after-traverse']), printTD(stats['time-before-commit']), printTD(stats['transchain']), printTD(loads), total, total_cached, stats['modified'], environ['REQUEST_METHOD'], environ['PATH_INFO'], printTD(t_total), printTD(t_cached), printTD(t_uncached), rss1, rss2 ) if os.getenv("COLLECTIVE_STATS_DISABLE_LOG") != "1": logger.info( '| %s %s %s %s %s %0.4d %0.4d %0.4d ' '| %s:%s | t: %s, t_c: %s, t_nc: %s ' '| RSS: %s - %s' % info ) ev.request.response.setHeader( 'x-stats', '%s %s %s %s %s %0.4d %0.4d %0.4d' % info[:8] ) del STATS.stats
def pubAfterTraverseHandler(ev): if getattr(STATS, 'stats', None) is None: init_stats() STATS.stats['time-after-traverse'] = datetime.now() - STATS.stats['time-start'] # noqa
def pubStartHandler(ev): init_stats()