-
-
Notifications
You must be signed in to change notification settings - Fork 26
Split codetracer.nim into multiple files and remove orphaned functions #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import | ||
| std/[ osproc ], | ||
| ../../common/[paths] | ||
|
|
||
| proc displayHelp*: void = | ||
| # echo "help: TODO" | ||
| let process = startProcess(codetracerExe, args = @["--help"], options = {poParentStreams}) | ||
| let code = waitForExit(process) | ||
| quit(code) | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import | ||
| std/[strutils, strformat, sequtils, algorithm, rdstdin], | ||
| ../../common/[ trace_index, types, lang ], | ||
| ../trace/[ run, storage_and_import ], | ||
| ../utilities/[ env ], | ||
| ../codetracerconf, | ||
| json_serialization | ||
|
|
||
| const | ||
| TRACE_CMD_COLUMN_WIDTH = 70 | ||
| TRACE_WORKDIR_COLUMN_WIDTH = 40 | ||
|
|
||
| func limitColumnLeft(text: string, width: int): string = | ||
| if text.len > width: | ||
| ".." & text[text.len - (width - 2) .. ^1] | ||
| else: | ||
| text | ||
|
|
||
|
|
||
| func limitColumnRight(text: string, width: int): string = | ||
| if text.len > width: | ||
| text[0 .. (width - 2) - 1] & ".." | ||
| else: | ||
| text | ||
|
|
||
|
|
||
| func traceInText*(trace: Trace): string = | ||
| let displayCmd = limitColumnRight(trace.program & " " & trace.args.join(" "), TRACE_CMD_COLUMN_WIDTH) | ||
| let displayWorkdir = limitColumnLeft("ran in " & trace.workdir, TRACE_WORKDIR_COLUMN_WIDTH) | ||
| let idColumn = fmt"{trace.id}." | ||
| alignLeft(idColumn, 5) & " | " & alignLeft(displayCmd, TRACE_CMD_COLUMN_WIDTH) & " | " & | ||
| alignLeft(displayWorkdir, TRACE_WORKDIR_COLUMN_WIDTH) & " | " & | ||
| alignLeft(toName(trace.lang), 15) & " | " & alignLeft(trace.date, 15) | ||
|
|
||
|
|
||
| func tracesInText*(traces: seq[Trace]): string = | ||
| traces.reversed.mapIt(traceInText(it)).join("\n") | ||
|
|
||
|
|
||
| func tracesInJson*(traces: seq[Trace]): string = | ||
| Json.encode(traces) | ||
|
|
||
|
|
||
| proc interactiveReplayMenu*(command: StartupCommand) = | ||
| let recordCore = envLoadRecordCore() | ||
| # ordered by id | ||
| # returns the newest(biggest id) first | ||
| let traces = trace_index.all(test=false) | ||
| let limitedTraces = if traces.len > 10: | ||
| traces[0 ..< 10] | ||
| else: | ||
| traces | ||
|
|
||
| echo "Select a trace to replay, entering its id:" | ||
| echo "" | ||
|
|
||
| for trace in limitedTraces: | ||
| echo traceInText(trace) | ||
|
|
||
| if traces.len > 10: | ||
| echo "..(older traces not shown)" | ||
|
|
||
| echo "" | ||
|
|
||
| while true: | ||
| let raw = readLineFromStdin("replay: ") | ||
| try: | ||
| let traceId = raw.parseInt | ||
| let trace = trace_index.find(traceId, test=false) | ||
| if not trace.isNil: | ||
| if command != StartupCommand.upload: | ||
| discard runRecordedTrace(trace, test=false, recordCore=recordCore) | ||
| else: | ||
| uploadTrace(trace) | ||
| break | ||
| else: | ||
| echo fmt"trace with id {traceId} not found in local codetracer db, please try again" | ||
| except: | ||
| echo "error: ", getCurrentExceptionMsg() | ||
| echo "please try again" |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import | ||
| ../../common/trace_index, | ||
| logging, | ||
| interactive_replay | ||
|
|
||
| type | ||
| ListFormat = enum FormatText, FormatJson | ||
| ListTarget {.pure.} = enum Local, Remote | ||
|
|
||
|
|
||
| proc parseListFormat(arg: string): ListFormat = | ||
| if arg == "text": | ||
| FormatText | ||
| elif arg == "json": | ||
| FormatJson | ||
| else: | ||
| errorMessage "error: expected --format text/json" | ||
| quit(1) | ||
|
|
||
|
|
||
| proc parseListTarget(arg: string): ListTarget = | ||
| if arg == "local": | ||
| ListTarget.Local | ||
| elif arg == "remote": | ||
| ListTarget.Remote | ||
| else: | ||
| errorMessage "error: expected local or remote" | ||
| quit(1) | ||
|
|
||
|
|
||
| proc listLocalTraces(format: ListFormat) = | ||
| let traces = trace_index.all(test=false) | ||
| case format: | ||
| of FormatText: | ||
| echo tracesInText(traces) | ||
| of FormatJson: | ||
| echo tracesInJson(traces) | ||
|
|
||
|
|
||
| proc listCommand*(rawTarget: string, rawFormat: string) = | ||
| # list [local/remote (default local)] [--format text/json (default text)] | ||
| let target = parseListTarget(rawTarget) | ||
| let format = parseListFormat(rawFormat) | ||
| case target: | ||
| of ListTarget.Local: | ||
| listLocalTraces(format) | ||
| of ListTarget.Remote: | ||
| echo "error: unsupported currently!" | ||
| # listRemoteTraces(format) |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import std/[ strformat ] | ||
|
|
||
| template errorMessage*(message: string) = | ||
| echo message | ||
|
|
||
| proc notSupportedCommand*(commandName: string) = | ||
| echo fmt"{commandName} not supported with this backend" |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.