00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <pch.h>
00033
00034 #include "Sim/Dumper/TraceDumper.h"
00035
00036 #include "Utility/RuntimeError.h"
00037 #include "Sim/Dumper/DumpState.h"
00038 #include "Sim/Dumper/DumpFileName.h"
00039 #include "Sim/Op/Op.h"
00040
00041
00042 using namespace std;
00043 using namespace boost;
00044 using namespace Onikiri;
00045
00046 TraceDumper::TraceDumper()
00047 {
00048 m_enabled = false;
00049 m_detail = 0;
00050 m_valDetail = 0;
00051 m_cycle = 0;
00052 m_skipInsns = 0;
00053 m_flush = false;
00054 }
00055
00056 TraceDumper::~TraceDumper()
00057 {
00058 }
00059
00060 void TraceDumper::Initialize( const String& suffix )
00061 {
00062 LoadParam();
00063 Open( suffix );
00064 }
00065
00066 void TraceDumper::Finalize()
00067 {
00068 ReleaseParam();
00069 Close();
00070 }
00071
00072 void TraceDumper::DumpString(const std::string& str)
00073 {
00074 m_dumpStream << m_cycle << "\t" << str << "\n";
00075 if( m_flush )
00076 m_dumpStream.flush();
00077 }
00078
00079 void TraceDumper::Open( const String& suffix )
00080 {
00081
00082 if( Enabled() && (!m_dumpStream.is_complete()) ) {
00083 String fileName = g_env.GetHostWorkPath() + MakeDumpFileName( m_filename, suffix, m_gzipEnabled );
00084 if (m_gzipEnabled){
00085 m_dumpStream.push(
00086 iostreams::gzip_compressor(
00087 iostreams::gzip_params(m_gzipLevel)
00088 )
00089 );
00090 }
00091 m_dumpStream.push( iostreams::file_sink(fileName, ios::binary));
00092 }
00093 }
00094
00095 void TraceDumper::Close()
00096 {
00097 if(m_dumpStream.is_complete()) {
00098 m_dumpStream.reset();
00099 }
00100 }
00101
00102
00103 void TraceDumper::Dump(DUMP_STATE state, Op* op, int detail)
00104 {
00105 if( !Enabled() )
00106 return;
00107
00108 if( op->GetGlobalSerialID() < m_skipInsns )
00109 return;
00110
00111 const char* str = g_traceDumperStrTbl[state];
00112
00113 if(detail == -1){
00114 if(op == NULL){
00115 DumpString(str);
00116 }
00117 else{
00118 Dump(state, op, Detail());
00119 }
00120 }
00121 else{
00122 ostringstream oss;
00123 oss << str << "\t" << op->ToString(detail, m_valDetail > 0);
00124 DumpString(oss.str());
00125 }
00126
00127 }
00128
00129 void TraceDumper::DumpStallBegin(Op* op)
00130 {
00131 if( !Enabled() )
00132 return;
00133
00134 if( op->GetGlobalSerialID() < m_skipInsns )
00135 return;
00136
00137 ostringstream oss;
00138 oss << "stall begin" << "\t" << op->ToString(0);
00139 DumpString(oss.str());
00140 }
00141
00142 void TraceDumper::DumpStallEnd(Op* op)
00143 {
00144 if( !Enabled() )
00145 return;
00146
00147 if( op->GetGlobalSerialID() < m_skipInsns )
00148 return;
00149
00150 ostringstream oss;
00151 oss << "stall end" << "\t" << op->ToString(0);
00152 DumpString(oss.str());
00153 }
00154
00155 void TraceDumper::SetCurrentCycle(s64 cycle)
00156 {
00157 m_cycle = cycle;
00158 }