Skip to content

Commit 7cd3e6e

Browse files
committed
Tests/LibGfx: Let jbig2/json/compile.sh process files in parallel
This uses `xargs -P` as a fairly simple parallelism mechanism. It relies on `echo` being atomic in practice (for small enough outputs). (Alternatively, each child could write to a dedicated log file in some temp dir, and we could cat all the log files at the end. For now, this seems like it's good enough.) Takes the time to run compile.sh from 1.65s to 0.23s on my system.
1 parent 15866aa commit 7cd3e6e

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed
Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
#!/bin/bash
22

3-
set -eu
3+
set -u
44

5-
DIR=$(dirname "$0")
6-
LAGOM_BUILD=$DIR/../../../../../Build/lagom
7-
JBIG2_FROM_JSON=$LAGOM_BUILD/bin/jbig2-from-json
5+
DIR="$(cd "$(dirname "$0")" && pwd)"
6+
ROOT="$DIR/../../../../.."
7+
LAGOM_BUILD="$ROOT/Build/lagom"
8+
JBIG2_FROM_JSON="$LAGOM_BUILD/bin/jbig2-from-json"
89

9-
for f in "$DIR"/*.json; do
10-
f_jb2="$DIR"/../$(basename "${f%.json}.jbig2")
11-
if ! "$JBIG2_FROM_JSON" -o "$f_jb2" "$f"; then
12-
echo failed to run:
13-
echo "$JBIG2_FROM_JSON" -o "$f_jb2" "$f"
14-
exit 1
15-
fi
16-
done
10+
export DIR
11+
export JBIG2_FROM_JSON
12+
13+
run_jbig2() {
14+
f="$1"
15+
filename=$(basename "${f%.json}.jbig2")
16+
f_jb2="$DIR/../$filename"
17+
18+
if ! output=$("$JBIG2_FROM_JSON" -o "$f_jb2" "$f" 2>&1); then
19+
echo failed to run:
20+
echo "$JBIG2_FROM_JSON" -o "$f_jb2" "$f"
21+
echo "$output"
22+
return 1
23+
fi
24+
}
25+
26+
. "$ROOT/Meta/shell_include.sh"
27+
NPROC=$(get_number_of_processing_units)
28+
29+
export -f run_jbig2
30+
find "$DIR" -maxdepth 1 -name "*.json" -print0 | \
31+
xargs -0 -P "$NPROC" -I {} bash -c 'run_jbig2 "$@"' _ {}

0 commit comments

Comments
 (0)