Skip to content
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

feat: add low-memory-mode option for automagic #163

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: setup Nim
uses: jiro4989/setup-nim-action@v1
with:
nim-version: '2.x' # default is 'stable'
nim-version: '2.0.4' # default is 'stable'

- name: clone takajo
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@v3
- uses: jiro4989/setup-nim-action@v1
with:
nim-version: '2.x' # default is 'stable'
nim-version: '2.0.4' # default is 'stable'
- name: Build check
run: nimble build --threads:on -Y
- name: Run tests
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:

- name: Setup Nim
uses: jiro4989/setup-nim-action@v1
with:
nim-version: '2.0.4'

- name: Update nimble libraries
run: |
Expand Down
1 change: 1 addition & 0 deletions src/takajo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ when isMainModule:
help = {
"displayTable": "display the results table (default: false)",
"level": "specify the minimum alert level (default: informational)",
"low-memory-mode": "Scan with minimal memory usage by processing each command sequentially (default: false)",
"output": "output directory (default: case-1)",
"quiet": "do not display the launch banner (default: false)",
"skipProgressBar": "do not display the progress bar (default: false)",
Expand Down
7 changes: 5 additions & 2 deletions src/takajopkg/automagic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type

proc autoMagic(level: string = "informational", skipProgressBar: bool = false,
displayTable: bool = false, output: string = "case-1", quiet: bool = false,
timeline: string) =
timeline: string, lowMemoryMode:bool = false) =
checkArgs(quiet, timeline, level)
if dirExists(output):
echo "The directory '" & output & "' exists. Please specify a new folder name."
Expand Down Expand Up @@ -147,4 +147,7 @@ proc autoMagic(level: string = "informational", skipProgressBar: bool = false,
let cmd = AutoMagicCmd(level: level, skipProgressBar: skipProgressBar,
displayTable: displayTable, output: output, timeline: timeline,
name: "automagic", msg: AutoMagicMsg)
cmd.analyzeJSONLFile(cmds)
if lowMemoryMode:
cmd.analyzeJSONLFileLowMemory(cmds)
else:
cmd.analyzeJSONLFile(cmds)
44 changes: 44 additions & 0 deletions src/takajopkg/takajoCore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,47 @@ proc analyzeJSONLFile*(self: AbstractCmd, cmds: seq[AbstractCmd] = newSeq[
table.echoTableSepsWithStyled(seps = boxSeps)

outputElapsedTime(startTime)


proc analyzeJSONLFileLowMemory*(self: AbstractCmd, cmds: seq[AbstractCmd] = newSeq[
AbstractCmd]()) =
let startTime = epochTime()
var commands = cmds
var bar: SuruBar
if not self.skipProgressBar:
bar = initSuruBar()
bar[0].total = countJsonlAndStartMsg(self.name, self.msg, self.timeline) * cmds.len()
bar.setup()
var resultSummaryTable: seq[CmdResult] = @[]
let fileInfo = getFileInfo(self.timeline)
var filePaths = @[self.timeline]
if (fileInfo.kind == pcDir or fileInfo.kind == pcLinkToDir):
filePaths = getTargetExtFileLists(self.timeline, ".jsonl", true)
for cmd in commands:
for path in filePaths:
for line in lines(path):
if not self.skipProgressBar:
inc bar
bar.update(1000000000)
let jsonLineOpt = parseLine(line)
if jsonLineOpt.isNone:
continue
let jsonLine: HayabusaJson = jsonLineOpt.get()
try:
if cmd.filter(jsonLine):
cmd.analyze(jsonLine)
except CatchableError:
continue
cmd.resultOutput()
resultSummaryTable.add(cmd.cmdResult)
if not self.skipProgressBar:
bar.finish()

var table: TerminalTable
table.add @["Command", "Results", "Saved Files"]
for i, result in enumerate(resultSummaryTable):
table.add commands[i].name, result.results, result.savedFiles
echo ""
table.echoTableSepsWithStyled(seps = boxSeps)

outputElapsedTime(startTime)
Loading