522 This method is deprecated in favor of using _cw.call_service('repo_stats') |
522 This method is deprecated in favor of using _cw.call_service('repo_stats') |
523 """ |
523 """ |
524 with self.internal_session() as session: |
524 with self.internal_session() as session: |
525 return session.call_service('repo_stats') |
525 return session.call_service('repo_stats') |
526 |
526 |
|
527 @deprecated("[4.0] use _cw.call_service('repo_gc_stats'") |
527 def gc_stats(self, nmax=20): |
528 def gc_stats(self, nmax=20): |
528 """Return a dictionary containing some statistics about the repository |
529 """Return a dictionary containing some statistics about the repository |
529 memory usage. |
530 memory usage. |
530 |
531 |
531 This is a public method, not requiring a session id. |
532 This is a public method, not requiring a session id. |
532 |
533 |
533 nmax is the max number of (most) referenced object returned as |
534 nmax is the max number of (most) referenced object returned as |
534 the 'referenced' result |
535 the 'referenced' result |
535 """ |
536 """ |
536 |
537 with self.internal_session() as session: |
537 from cubicweb._gcdebug import gc_info |
538 return session.call_service('repo_gc_stats', nmax=nmax) |
538 from cubicweb.appobject import AppObject |
|
539 from cubicweb.rset import ResultSet |
|
540 from cubicweb.dbapi import Connection, Cursor |
|
541 from cubicweb.web.request import CubicWebRequestBase |
|
542 from rql.stmts import Union |
|
543 |
|
544 lookupclasses = (AppObject, |
|
545 Union, ResultSet, |
|
546 Connection, Cursor, |
|
547 CubicWebRequestBase) |
|
548 try: |
|
549 from cubicweb.server.session import Session, InternalSession |
|
550 lookupclasses += (InternalSession, Session) |
|
551 except ImportError: |
|
552 pass # no server part installed |
|
553 |
|
554 results = {} |
|
555 counters, ocounters, garbage = gc_info(lookupclasses, |
|
556 viewreferrersclasses=()) |
|
557 values = sorted(counters.iteritems(), key=lambda x: x[1], reverse=True) |
|
558 results['lookupclasses'] = values |
|
559 values = sorted(ocounters.iteritems(), key=lambda x: x[1], reverse=True)[:nmax] |
|
560 results['referenced'] = values |
|
561 results['unreachable'] = len(garbage) |
|
562 return results |
|
563 |
539 |
564 def get_schema(self): |
540 def get_schema(self): |
565 """Return the instance schema. |
541 """Return the instance schema. |
566 |
542 |
567 This is a public method, not requiring a session id. |
543 This is a public method, not requiring a session id. |