Skip to content
This repository has been archived by the owner on Jan 4, 2020. It is now read-only.

Marathon script uses all available memory #190

Open
eivindml opened this issue Nov 7, 2018 · 3 comments
Open

Marathon script uses all available memory #190

eivindml opened this issue Nov 7, 2018 · 3 comments

Comments

@eivindml
Copy link

eivindml commented Nov 7, 2018

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

@vknabel
Copy link
Contributor

vknabel commented Nov 7, 2018

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"])

@eivindml
Copy link
Author

eivindml commented Nov 7, 2018

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.

@vknabel
Copy link
Contributor

vknabel commented Nov 7, 2018

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 vapor/vapor#796 (comment)

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants