MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / run_with_profile

Function run_with_profile

test/perf/orm2010.py:123–167  ·  view source on GitHub ↗
(runsnake=False, dump=False)

Source from the content-addressed store, hash-verified

121
122
123def run_with_profile(runsnake=False, dump=False):
124 import cProfile
125 import pstats
126
127 filename = "orm2010.profile"
128
129 if os.path.exists("orm2010.profile"):
130 os.remove("orm2010.profile")
131
132 def status(msg):
133 print(msg)
134
135 cProfile.runctx(
136 # "runit_persist(status)",
137 "runit_persist(status); runit_query_runs(status)",
138 globals(),
139 locals(),
140 filename,
141 )
142 stats = pstats.Stats(filename)
143
144 counts_by_methname = {key[2]: stats.stats[key][0] for key in stats.stats}
145
146 print("SQLA Version: %s" % __version__)
147 print("Total calls %d" % stats.total_calls)
148 print("Total cpu seconds: %.2f" % stats.total_tt)
149 print(
150 "Total execute calls: %d"
151 % counts_by_methname["<method 'execute' of 'sqlite3.Cursor' objects>"]
152 )
153 print(
154 "Total executemany calls: %d"
155 % counts_by_methname.get(
156 "<method 'executemany' of 'sqlite3.Cursor' objects>", 0
157 )
158 )
159
160 if dump:
161 # stats.sort_stats("nfl")
162 stats.sort_stats("cumtime", "calls")
163 stats.print_stats()
164 # stats.print_callers()
165
166 if runsnake:
167 os.system("runsnake %s" % filename)
168
169
170def run_with_time(factor):

Callers 1

orm2010.pyFile · 0.85

Calls 4

localsFunction · 0.85
existsMethod · 0.45
removeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected