From: Mike Bayer Date: Sun, 1 Oct 2006 23:15:53 +0000 (+0000) Subject: - added profiling to massave X-Git-Tag: rel_0_3_0~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a2194e6c0c392ea50fb8b325acb27f8a98428f9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - added profiling to massave - adjusted the formatting for per-instance loggers to limit the number of loggers that get created in memory. --- diff --git a/lib/sqlalchemy/logging.py b/lib/sqlalchemy/logging.py index bba1e0764b..bbd008dac1 100644 --- a/lib/sqlalchemy/logging.py +++ b/lib/sqlalchemy/logging.py @@ -40,8 +40,10 @@ def default_logging(): handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s')) rootlogger.addHandler(handler) -def _get_instance_name(instance): - return instance.__class__.__module__ + "." + instance.__class__.__name__ + "." + hex(id(instance)) +def _get_instance_name(instance): + # since getLogger() does not have any way of removing logger objects from memory, + # instance logging displays the instance id as a modulus of 10 to prevent endless memory growth + return instance.__class__.__module__ + "." + instance.__class__.__name__ + ".0x.." + hex(id(instance))[-2:] def instance_logger(instance): return logging.getLogger(_get_instance_name(instance)) diff --git a/test/perf/masssave.py b/test/perf/masssave.py index 0ffb345532..8e4d5e3fff 100644 --- a/test/perf/masssave.py +++ b/test/perf/masssave.py @@ -5,10 +5,11 @@ import sqlalchemy.attributes as attributes import StringIO import testbase import gc - +import sqlalchemy.orm.session +import types db = testbase.db -NUM = 25000 +NUM = 250000 class SaveTest(AssertMixin): def setUpAll(self): @@ -27,13 +28,29 @@ class SaveTest(AssertMixin): m = mapper(Item, items) - for x in range(0,100): + for x in range(0,NUM/50): sess = create_session() query = sess.query(Item) for y in range (0,50): - print "x,y", (x,y) + # print "x,y", (x,y) sess.save(Item()) sess.flush() - + #self._profile() + print "ROWS:", x * 50 + def _profile(self): + print "------------------------" + d = {} + for o in gc.get_objects(): + t = type(o) + if t is types.InstanceType: + t = o.__class__ + d.setdefault(t, 0) + d[t] += 1 + rep = [(key, value) for key, value in d.iteritems()] + def sorter(a, b): + return cmp(b[1], a[1]) + rep.sort(sorter) + for x in rep[0:30]: + print x if __name__ == "__main__": testbase.main()