Skip to content

Commit

Permalink
feat: retrieve v8 flags from @codspeed/core introspection mechanism
Browse files Browse the repository at this point in the history
Co-authored-by: @adriencaccia
  • Loading branch information
art049 committed Jun 27, 2023
1 parent f5d6dfd commit 9cf6a36
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
54 changes: 29 additions & 25 deletions dist/bin/node
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,38 @@ fi
# Save the real node path.
REAL_NODE_PATH=$(env PATH="$ORIGINAL_PATH" which node)

V8_FLAGS=(
"--hash-seed=1"
"--random-seed=1"
"--no-opt"
"--predictable"
"--predictable-gc-schedule"
)

# get node major version, using bash regex
NODE_MAJOR_VERSION=$($REAL_NODE_PATH --version | sed -E 's/^v([0-9]+)\..*$/\1/')

# add flags deprecated in node 18 in older versions
if [ "$NODE_MAJOR_VERSION" -lt 18 ]; then
V8_FLAGS=(
"${V8_FLAGS[@]}"
"--no-randomize-hashes"
)
# Generate a random file in /tmp to store introspection data
INTROSPECTION_FILE=$(mktemp)
echo "::debug::Introspection file: $INTROSPECTION_FILE"

# Temporarily disable 'set -e' for the command and capture its exit code.
echo ::debug::Introspection trigger: env __CODSPEED_NODE_CORE_INTROSPECTION_PATH__="$INTROSPECTION_FILE" $REAL_NODE_PATH "$@"
set +e
{
env __CODSPEED_NODE_CORE_INTROSPECTION_PATH__="$INTROSPECTION_FILE" $REAL_NODE_PATH "$@"
FIRST_EXIT_CODE=$?
}
set -e

INTROSPECTION_EXIT_CODE=213
# If the exit code was anything other than the INTROSPECTION_EXIT_CODE, exit with that code.
# If no introspection happened, we will exit here with the original exit code.
if [ "$FIRST_EXIT_CODE" -ne $INTROSPECTION_EXIT_CODE ]; then
echo "::debug::No introspection detected (exit code: $FIRST_EXIT_CODE)"
exit "$FIRST_EXIT_CODE"
fi
# add flags deprecated in node 20 in older versions
if [ "$NODE_MAJOR_VERSION" -lt 20 ]; then
V8_FLAGS=(
"${V8_FLAGS[@]}"
"--no-scavenge-task"
)
# If the introspection file is empty, it means that the introspection didn't happen (exit code collision).
if [ ! -s "$INTROSPECTION_FILE" ]; then
echo "::debug::No introspection detected (no introspection file found)"
exit "$FIRST_EXIT_CODE"
fi

# Retrieve the V8 flags from the introspection file
V8_FLAGS=$(jq -r '.flags | join(" ")' "$INTROSPECTION_FILE")
echo "::debug::V8 flags harvested from introspection: $V8_FLAGS"

echo "::debug::Running the CodSpeed node script, the node command that will be run:"
echo "::debug::$REAL_NODE_PATH" "${V8_FLAGS[@]}" "$@"
echo "::debug::$REAL_NODE_PATH" $V8_FLAGS "$@"

# Call the real "node" command with any arguments passed to this script.
$REAL_NODE_PATH "${V8_FLAGS[@]}" "$@"
$REAL_NODE_PATH $V8_FLAGS "$@"
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ const run = async (inputs: ActionInputs): Promise<{profileFolder: string}> => {
PATH: `${customBinPath}:${process.env.PATH}`,
PYTHONMALLOC: "malloc",
PYTHONHASHSEED: "0",
/**
* @deprecated this should not be used to add new flags and
* the getV8Flags from codspeed-node should be preferred
* (available from 1.2.0)
*/
CODSPEED_V8_FLAGS: [
"--hash-seed=1",
"--random-seed=1",
"--no-randomize-hashes",
"--no-scavenge-task",
"--no-opt ",
"--predictable ",
"--predictable-gc-schedule",
].join(" "),
ARCH: arch,
CODSPEED_ENV: "github",
},
Expand Down

0 comments on commit 9cf6a36

Please sign in to comment.