server/repository.py
changeset 8236 cc70da744f43
parent 8229 b7bc631816f7
parent 8224 e35d4d4f7eb3
child 8239 c6cdd060212e
equal deleted inserted replaced
8230:00435a332502 8236:cc70da744f43
   507             ):
   507             ):
   508             results['%s_cache_size' % title] =  '%s / %s' % (size, maxsize)
   508             results['%s_cache_size' % title] =  '%s / %s' % (size, maxsize)
   509             results['%s_cache_hit' % title] =  hits
   509             results['%s_cache_hit' % title] =  hits
   510             results['%s_cache_miss' % title] = misses
   510             results['%s_cache_miss' % title] = misses
   511             results['%s_cache_hit_percent' % title] = (hits * 100) / (hits + misses)
   511             results['%s_cache_hit_percent' % title] = (hits * 100) / (hits + misses)
       
   512         results['type_source_cache_size'] = len(self._type_source_cache)
       
   513         results['extid_cache_size'] = len(self._extid_cache)
   512         results['sql_no_cache'] = self.system_source.no_cache
   514         results['sql_no_cache'] = self.system_source.no_cache
   513         results['nb_open_sessions'] = len(self._sessions)
   515         results['nb_open_sessions'] = len(self._sessions)
   514         results['nb_active_threads'] = threading.activeCount()
   516         results['nb_active_threads'] = threading.activeCount()
   515         results['looping_tasks'] = ', '.join(str(t) for t in self._looping_tasks)
   517         results['looping_tasks'] = ', '.join(str(t) for t in self._looping_tasks)
   516         results['available_cnxsets'] = self._cnxsets_pool.qsize()
   518         results['available_cnxsets'] = self._cnxsets_pool.qsize()
   517         results['threads'] = ', '.join(sorted(str(t) for t in threading.enumerate()))
   519         results['threads'] = ', '.join(sorted(str(t) for t in threading.enumerate()))
       
   520         return results
       
   521 
       
   522     def gc_stats(self, nmax=20):
       
   523         """Return a dictionary containing some statistics about the repository
       
   524         memory usage.
       
   525 
       
   526         This is a public method, not requiring a session id.
       
   527 
       
   528         nmax is the max number of (most) referenced object returned as
       
   529         the 'referenced' result
       
   530         """
       
   531 
       
   532         from cubicweb._gcdebug import gc_info
       
   533         from cubicweb.appobject import AppObject
       
   534         from cubicweb.rset import ResultSet
       
   535         from cubicweb.dbapi import Connection, Cursor
       
   536         from cubicweb.web.request import CubicWebRequestBase
       
   537         from rql.stmts import Union
       
   538 
       
   539         lookupclasses = (AppObject,
       
   540                          Union, ResultSet,
       
   541                          Connection, Cursor,
       
   542                          CubicWebRequestBase)
       
   543         try:
       
   544             from cubicweb.server.session import Session, InternalSession
       
   545             lookupclasses += (InternalSession, Session)
       
   546         except ImportError:
       
   547             pass # no server part installed
       
   548 
       
   549         results = {}
       
   550         counters, ocounters, garbage = gc_info(lookupclasses,
       
   551                                                viewreferrersclasses=())
       
   552         values = sorted(counters.iteritems(), key=lambda x: x[1], reverse=True)
       
   553         results['lookupclasses'] = values
       
   554         values = sorted(ocounters.iteritems(), key=lambda x: x[1], reverse=True)[:nmax]
       
   555         results['referenced'] = values
       
   556         results['unreachable'] = len(garbage)
   518         return results
   557         return results
   519 
   558 
   520     def get_schema(self):
   559     def get_schema(self):
   521         """Return the instance schema.
   560         """Return the instance schema.
   522 
   561