-
Notifications
You must be signed in to change notification settings - Fork 141
Added operation logging to JSON #1452
Draft
pavelkryukov
wants to merge
9
commits into
main
Choose a base branch
from
json
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a776085
Added operation logging to JSON
andreyess 1cbb6df
Add Andrei Karpyza to LICENSE
pavelkryukov f4f4d1e
Use get_disasm instead of generate_disasm
pavelkryukov eed20d9
Merge branch 'master' into json
pavelkryukov d3f2be0
Close JSON output file on exit
pavelkryukov 412bcc2
Use linux-compatible file name for JSON output
pavelkryukov 44b91c8
Match PipelineVis input format
pavelkryukov 156057b
Merge branch 'master' into json
pavelkryukov 015a2f4
Merge branch 'main' into json
pavelkryukov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
#define LOG_H | ||
|
||
#include <iosfwd> | ||
#include "fstream" | ||
|
||
class LogOstream | ||
{ | ||
|
@@ -49,6 +50,9 @@ class Log | |
mutable LogOstream sout; | ||
mutable LogOstream serr; | ||
|
||
std::ofstream& jsonout(); | ||
bool jsonout_enabled = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By using |
||
|
||
Log(); | ||
|
||
// Rule of five | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
namespace config { | ||
static const AliasedValue<std::string> units_to_log = { "l", "logs", "nothing", "print logs for modules"}; | ||
static const Switch topology_dump = { "tdump", "module topology dump into topology.json" }; | ||
// command line flag argument for enable/disable json logging | ||
static const AliasedSwitch json_dump = { "j", "json-dump", "json logs in .\\logs.json" }; | ||
} // namespace config | ||
|
||
template <typename ISA> | ||
|
@@ -32,6 +34,8 @@ PerfSim<ISA>::PerfSim( std::endian endian, std::string_view isa) | |
init_portmap(); | ||
enable_logging( config::units_to_log); | ||
topology_dumping( config::topology_dump, "topology.json"); | ||
// json logger configuration | ||
enable_json_logging(config::json_dump); | ||
} | ||
|
||
template <typename ISA> | ||
|
@@ -59,6 +63,9 @@ Addr PerfSim<ISA>::get_pc() const | |
template<typename ISA> | ||
Trap PerfSim<ISA>::run( uint64 instrs_to_run) | ||
{ | ||
/* start json dump strings */ | ||
start_dump_json(); | ||
|
||
current_trap = Trap( Trap::NO_TRAP); | ||
|
||
writeback.set_instrs_to_run( instrs_to_run); | ||
|
@@ -68,6 +75,9 @@ Trap PerfSim<ISA>::run( uint64 instrs_to_run) | |
while (current_trap == Trap::NO_TRAP) | ||
clock(); | ||
|
||
/* end strings */ | ||
stop_dump_json(); | ||
|
||
dump_statistics(); | ||
|
||
return current_trap; | ||
|
@@ -99,6 +109,24 @@ auto get_rate( int total, float64 piece) | |
return total != 0 ? ( piece / total * 100) : 0; | ||
} | ||
|
||
/* standard lines loggers implementation */ | ||
template<typename ISA> | ||
void PerfSim<ISA>::start_dump_json() { | ||
if (jsonout_enabled) | ||
(jsonout()) << "[\n" << | ||
"\t{ \"type\": \"Stage\", \"id\": 0, \"description\": \"Fetch\" },\n" << | ||
"\t{ \"type\": \"Stage\", \"id\": 1, \"description\": \"Decode\" },\n" << | ||
"\t{ \"type\": \"Stage\", \"id\": 2, \"description\": \"Execute\" },\n" << | ||
"\t{ \"type\": \"Stage\", \"id\": 3, \"description\": \"Memory\" },\n" << | ||
"\t{ \"type\": \"Stage\", \"id\": 4, \"description\": \"Writeback\" }"; | ||
} | ||
|
||
template<typename ISA> | ||
void PerfSim<ISA>::stop_dump_json() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It must be called in destructor, so file closing and proper finalization would be guaranteed. |
||
if (jsonout_enabled) | ||
(jsonout()) << "\n]\n"; | ||
} | ||
|
||
template<typename ISA> | ||
void PerfSim<ISA>::dump_statistics() const | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing, these variables should be non-static and reside in "Root" class. Objects can access them recursively.
Additionally, file name should be configurable from command line.