当前位置:网站首页>SystemC uses SC_ report_ Handler processing log printing
SystemC uses SC_ report_ Handler processing log printing
2022-06-12 13:54:00 【123axj】
sc_severity Every time you need to print information , According to the type of this information (info、warning Tips ,error Report errors ,fatal Report errors ) Make a selection .sc_verbosity Only in sc_severity by SC_INFO Only in the case of , That's because usually ,warning/error/fatal There won't be too much information , and info More information , And info A lot of information is for debug The use of , So we need to be right info Information is graded .
Corresponding sc_severity Enumerated type of , Defined separately 4 Basic macros , There is another one for SC_INFO Enhanced macro for :
SC_REPORT_INFO( msg_type, msg )
SC_REPORT_WARNING( msg_type, msg )
SC_REPORT_ERROR( msg_type, msg )
SC_REPORT_FATAL( msg_type, msg )
SC_REPORT_INFO_VERB( msg_type, msg, verbosity )
Parameters const char* msg_type The general assignment is this->name(), That's Ben sc_module Instantiation name of .msg_type stay set_actions And so on , For sub module Make print settings .
Systemc Source code /src/sysc/utils/sc_report.h Is defined as follows .
enum sc_severity {
SC_INFO = 0, // informative only
SC_WARNING, // indicates potentially incorrect condition
SC_ERROR, // indicates a definite problem
SC_FATAL, // indicates a problem from which we cannot recover
SC_MAX_SEVERITY
};
enum sc_verbosity {
SC_NONE = 0,
SC_LOW = 100,
SC_MEDIUM = 200,
SC_HIGH = 300,
SC_FULL = 400,
SC_DEBUG = 500
};
enum {
SC_UNSPECIFIED = 0x0000, // look for lower-priority rule
SC_DO_NOTHING = 0x0001, // take no action (ignore if other bits set)
SC_THROW = 0x0002, // throw an exception
SC_LOG = 0x0004, // add report to report log
SC_DISPLAY = 0x0008, // display report to screen
SC_CACHE_REPORT = 0x0010, // save report to cache
SC_INTERRUPT = 0x0020, // call sc_interrupt_here(...)
SC_STOP = 0x0040, // call sc_stop()
SC_ABORT = 0x0080 // call abort()
};
static sc_actions set_actions(sc_severity,sc_actions = SC_UNSPECIFIED);
static sc_actions set_actions(const char * msg_type,sc_actions = SC_UNSPECIFIED);
static sc_actions set_actions(const char * msg_type,sc_severity,sc_actions = SC_UNSPECIFIED);
sc_report_handler.h in ,sc_report_handler_proc Is a function pointer type defined ,handler Is a function pointer ( Member variables ).
typedef void (* sc_report_handler_proc)(const sc_report&, const sc_actions &);
static sc_report_handler_proc handler;
sc_report_handler.cpp in ,default_handler It's a function , then handler By default, it points to this function ; It can also be done through set_handler Function to override handler.
void sc_report_handler::default_handler(const sc_report& rep, const sc_actions& actions)
sc_report_handler_proc sc_report_handler::handler = &sc_report_handler::default_handler;
An application example is as follows
#include <iostream>
#include <fstream>
#include "systemc.h"
using namespace std;
using namespace sc_core;
class TestPlatform
: public sc_module
{
public:
SC_HAS_PROCESS(TestPlatform);
TestPlatform(const sc_module_name& name)
: sc_module(name)
,m_period (sc_time(1000,SC_PS))
{
SC_THREAD(PrintMessage);
};
public:
void PrintMessage();
~TestPlatform()
{ ;
}
public:
sc_time m_period;
};
void TestPlatform::PrintMessage()
{
while(1)
{
wait(m_period);
SC_REPORT_INFO_VERB(name(),"this is a SC_LOW info message ",SC_LOW);
SC_REPORT_INFO_VERB(name(),"this is a SC_MEDIUM info message ",SC_MEDIUM);
SC_REPORT_INFO_VERB(name(),"this is a SC_HIGH info message ",SC_HIGH);
SC_REPORT_INFO_VERB(name(),"this is a SC_FULL info message ",SC_FULL);
SC_REPORT_INFO_VERB(name(),"this is a SC_DEBUG info message ",SC_DEBUG);
SC_REPORT_WARNING(name(),"this is a SC_WARNING message "); // SC_WARNING
SC_REPORT_WARNING(name(),"this is a SC_ERROR message ");
SC_REPORT_WARNING(name(),"this is a SC_FATAL message ");
cout<<"SC_INFO counter " << sc_report_handler::get_count(SC_INFO)<< endl; // Get is SC_INFO Number of lines printed (SC_LOW + SC_MEDIUM + ....)
cout<<"SC_WARNING counter " << sc_report_handler::get_count(SC_WARNING)<< endl; // Get is SC_WARNINNG Number of lines printed (SC_WARNING * 3 )a
sc_report_handler::stop_after(SC_INFO, 500);// When SC_INFO The number of lines printed has reached 500 That's ok when Just call st_stop()
}
}
int sc_main(int argc, char** argv)
{
TestPlatform * m_platform;
m_platform = new TestPlatform("TestPlatform");
const char* filename = "./log_file" ;
sc_report_handler::set_log_file_name(filename);
sc_report_handler::set_actions(SC_INFO, SC_DISPLAY | SC_LOG);
sc_report_handler::suppress(SC_LOG); // Inhibition SC_LOG, That is, do not print to log file
// sc_report_handler::suppress(); // Without any parameters , Used to clear previous suppress
sc_report_handler::force(SC_LOG); // Force open SC_LOG, That is, before this line of code about SC_LOG Of suppress All fail
// sc_report_handler::suppress(SC_DISPLAY);
sc_report_handler::set_verbosity_level(sc_core::SC_MEDIUM); // Set global verbosity level, Only aim at SC_INFO
sc_start(500,SC_NS);
return 0;
}
边栏推荐
猜你喜欢

Record some settings for visual studio 2019
FFmpeg 学习指南

Démontage et modification de la machine publicitaire - décompression amateur

Implementing singleton mode of database under QT multithreading

Implementation of Ackermann function with simulated recursion

基于Profibus-DP协议的PLC智能从站设计

xcode 调试openGLES

Talk about the top 10 classic MySQL errors

上海解封背后,这群开发者“云聚会”造了个AI抗疫机器人

当字节跳动在美国输出中国式 996
随机推荐
Ffmpeg Learning Guide
[WUSTCTF2020]颜值成绩查询-1
Alibaba cloud development board haas510 responds to UART serial port instructions
[wustctf2020] selfie score query -1
简述CGI与FASTCGI区别
Paw advanced user guide
Backtracking: Prime Rings
Use of pytorch (to be supplemented)
工具笔记 —— 常用自定义工具类(正则,随机数等)
【mysql进阶】mysql索引数据结构的演变(四)
Codeforces 1629 B. GCD arrays - simple thinking
聊聊MySQL的10大经典错误
Seeking magic square of order n with C language
Mold and remainder
[semidrive source code analysis] [x9 chip startup process] 26 - LK of R5 safetyos_ INIT_ LEVEL_ Target phase code flow analysis (TP drvier, audio server initialization)
阿裏雲開發板HaaS510報送設備屬性
通过loganalyzer展示数据库中的日志
【mysql进阶】索引分类及索引优化方案(五)
拆改广告机---业余解压
Go zero micro Service Practice Series (II. Service splitting)