@@ -109,6 +109,21 @@ def skip_to_first_trace(trace_item_gen: TraceItemGenerator):
109109 return item
110110 return next (trace_item_gen )
111111
112+ def get_timestamp_from_line (line , span_end_pos ):
113+ try :
114+ timestamp = float (line [span_end_pos - 19 : span_end_pos - 7 ].strip ())
115+ # Support for CONFIG_LOG_OUTPUT_FORMAT_TIME_TIMESTAMP - For when default Zephyr timestamp format is used
116+ except ValueError :
117+ h , m , rest = line [span_end_pos - 23 : span_end_pos - 7 ].strip ().split (':' )
118+ s1 , s2 = rest .split (',' )
119+ s = s1 + s2
120+ timestamp = timedelta (
121+ hours = int (h ),
122+ minutes = int (m ),
123+ seconds = float (s )
124+ ).total_seconds ()
125+ return timestamp
126+
112127def make_trace_item (fileio : TextIO ) -> TraceItemGenerator :
113128 '''Filter and parse a line of trace in string form into TraceItem object, for example:
114129 '[ 2.566046] <inf> component: comp_copy: comp:0 0x40000 perf comp_copy samples
@@ -134,26 +149,18 @@ def make_trace_item(fileio: TextIO) -> TraceItemGenerator:
134149 # second trace from the line. This is done by regarding the end position
135150 # of the matched substring as sentinel, timestamp and trace level are
136151 # both some specific offset from the sentinel.
137- span_end_pos = match_obj .span ()[1 ]
138- trace_lvl = line [span_end_pos - 4 : span_end_pos - 1 ]
139152 try :
140- timestamp = float (line [span_end_pos - 19 : span_end_pos - 7 ].strip ())
141- # Support for CONFIG_LOG_OUTPUT_FORMAT_TIME_TIMESTAMP - For when default Zephyr timestamp format is used
142- except ValueError :
143- h , m , rest = line [span_end_pos - 23 : span_end_pos - 7 ].strip ().split (':' )
144- s1 , s2 = rest .split (',' )
145- s = s1 + s2
146- timestamp = timedelta (
147- hours = int (h ),
148- minutes = int (m ),
149- seconds = float (s )
150- ).total_seconds ()
151-
152- # The rest after removing timestamp and log level
153- rest = line [span_end_pos + 1 :].split (': ' )
154- ctx , func = rest [0 :2 ]
155- msg = ': ' .join (rest [2 :]).strip ()
156- yield TraceItem (timestamp , trace_lvl , ctx , func , msg )
153+ span_end_pos = match_obj .span ()[1 ]
154+ trace_lvl = line [span_end_pos - 4 : span_end_pos - 1 ]
155+ timestamp = get_timestamp_from_line (line , span_end_pos )
156+
157+ # The rest after removing timestamp and log level
158+ rest = line [span_end_pos + 1 :].split (': ' )
159+ ctx , func = rest [0 :2 ]
160+ msg = ': ' .join (rest [2 :]).strip ()
161+ yield TraceItem (timestamp , trace_lvl , ctx , func , msg )
162+ except Exception as e : # pylint: disable=W0718
163+ print (f"WARNING: Couldn't parse line: { line } , error: { e } " )
157164
158165def process_trace_file ():
159166 '''The top-level caller for processing the trace file'''
0 commit comments