import collections
import time


Op = collections.namedtuple('Op', ['name', 'args', 'kwargs', 'time'])


class TraceCollection(object):
    def __init__(self, collection):
        self.collection = collection
        self.ops = []

    def find(self, *args, **kwargs):
        start = time.time()
        retval = self.collection.find(*args, **kwargs)
        end = time.time()
        self.ops.append(Op('find', args, kwargs, end - start))
        return retval

    def find_one(self, *args, **kwargs):
        start = time.time()
        retval = self.collection.find_one(*args, **kwargs)
        end = time.time()
        self.ops.append(Op('find_one', args, kwargs, end - start))
        return retval

    def count(self, *args, **kwargs):
        start = time.time()
        retval = self.collection.count(*args, **kwargs)
        end = time.time()
        self.ops.append(Op('count', args, kwargs, end - start))
        return retval

    def save(self, *args, **kwargs):
        start = time.time()
        retval = self.collection.save(*args, **kwargs)
        end = time.time()
        self.ops.append(Op('save', args, kwargs, end - start))
        return retval

    def remove(self, *args, **kwargs):
        start = time.time()
        retval = self.collection.remove(*args, **kwargs)
        end = time.time()
        self.ops.append(Op('remove', args, kwargs, end - start))
        return retval

@@ -1,12 +1,22 @@
+import os%0A
 import colle
@@ -22,16 +22,16 @@
 ections%0A
-
 import t
@@ -108,16 +108,73 @@
 me'%5D)%0A%0A%0A
+THUNDER_DEBUG = os.environ.get('THUNDER_DEBUG') == '1'%0A%0A%0A
 class Tr
@@ -292,16 +292,437 @@
 s = %5B%5D%0A%0A
+    def add(self, op):%0A        if THUNDER_DEBUG:  # pragma nocoverage%0A            s = %5B%5D%0A            for arg, value in op.kwargs.items():%0A                s.append('%25s=%25r' %25 (arg, value))%0A            args = %5B%5D%0A            args.append(repr(op.args))%0A            args.extend(s)%0A            print '%25.6f %25-.2f msec: %25s%25s' %25 (%0A                time.time(), op.time * 1000, op.name, ', '.join(args))%0A        self.ops.append(op)%0A%0A
     def 
@@ -868,33 +868,26 @@
        self.
-ops.appen
+ad
 d(Op('find',
@@ -1101,33 +1101,26 @@
        self.
-ops.appen
+ad
 d(Op('find_o
@@ -1332,33 +1332,26 @@
        self.
-ops.appen
+ad
 d(Op('count'
@@ -1558,33 +1558,26 @@
        self.
-ops.appen
+ad
 d(Op('save',
@@ -1791,25 +1791,18 @@
    self.
-ops.appen
+ad
 d(Op('re

Add THUNDER_DEBUG enviroment variable