15 cm( inst, this,
"SimpleDiagnostics" ),
17 frame_enabled( (unsigned)-1 )
25 []( std::ostream &
out )
28 out << R
"STRING([SimpleLogger]
32 #system my_system Performance
33 #instance my_instance Performance
35 #client Slot:* Performance
38 client * Warning (Critical) (SrcInfo)
39 system * Warning (Critical) (SrcInfo)
40 )STRING" << std::endl;
48 this->print_welcome();
53 for(
auto & [ type, system ] : this->
instance()->getSystemContainer()->debug_GetSystems() )
55 this->print_system( system );
58 SimpleLogger::Flags SimpleDiagnostics::LineLogFlags( LogLine
const & line,
bool frame_enabled, LogId
id )
60 if( !line.frame || frame_enabled )
61 if( !line.log_id.has_value() || line.log_id.value() ==
id )
82 for( SimpleLogger_GeneralLog
const & log : this->generalLog )
84 flags = this->LogFlagsCombine( flags, this->LineLogFlags( log.line, this->frame_enabled == frame_id,
id ) );
88 for( SimpleLogger_InstanceLog
const & log : this->instanceLog )
90 if( !log.instance_name.has_value() || log.instance_name.value() == marker->instance()->instance_name() )
91 flags = this->LogFlagsCombine( flags, this->LineLogFlags( log.line, this->frame_enabled == frame_id,
id ) );
95 for( SimpleLogger_ClientLog
const & log : this->clientLog )
97 SimpleLogger::Flags client_flags = this->LineLogFlags( log.line, this->frame_enabled == frame_id,
id );
101 if( !log.client_name.has_value() )
103 flags = this->LogFlagsCombine( flags, client_flags );
108 ClientMarker
const * m = marker;
111 if( m->name() == log.client_name.value() )
112 if( !log.client_id.has_value() || log.client_id.value() == m->marker_id() )
114 flags = this->LogFlagsCombine( flags, client_flags );
117 m = m->inheritance_child();
136 for( SimpleLogger_GeneralLog
const & log : this->generalLog )
138 flags = this->LogFlagsCombine( flags, this->LineLogFlags( log.line, this->frame_enabled == frame_id,
id ) );
142 for( SimpleLogger_SystemLog
const & log : this->systemLog )
144 if( !log.system_name.has_value() || log.system_name == system->debug_name() )
145 flags = this->LogFlagsCombine( flags, this->LineLogFlags( log.line, this->frame_enabled == frame_id,
id ) );
151 void SimpleDiagnostics::AcceptLogLine(
Lex & lex, LogLine & line )
155 line.log_id = LogId( lex.AcceptName().c_str(), &this->cm );
157 lex.AcceptOperator(
"*" );
160 while( lex.IsNextOperator(
"(" ) )
162 lex.AcceptOperator(
"(" );
163 std::string flag_str = lex.AcceptName();
164 lex.AcceptOperator(
")" );
166 if( flag_str ==
"Frame" )
172 auto flag = iv::StringIO_Read< SimpleLogger::Flags >( flag_str.c_str(), &this->cm );
176 lex.LogicFail(
"Invalid flag keyword." );
183 this->reading =
true;
185 this->instanceLog.clear();
186 this->clientLog.clear();
187 this->systemLog.clear();
190 [&]( std::istream & in )
193 lex.DisableNewlineSkipping();
194 lex.DefineOperator(
"[" );
195 lex.DefineOperator(
"]" );
196 lex.DefineKeyword(
"log" );
197 lex.DefineKeyword(
"unpack" );
198 lex.DefineOperator(
"*" );
199 lex.DefineOperator(
":" );
200 lex.DefineOperator(
"(" );
201 lex.DefineOperator(
")" );
205 Lex_LogTrace _mod( lex );
207 constexpr
int Mode_None = 0;
208 constexpr
int Mode_SimpleLogger = 1;
210 int mode = Mode_None;
214 if( lex.IsNext( Lex::Token::Newline ) )
216 lex.Accept( Lex::Token::Newline );
218 else if( lex.IsNextOperator(
"[" ) )
220 lex.AcceptOperator(
"[" );
221 std::string name = lex.AcceptName();
222 lex.AcceptOperator(
"]" );
226 else if( name ==
"SimpleLogger" )
227 mode = Mode_SimpleLogger;
229 lex.LogicFail(
"Unknown section identifier." );
233 lex.Accept( Lex::Token::Newline );
235 else if( mode == Mode_SimpleLogger )
237 if( lex.IsNextOperator(
"*" ) )
239 lex.AcceptOperator(
"*" );
241 SimpleLogger_GeneralLog log;
244 this->AcceptLogLine( lex, log.line );
248 this->generalLog.push_back( log );
252 lex.Accept( Lex::Token::Newline );
256 std::string name = lex.AcceptName();
257 if( name ==
"instance" )
259 SimpleLogger_InstanceLog log;
262 if( lex.IsNextOperator(
"*" ) )
263 lex.AcceptOperator(
"*" );
265 log.instance_name = lex.AcceptName();
268 this->AcceptLogLine( lex, log.line );
272 this->instanceLog.push_back( log );
276 lex.Accept( Lex::Token::Newline );
278 else if( name ==
"client" )
280 SimpleLogger_ClientLog log;
283 if( lex.IsNextOperator(
"*" ) )
284 lex.AcceptOperator(
"*" );
286 log.client_name = lex.AcceptName();
288 if( log.client_name.has_value() && lex.IsNextOperator(
":" ) )
291 lex.AcceptOperator(
":" );
294 if( lex.IsNextKeyword(
"*" ) )
295 lex.AcceptKeyword(
"*" );
297 log.client_id = lex.AcceptInteger();
301 this->AcceptLogLine( lex, log.line );
305 this->clientLog.push_back( log );
309 lex.Accept( Lex::Token::Newline );
311 else if( name ==
"system" )
313 SimpleLogger_SystemLog log;
316 if( lex.IsNextOperator(
"*" ) )
317 lex.AcceptOperator(
"*" );
319 log.system_name = lex.AcceptName();
322 this->AcceptLogLine( lex, log.line );
326 this->systemLog.push_back( log );
330 lex.Accept( Lex::Token::Newline );
346 this->reading =
false;
358 unsigned character = iq.input_character();
360 if( this->action( character ) )
372 void SimpleDiagnostics::print_system( System * sys )
376 this->
out() << sys->debug_name() <<
":" << std::endl;
379 this->
out() << std::endl;
384 void SimpleDiagnostics::print_welcome()
386 this->
out() <<
"========= SimpleDiagnostics =========" << std::endl;
387 this->
out() <<
" p - Print all systems." << std::endl;
388 this->
out() <<
" e - Print ElementSystem." << std::endl;
389 this->
out() <<
" i - Print InstanceSystem." << std::endl;
390 this->
out() <<
" n - Print AnimSystem." << std::endl;
391 this->
out() <<
" f - Frame log." << std::endl;
392 this->
out() <<
"" << std::endl;
394 this->
out() <<
" LogId:" << std::endl;
398 this->
out() <<
" " <<
id.runtime_value() <<
" - " <<
id.persistent_value() << std::endl;
400 this->
out() <<
"" << std::endl;
403 bool SimpleDiagnostics::action(
unsigned key )
409 else if( key ==
'e' )
414 this->print_system( es );
417 else if( key ==
'i' )
419 this->print_system( this->
instance()->getSystem< InstanceSystem >() );
421 else if( key ==
'n' )
423 this->print_system( this->
instance()->getSystem< AnimSystem >() );
425 else if( key ==
'b' )
427 this->print_system( this->
instance()->getSystem< InputBindingSystem >() );
429 else if( key ==
'f' )