Marathon icon indicating copy to clipboard operation
Marathon copied to clipboard

Marathon script uses all available memory

Open eivindml opened this issue 5 years ago • 3 comments

Hi,

I'm testing out Swift scripting using Marathon, by trying to create a script to build and launch apps.

But it the scripts takes up all available memory, until my computer turns unresponsive. Here is the script:

import Foundation
import Files
import ShellOut

// Compile and launch project for physical device

// This compiles an archive
print("Building archive")

let _ = try shellOut(to: "xcodebuild", arguments: ["-project QDB.xcodeproj -scheme QDB -archivePath build/physical archive"])

// This compiles .ipa
print("Building ipa")
let _ = try shellOut(to: "xcodebuild", arguments: ["-exportArchive -archivePath ./build/physical.xcarchive -exportPath ./build/ -exportOptionsPlist ./export.plist"])

// Install .ipa on physical device
print("Installing to device")
let _ = try shellOut(to: "cfgutil", arguments: ["install-app build/QDB.ipa"])

If I run each shell command seperately in Terminal, they execute quite quickly, without high CPU/memory usage. But through Marathon, using ShellOut, the memory usage just increases and increases.

The first print() statement is never executed either, so it looks like it has to process the entire script somehow, before it outputs the print statements.

Not sure if this issue is related ShellOut or Marathon, but since it won't print the print statements, it looks like something related to how Marathon executes scripts.

Here you can see the running script and the memory/CPU usage. skjermbilde 2018-11-07 kl 11 00 21

eivindml avatar Nov 07 '18 10:11 eivindml

xcodebuild produces a lot of output and shellOut tries put all that output into one single Swift string if I am correct.

I did not test the following code, but you could pipe the output into /dev/null (into a .log-file). Would this solve your issue?

let _ = try shellOut(to: "bash", arguments: ["-c", "xcodebuild -project QDB.xcodeproj -scheme QDB -archivePath build/physical archive > /dev/null"])

vknabel avatar Nov 07 '18 13:11 vknabel

Thank you. That was the issue.

The example code you posted above didn't quit work. It generated some weird build files. But it works when I put it like this:

let _ = try shellOut(to: "xcodebuild", arguments: ["-project QDB.xcodeproj -scheme QDB -archivePath build/physical.xcarchive archive > /dev/null"])

Maybe it could be a feature request for ShellOut to make it not build a string of the result.

The other weird behaviour is that it needs to execute all three shellOut statements, before the print statemenst are displayed in terminal.

I would excpect the print outs to be displayed as the script is executed line by line. Without this feature, it's a bit difficult to display progress printouts to the user of the script.

eivindml avatar Nov 07 '18 14:11 eivindml

Glad to hear the memory issue is fixed. You probably need to manually flush stdout. The API might have changed, but you could try this workaround https://github.com/vapor/vapor/issues/796#issuecomment-272607499

For better readability you could create a helper which automatically flushes the contents.

vknabel avatar Nov 07 '18 16:11 vknabel