src/Sim/Dumper/TraceDumper.cpp

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
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 }

Onikiri2に対してTue Jun 18 14:34:22 2013に生成されました。  doxygen 1.4.7