~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

Merge cleanup into first-try

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import sys
29
29
import urllib
30
30
 
 
31
import bzrlib
31
32
from bzrlib.lazy_import import lazy_import
32
33
lazy_import(globals(), """
33
 
import atexit
34
34
import socket
35
35
import thread
36
36
import weakref
494
494
class _DebugCounter(object):
495
495
    """An object that counts the HPSS calls made to each client medium.
496
496
 
497
 
    When a medium is garbage-collected, or failing that when atexit functions
498
 
    are run, the total number of calls made on that medium are reported via
499
 
    trace.note.
 
497
    When a medium is garbage-collected, or failing that when
 
498
    bzrlib.global_state exits, the total number of calls made on that medium
 
499
    are reported via trace.note.
500
500
    """
501
501
 
502
502
    def __init__(self):
503
503
        self.counts = weakref.WeakKeyDictionary()
504
504
        client._SmartClient.hooks.install_named_hook(
505
505
            'call', self.increment_call_count, 'hpss call counter')
506
 
        atexit.register(self.flush_all)
 
506
        bzrlib.global_state.cleanups.add_cleanup(self.flush_all)
507
507
 
508
508
    def track(self, medium):
509
509
        """Start tracking calls made to a medium.