Created
June 30, 2015 05:55
-
-
Save hbrunn/adb140e34c7b87693ef1 to your computer and use it in GitHub Desktop.
simple script to profile name_get performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
from argparse import ArgumentParser | |
parser = ArgumentParser() | |
parser.add_argument('odoo_basedir') | |
parser.add_argument('odoo_cfg') | |
parser.add_argument('odoo_db') | |
parser.add_argument('model') | |
args = parser.parse_args() | |
import sys | |
sys.path.insert(0, args.odoo_basedir) | |
from openerp import SUPERUSER_ID, api, tools | |
from openerp.sql_db import db_connect | |
tools.config.parse_config(['-c', args.odoo_cfg]) | |
cr = db_connect(args.odoo_db).cursor() | |
uid = SUPERUSER_ID | |
with api.Environment.manage(): | |
env = api.Environment(cr, uid, {}) | |
records = env[args.model].search([]) | |
print 'name_getting {} records'.format(len(records)) | |
import cProfile, pstats, StringIO | |
pr = cProfile.Profile() | |
pr.enable() | |
records.name_get() | |
pr.disable() | |
s = StringIO.StringIO() | |
sortby = 'cumulative' | |
ps = pstats.Stats(pr, stream=s).sort_stats(sortby) | |
ps.print_stats() | |
print s.getvalue() | |
cr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment