From b4113f123098408797f04ba08aa58e7e0c4cbb3a Mon Sep 17 00:00:00 2001 From: Thomas Frimann Koren Date: Mon, 16 Dec 2024 09:38:40 +0100 Subject: [PATCH] Support for us floating point timestamps generated by Incisive (#22) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Support for us floating point timestamps generated by Incisive Incisive running on a Cortex M0+ generates tarmac files in this format: ```tarmac 1166.141000us E HRESETn 1 1166.177000us MR4_D 00000000 00204800 1166.177000us R MSP 00204800 1166.187000us MR4_D 00000004 0000010b 1166.196000us R PSR f1000000 1166.196000us E ATOMIC 0 1166.205000us MR2_I 0000010a b5100000 1166.214000us MR4_I 0000010c ffdaf7ff 1166.214000us IT 0000010a b510 PUSH {r4,lr} 1166.223000us MW4_D 002047f8 ffffffff 1166.232000us MW4_D 002047fc ffffffff 1166.232000us R MSP 002047f8 1166.250000us IT 0000010c f7ffffda BL {pc} - 0x48 ; 0xc4 ``` Add support for us as a timestamp, and conversion of float-literals to an integer. * Updated parsertest with float µs-timestamp from Cadence Incisive. --- lib/parser.cpp | 30 ++++++++++++++++++++++++--- tests/parsertest-implicit-thumb.ref | 32 +++++++++++++++++++++++++++++ tests/parsertest-implicit-thumb.txt | 23 +++++++++++++++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/lib/parser.cpp b/lib/parser.cpp index b562aa0..ce28dcd 100644 --- a/lib/parser.cpp +++ b/lib/parser.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,7 @@ static bool contains_only(const std::string &str, const char *permitted_chars) struct Token { static constexpr const char *decimal_digits = "0123456789"; + static constexpr const char *float_chars = "0123456789."; static constexpr const char *hex_digits = "0123456789ABCDEFabcdef"; static constexpr const char *regvalue_chars = "0123456789ABCDEFabcdef_-"; @@ -99,6 +101,14 @@ struct Token { assert(isdecimal()); return stoull(s, NULL, 10); } + inline bool isfloat() const { return isword(float_chars); } + inline uint64_t decimalvaluefromfloat() const + { + assert(isfloat()); + // Timestamp encountered as xxx.yyyyyyyyus - just multiply by 1e6 + // to make them an integer. + return static_cast(round(stold(s, NULL) * 1000000.f)); + } inline bool ishex() const { return isword(hex_digits); } inline bool isregvalue() const { return isword(regvalue_chars); } inline bool ishexwithoptionalnamespace() const @@ -362,6 +372,14 @@ class TarmacLineParserImpl { highlight(tok, HL_TIMESTAMP); tok = lex(); + if (tok.isword() && (known_timestamp_units.find(tok.s) != + known_timestamp_units.end())) + tok = lex(); + } else if (tok.isfloat()) { + time = tok.decimalvaluefromfloat(); + highlight(tok, HL_TIMESTAMP); + tok = lex(); + if (tok.isword() && (known_timestamp_units.find(tok.s) != known_timestamp_units.end())) tok = lex(); @@ -371,12 +389,18 @@ class TarmacLineParserImpl { // intervening space. if (tok.isword()) { size_t end_of_digits = - tok.s.find_first_not_of(Token::decimal_digits); + tok.s.find_first_not_of(Token::float_chars); if (end_of_digits > 0 && end_of_digits != string::npos && (known_timestamp_units.find(tok.s.substr( end_of_digits)) != known_timestamp_units.end())) { auto pair = tok.split(end_of_digits); - time = pair.first.decimalvalue(); + if (pair.first.isdecimal()) { + time = pair.first.decimalvalue(); + } + else { + // Float + time = pair.first.decimalvaluefromfloat(); + } highlight(pair.first, HL_TIMESTAMP); tok = lex(); } @@ -1296,5 +1320,5 @@ TarmacLineParser::~TarmacLineParser() { delete pImpl; } void TarmacLineParser::parse(const string &s) const { pImpl->parse(s); } set TarmacLineParserImpl::known_timestamp_units = { - "clk", "ns", "cs", "cyc", "tic", "ps", + "clk", "ns", "cs", "cyc", "tic", "ps", "us", }; diff --git a/tests/parsertest-implicit-thumb.ref b/tests/parsertest-implicit-thumb.ref index 06ee6b3..baaa87b 100644 --- a/tests/parsertest-implicit-thumb.ref +++ b/tests/parsertest-implicit-thumb.ref @@ -1,2 +1,34 @@ --- Tarmac line: 354ns IT 00000350 490d LDR r1,[pc,#52] ; [0x388] * InstructionEvent time=354 effect=executed pc=350 iset=Thumb width=16 instruction=490d disassembly="LDR r1,[pc,#52] ; [0x388]" +--- Tarmac line: 10.356000us R CONTROL 00000000 +--- Tarmac line: 10.356000us R PRIMASK 00000000 +--- Tarmac line: 10.356000us R PSR f1000003 +* RegisterEvent time=10356000 reg=psr offset=0 bytes=f1:00:00:03 +--- Tarmac line: 10.356000us E HRESETn 0 +* ExceptionEvent time=10356000 +--- Tarmac line: 10.356000us E LOCKUP 0 +* ExceptionEvent time=10356000 +--- Tarmac line: 10.356000us E HALTED 0 +* ExceptionEvent time=10356000 +--- Tarmac line: 10.356000us E INT_READY 0 +* ExceptionEvent time=10356000 +--- Tarmac line: 10.356000us E ATOMIC 1 +* ExceptionEvent time=10356000 +--- Tarmac line: 1166.141000us E HRESETn 1 +* ExceptionEvent time=1166141000 +--- Tarmac line: 1166.177000us MR4_D 00000000 00204800 +* MemoryEvent time=1166177000 read=true known=true addr=0 size=4 contents=204800 +--- Tarmac line: 1166.177000us R MSP 00204800 +* RegisterEvent time=1166177000 reg=r13 offset=0 bytes=00:20:48:00 +--- Tarmac line: 1166.187000us MR4_D 00000004 0000010b +* MemoryEvent time=1166187000 read=true known=true addr=4 size=4 contents=10b +--- Tarmac line: 1166.196000us R PSR f1000000 +* RegisterEvent time=1166196000 reg=psr offset=0 bytes=f1:00:00:00 +--- Tarmac line: 1166.196000us E ATOMIC 0 +* ExceptionEvent time=1166196000 +--- Tarmac line: 1166.205000us MR2_I 0000010a b5100000 +* MemoryEvent time=1166205000 read=true known=true addr=10a size=2 contents=b5100000 +--- Tarmac line: 1166.214000us MR4_I 0000010c ffdaf7ff +* MemoryEvent time=1166214000 read=true known=true addr=10c size=4 contents=ffdaf7ff +--- Tarmac line: 1166.214000us IT 0000010a b510 PUSH {r4,lr} +* InstructionEvent time=1166214000 effect=executed pc=10a iset=Thumb width=16 instruction=b510 disassembly="PUSH {r4,lr}" diff --git a/tests/parsertest-implicit-thumb.txt b/tests/parsertest-implicit-thumb.txt index 650662b..29cf0b7 100644 --- a/tests/parsertest-implicit-thumb.txt +++ b/tests/parsertest-implicit-thumb.txt @@ -11,3 +11,26 @@ 354ns IT 00000350 490d LDR r1,[pc,#52] ; [0x388] +# ---------------------------------------------------------------------- +# Trace lines as output by Cadence Incisive for a Cortex M0+ +# This trace format uses us-level timestamps as floating point numbers. +# CORTEXM0PLUS TARMAC 00000001 +# hw_top.u_tarmac + 10.356000us R CONTROL 00000000 + 10.356000us R PRIMASK 00000000 + 10.356000us R PSR f1000003 + 10.356000us E HRESETn 0 + 10.356000us E LOCKUP 0 + 10.356000us E HALTED 0 + 10.356000us E INT_READY 0 + 10.356000us E ATOMIC 1 + 1166.141000us E HRESETn 1 + 1166.177000us MR4_D 00000000 00204800 + 1166.177000us R MSP 00204800 + 1166.187000us MR4_D 00000004 0000010b + 1166.196000us R PSR f1000000 + 1166.196000us E ATOMIC 0 + 1166.205000us MR2_I 0000010a b5100000 + 1166.214000us MR4_I 0000010c ffdaf7ff + 1166.214000us IT 0000010a b510 PUSH {r4,lr} +