-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add instrumented go shell script #102
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
Merged
not-matthias
merged 1 commit into
main
from
cod-1208-run-golang-with-walltime-in-runner
Aug 28, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| debug_log() { | ||
| if [ "${CODSPEED_LOG:-}" = "debug" ]; then | ||
| echo "[DEBUG go.sh] $*" >&2 | ||
| fi | ||
| } | ||
|
|
||
| debug_log "Called with arguments: $*" | ||
| debug_log "Number of arguments: $#" | ||
|
|
||
| # Find the real go binary, so that we don't end up in infinite recursion | ||
| REAL_GO=$(which -a go | grep -v "$(realpath "$0")" | head -1) | ||
| if [ -z "$REAL_GO" ]; then | ||
| echo "ERROR: Could not find real go binary" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if we have any arguments | ||
| if [ $# -eq 0 ]; then | ||
| debug_log "No arguments provided, using standard go binary" | ||
| "$REAL_GO" | ||
| exit $? | ||
| fi | ||
|
|
||
| # Check if first argument is "test" | ||
| if [ "$1" = "test" ]; then | ||
| debug_log "Detected 'test' command, routing to go-runner" | ||
|
|
||
| # Find go-runner or install if not found | ||
| GO_RUNNER=$(which go-runner 2>/dev/null || true) | ||
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [ -z "$GO_RUNNER" ]; then | ||
| curl -fsSL http://github.com/CodSpeedHQ/runner/releases/latest/download/go-runner-installer.sh | bash -s -- --quiet | ||
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| GO_RUNNER=$(which go-runner 2>/dev/null || true) | ||
| fi | ||
|
|
||
| debug_log "Using go-runner at: $GO_RUNNER" | ||
| debug_log "Full command: RUST_LOG=info $GO_RUNNER $*" | ||
|
|
||
| "$GO_RUNNER" "$@" | ||
| else | ||
| debug_log "Detected non-test command ('$1'), routing to standard go binary" | ||
| debug_log "Full command: $REAL_GO $*" | ||
| "$REAL_GO" "$@" | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| use crate::prelude::*; | ||
| use std::{env, fs::File, io::Write, os::unix::fs::PermissionsExt, path::PathBuf}; | ||
|
|
||
| const INTROSPECTED_GO_SCRIPT: &str = include_str!("go.sh"); | ||
|
|
||
| /// Creates the `go` script that will replace the `go` binary while running | ||
| /// Returns the path to the script folder, which should be added to the PATH environment variable | ||
| pub fn setup_introspected_go() -> Result<PathBuf> { | ||
| let script_folder = env::temp_dir().join("codspeed_introspected_go"); | ||
| std::fs::create_dir_all(&script_folder)?; | ||
| let script_path = script_folder.join("go"); | ||
| let mut script_file = File::create(script_path)?; | ||
| script_file.write_all(INTROSPECTED_GO_SCRIPT.as_bytes())?; | ||
| // Make the script executable | ||
| let mut perms = script_file.metadata()?.permissions(); | ||
| perms.set_mode(0o755); | ||
| script_file.set_permissions(perms)?; | ||
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Ok(script_folder) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| pub mod executor; | ||
| pub mod introspected_golang; | ||
| pub mod perf; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.