MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / profile

Function profile

test/aaa_profiling/test_memusage.py:117–202  ·  view source on GitHub ↗
(queue, func_args)

Source from the content-addressed store, hash-verified

115 return gc.get_objects()
116
117 def profile(queue, func_args):
118 # give testing.db a brand new pool and don't
119 # touch the existing pool, since closing a socket
120 # in the subprocess can affect the parent
121 testing.db.pool = testing.db.pool.recreate()
122
123 gc_collect()
124 samples = []
125 max_ = 0
126 max_grew_for = 0
127 success = False
128 until_maxtimes = 0
129 try:
130 while True:
131 if until_maxtimes >= maxtimes // 5:
132 break
133 for x in range(5):
134 try:
135 func(*func_args)
136 except Exception as err:
137 queue.put(
138 (
139 "result",
140 False,
141 "Test raised an exception: %r" % err,
142 )
143 )
144
145 raise
146
147 gc_collect()
148
149 samples.append(
150 get_num_objects()
151 if get_num_objects is not None
152 else len(get_objects_skipping_sqlite_issue())
153 )
154
155 if assert_no_sessions:
156 assert len(_sessions) == 0, "%d sessions remain" % (
157 len(_sessions),
158 )
159
160 # queue.put(('samples', samples))
161
162 latest_max = max(samples[-5:])
163 if latest_max > max_:
164 queue.put(
165 (
166 "status",
167 "Max grew from %s to %s, max has "
168 "grown for %s samples"
169 % (max_, latest_max, max_grew_for),
170 )
171 )
172 max_ = latest_max
173 max_grew_for += 1
174 until_maxtimes += 1

Callers 1

run_plainFunction · 0.85

Calls 5

maxClass · 0.85
recreateMethod · 0.45
putMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected