当前位置:网站首页>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;
}

 

原网站

版权声明
本文为[123axj]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010514261423.html