From 94a0e693655acaf89e1abf40f43e5c9d110587c4 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 5 Apr 2024 16:52:08 -0700 Subject: [PATCH] format fields for object format --- src/python/perfflowaspect/advice_chrome.py | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index 58ac2dc0..9869f128 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -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"} @@ -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): @@ -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 @@ -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() @@ -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()