Skip to content

Commit

Permalink
Support for us floating point timestamps generated by Incisive (#22)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
thomasfrimannkoren authored Dec 16, 2024
1 parent cb314a6 commit b4113f1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
30 changes: 27 additions & 3 deletions lib/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <cassert>
#include <cstring>
#include <iostream>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -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_-";

Expand Down Expand Up @@ -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<uint64_t>(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
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down Expand Up @@ -1296,5 +1320,5 @@ TarmacLineParser::~TarmacLineParser() { delete pImpl; }
void TarmacLineParser::parse(const string &s) const { pImpl->parse(s); }

set<string> TarmacLineParserImpl::known_timestamp_units = {
"clk", "ns", "cs", "cyc", "tic", "ps",
"clk", "ns", "cs", "cyc", "tic", "ps", "us",
};
32 changes: 32 additions & 0 deletions tests/parsertest-implicit-thumb.ref
Original file line number Diff line number Diff line change
@@ -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}"
23 changes: 23 additions & 0 deletions tests/parsertest-implicit-thumb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit b4113f1

Please sign in to comment.