~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Jonathan Lange
  • Date: 2009-05-05 22:11:41 UTC
  • mto: This revision was merged to the branch mainline in revision 4349.
  • Revision ID: jml@canonical.com-20090505221141-dzboirew1a9dcqbc
Use as a dict.

Show diffs side-by-side

added added

removed removed

Lines of Context:
509
509
        """
510
510
        medium_repr = repr(medium)
511
511
        # Add this medium to the WeakKeyDictionary
512
 
        self.counts[medium] = [0, 0, medium_repr]
 
512
        self.counts[medium] = dict(count=0, vfs_count=0,
 
513
                                   medium_repr=medium_repr)
513
514
        # Weakref callbacks are fired in reverse order of their association
514
515
        # with the referenced object.  So we add a weakref *after* adding to
515
516
        # the WeakKeyDict so that we can report the value from it before the
519
520
    def increment_call_count(self, params):
520
521
        # Increment the count in the WeakKeyDictionary
521
522
        value = self.counts[params.medium]
522
 
        value[0] += 1
 
523
        value['count'] += 1
523
524
        request_method = request.request_handlers.get(params.method)
524
525
        if issubclass(request_method, vfs.VfsRequest):
525
 
            value[1] += 1
 
526
            value['vfs_count'] += 1
526
527
 
527
528
    def done(self, ref):
528
529
        value = self.counts[ref]
529
 
        count, vfs_count, medium_repr = value
 
530
        count, vfs_count, medium_repr = (
 
531
            value['count'], value['vfs_count'], value['medium_repr'])
530
532
        # In case this callback is invoked for the same ref twice (by the
531
533
        # weakref callback and by the atexit function), set the call count back
532
534
        # to 0 so this item won't be reported twice.
533
 
        value[0] = 0
 
535
        value['count'] = 0
 
536
        value['vfs_count'] = 0
534
537
        if count != 0:
535
538
            trace.note('HPSS calls: %d (%d vfs) %s',
536
539
                       count, vfs_count, medium_repr)