MCPcopy Create free account
hub / github.com/apache/trafficserver / readAndCombine

Function readAndCombine

plugins/traffic_dump/post_process.py:226–280  ·  view source on GitHub ↗

Read raw dump files, filter out incomplete sessions, and merge them into output files. Args: replay_dir (string) Full path to dumps num_sessions_per_file (int) number of sessions in each output file indent (int) The number of spaces per line in the output replay fil

(replay_dir, num_sessions_per_file, indent, fabricate_proxy_requests, out_dir)

Source from the content-addressed store, hash-verified

224
225
226def readAndCombine(replay_dir, num_sessions_per_file, indent, fabricate_proxy_requests, out_dir):
227 """ Read raw dump files, filter out incomplete sessions, and merge
228 them into output files.
229
230 Args:
231 replay_dir (string) Full path to dumps
232 num_sessions_per_file (int) number of sessions in each output file
233 indent (int) The number of spaces per line in the output replay files.
234 fabricate_proxy_requests (bool) Whether the post-processor should
235 fabricate proxy requests if they don't exist because the proxy served
236 the response locally.
237 out_dir (string) Output directory for post-processed json files.
238 """
239 session_count = 0
240 batch_count = 0
241 transaction_count = 0
242 error_count = defaultdict(int)
243
244 base_name = os.path.basename(replay_dir)
245
246 sessions = []
247 for f in os.listdir(replay_dir):
248 replay_file = os.path.join(replay_dir, f)
249 if not os.path.isfile(replay_file):
250 continue
251
252 try:
253 parsed_json = parse_json(replay_file)
254 except ParseJSONError as e:
255 error_count[e.message] += 1
256 continue
257
258 for session in parsed_json["sessions"]:
259 try:
260 verify_session(session, fabricate_proxy_requests)
261 except VerifyError as e:
262 connection_time = session['connection-time']
263 if not connection_time:
264 connection_time = session['start-time']
265 if connection_time:
266 logging.debug("Omitting session in %s with connection-time: %d: %s", replay_file, session['connection-time'], e)
267 else:
268 logging.debug("Omitting a session in %s, could not find a connection time: %s", replay_file, e)
269 continue
270 sessions.append(session)
271 session_count += 1
272 transaction_count += len(session["transactions"])
273 if len(sessions) >= num_sessions_per_file:
274 write_sessions(sessions, f"{out_dir}/{base_name}_{batch_count}.json", indent)
275 sessions = []
276 batch_count += 1
277 if sessions:
278 write_sessions(sessions, f"{out_dir}/{base_name}_{batch_count}.json", indent)
279
280 return session_count, transaction_count, error_count
281
282
283def post_process(in_dir, subdir_q, out_dir, num_sessions_per_file, single_line, fabricate_proxy_requests, cnt_q):

Callers 1

post_processFunction · 0.85

Calls 6

parse_jsonFunction · 0.85
verify_sessionFunction · 0.85
write_sessionsFunction · 0.85
joinMethod · 0.80
debugMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected