diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-07-31 15:03:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-31 13:03:27 -0700 |
| commit | bab4b821dc6bcee4ff86751743762584c17e9103 (patch) | |
| tree | f67eb2e1d4825cc45808cca285b0936b3f25827f /tools | |
| parent | 93a3ba812dd33b10f166f9172bd781e84d938e21 (diff) | |
Feature/replayer (#4750)
* record/replay: Implement the json consumer
Finish the implementation of json consumer.
Fix some bug in the block processing as Tailer is not a necessary block
so if the Magic bit is "HEAD", we should keep processing.
* record/replay: Implement the replayer component
Implement the replayer consumer, and also finish the slang-replay
standalone app that will run the while replayer.
It can take an option "--convert-json | -cj" which will convert
the record binary file to a human readable json file.
If there is no option provided, it will replay the record file by
default.
TODO: #4764 is created to remove the std::filesystem usage.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/slang-replay/main.cpp | 104 |
1 files changed, 101 insertions, 3 deletions
diff --git a/tools/slang-replay/main.cpp b/tools/slang-replay/main.cpp index 7f042f91b..adce34c56 100644 --- a/tools/slang-replay/main.cpp +++ b/tools/slang-replay/main.cpp @@ -1,10 +1,108 @@ #include <stdio.h> +#include <filesystem> + #include <replay/recordFile-processor.h> -#include <replay/decoder-consumer.h> +#include <replay/json-consumer.h> +#include <replay/replay-consumer.h> +#include <replay/slang-decoder.h> + +struct Options +{ + bool convertToJson {false}; + Slang::String recordFileName; +}; + +void printUsage() +{ + printf("Usage: slang-replay [options] <record-file>\n"); + printf("Options:\n"); + printf(" --convert-json, -cj: Convert the record file to a JSON file in the same directory with record file.\n\ + When this option is set, it won't replay the record file.\n"); +} + +Options parseOption(int argc, char *argv[]) +{ + Options option; + char const* arg {}; + if (argc <= 1) + { + printUsage(); + exit(1); + } + + int argIndex = 1; + while(argIndex < argc) + { + arg = argv[argIndex]; + + // For anything not starting with a '-', it is a file name + if (arg[0] != '-') + { + option.recordFileName = arg; + argIndex++; + } + else if ( (strcmp("--convert-json", arg) == 0) || + (strcmp("-cj", arg) == 0) ) + { + option.convertToJson = true; + argIndex++; + } + else if ( (strcmp("--help", arg) == 0) || + (strcmp("-h", arg) == 0) ) + { + printUsage(); + exit(0); + } + else + { + // Unknown option + printf("Unknown option: %s\n", arg); + printUsage(); + exit(1); + } + } + + if (option.recordFileName.getLength() == 0) + { + printUsage(); + exit(1); + } + + return option; +} int main(int argc, char *argv[]) { - // TODO: This is just a place holder binary - SlangRecord::RecordFileProcessor recordFileProcessor("input.capture"); + Options options = parseOption(argc, argv); + + SlangRecord::RecordFileProcessor recordFileProcessor(options.recordFileName); + + + std::filesystem::path jsonPath = options.recordFileName.begin(); + jsonPath.replace_extension(".json"); + + SlangRecord::JsonConsumer jsonConsumer(jsonPath.string()); + SlangRecord::ReplayConsumer replayConsumer; + + SlangRecord::SlangDecoder decoder; + + if (options.convertToJson) + { + decoder.addConsumer(&jsonConsumer); + } + else + { + decoder.addConsumer(&replayConsumer); + } + + recordFileProcessor.addDecoder(&decoder); + + while(true) + { + if(!recordFileProcessor.processNextBlock()) + { + break; + } + } return 0; } |
