27 m_prev( wxLog::GetActiveTarget() )
44static bool extractMs(
const wxString& aMsg,
double& aMs )
46 int tookPos = aMsg.Find( wxT(
" took " ) );
48 if( tookPos == wxNOT_FOUND )
51 wxString tail = aMsg.Mid( tookPos + 6 );
53 if( !tail.EndsWith( wxT(
" ms" ) ) )
56 wxString number = tail.Left( tail.length() - 3 );
58 return number.ToCDouble( &aMs );
67 int provPos = aMsg.Find( wxT(
"DRC provider '" ) );
69 if( provPos != wxNOT_FOUND )
71 wxString rest = aMsg.Mid( provPos + 14 );
72 int quote = rest.Find(
'\'' );
74 if( quote == wxNOT_FOUND )
77 wxString
name = rest.Left( quote );
88 int totalPos = aMsg.Find( wxT(
"DRC took " ) );
90 if( totalPos != wxNOT_FOUND )
92 wxString tail = aMsg.Mid( totalPos + 9 );
94 if( !tail.EndsWith( wxT(
" ms" ) ) )
97 wxString number = tail.Left( tail.length() - 3 );
100 if( !number.ToCDouble( &ms ) )
117 m_prev->LogTextAtLevel( aLevel, aMsg );
125 const wxString lines[] = {
126 wxT(
"DRC provider 'courtyard_overlap' took 12.345 ms" ),
127 wxT(
"DRC provider 'matched length' took 0.500 ms" ),
128 wxT(
"DRC took 42.000 ms" )
131 for(
const wxString& line : lines )
135 std::printf(
"selftest FAIL: unparsed line: %s\n",
static_cast<const char*
>( line.utf8_str() ) );
142 auto checkProvider = [&](
const wxString& aName,
double aExpected )
146 if( it == parser.
ProviderMs().end() || std::fabs( it->second - aExpected ) > 1e-9 )
148 std::printf(
"selftest FAIL: provider '%s' expected %.3f got %.3f\n",
149 static_cast<const char*
>( aName.utf8_str() ), aExpected,
150 it == parser.
ProviderMs().end() ? -1.0 : it->second );
155 checkProvider( wxT(
"courtyard_overlap" ), 12.345 );
156 checkProvider( wxT(
"matched length" ), 0.500 );
158 if( std::fabs( parser.
TotalMs() - 42.000 ) > 1e-9 )
160 std::printf(
"selftest FAIL: total expected 42.000 got %.3f\n", parser.
TotalMs() );
166 std::printf(
"selftest FAIL: expected 2 providers got %zu\n", parser.
ProviderMs().size() );
171 std::printf(
"selftest PASS\n" );
wxLog chain target that scrapes the engine's "KICAD_DRC_PROFILE" trace channel.
const std::map< wxString, double > & ProviderMs() const
void DoLogTextAtLevel(wxLogLevel aLevel, const wxString &aMsg) override
bool ParseLine(const wxString &aMsg)
Parse a single trace message into the maps.
std::map< wxString, double > m_providerMs
int RunTraceCaptureSelftest()
Run the three fixed self-test lines through a fresh parser and confirm the parsed provider map and to...
static bool extractMs(const wxString &aMsg, double &aMs)
Pull the millisecond value out of a "... took <ms> ms" tail.