Skip to content

Commit

Permalink
format fields for object format
Browse files Browse the repository at this point in the history
  • Loading branch information
slabasan committed Apr 5, 2024
1 parent 3fd3d51 commit 94a0e69
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/python/perfflowaspect/advice_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ def sync_event(cls, pointcut, *args, **kwargs):
except KeyError:
raise ValueError("Invalid pointcut: {}".format(pointcut))
event = cls.create_sync_event(*args, phase, **kwargs)
cls.__flush_log(json.dumps(event) + ",")
if ChromeTracingAdvice.array_format == True:
cls.__flush_log(json.dumps(event) + ",")
else:
cls.__flush_log(" " + json.dumps(event) + ",")

async_pointcut_phase_map = {"before": "b", "instant": "n", "after": "e"}

Expand All @@ -261,7 +264,10 @@ def async_event(cls, pointcut, *args, **kwargs):
except KeyError:
raise ValueError("Invalid pointcut: {}".format(pointcut))
event = cls.create_async_event(*args, phase, **kwargs)
cls.__flush_log(json.dumps(event) + ",")
if ChromeTracingAdvice.array_format == True:
cls.__flush_log(json.dumps(event) + ",")
else:
cls.__flush_log(" " + json.dumps(event) + ",")

@classmethod
def __create_event_from_func(cls, func):
Expand All @@ -278,9 +284,13 @@ def __flush_log(s):
formatter = logging.Formatter("%(message)s")
fh.setFormatter(formatter)
ChromeTracingAdvice.logger.addHandler(fh)
ChromeTracingAdvice.logger.debug("[")
if ChromeTracingAdvice.array_format == False:
ChromeTracingAdvice.logger.debug("\"traceEvents\": [")
if ChromeTracingAdvice.array_format == True:
ChromeTracingAdvice.logger.debug("[")
else:
ChromeTracingAdvice.logger.debug("{")
ChromeTracingAdvice.logger.debug(" \"displayTimeUnit\": \"us\",")
ChromeTracingAdvice.logger.debug(" \"otherData\": {},")
ChromeTracingAdvice.logger.debug(" \"traceEvents\": [")
ChromeTracingAdvice.logger.debug(s)

@staticmethod
Expand All @@ -295,7 +305,10 @@ def __update_log(func, event_type, event_args=None, event_ts=None, event_dur=Non
event["ts"] = event_ts
if event_dur is not None:
event["dur"] = event_dur
ChromeTracingAdvice.__flush_log(json.dumps(event) + ",")
if ChromeTracingAdvice.array_format == True:
ChromeTracingAdvice.__flush_log(json.dumps(event) + ",")
else:
ChromeTracingAdvice.__flush_log(" " + json.dumps(event) + ",")
counter = counter + 1
counter_mutex.release()

Expand All @@ -315,7 +328,10 @@ def __update_async_log(
event["ts"] = event_ts
if event_dur is not None:
event["dur"] = event_dur
ChromeTracingAdvice.__flush_log(json.dumps(event) + ",")
if ChromeTracingAdvice.array_format == True:
ChromeTracingAdvice.__flush_log(json.dumps(event) + ",")
else:
ChromeTracingAdvice.__flush_log(" " + json.dumps(event) + ",")
counter = counter + 1
counter_mutex.release()

Expand Down

0 comments on commit 94a0e69

Please sign in to comment.