Skip to content

Commit

Permalink
drop! add perf logs
Browse files Browse the repository at this point in the history
  • Loading branch information
o-orand committed Sep 13, 2023
1 parent c6544e2 commit 2fbd4ec
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions assets/check
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
#!/bin/bash
# vim: set ft=sh

log() {
local level=$1
local message=$2
local logfile=$3


echo "$(date +'%Y-%m-%d-%H-%M-%S.%N') - $level - $message " >> $logfile
}
set -e

exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
TIMESTAMP_CMD="date +'%Y-%m-%d-%H-%M-%S.%N'"
TIMESTAMP=$(date +'%Y-%m-%d-%H-%M-%S')
export PERFLOG_FILE=/tmp/perf-log-$TIMESTAMP.log

#ls -A1t /tmp/perf-log- | tail -n +11 | xargs rm
log "INFO" "Starting check" $PERFLOG_FILE
source $(dirname $0)/common.sh

echo ""
# for jq
PATH=/usr/local/bin:$PATH

Expand Down Expand Up @@ -35,6 +48,9 @@ sparse_checkout=$(jq -r '(.source.sparse_checkout // false)' <<< "$payload")
sparse_paths=`echo "$paths" | tr "\n\r" " "`
reverse=false

log "INFO" "Patch to disable sparse_checkout" $PERFLOG_FILE
sparse_checkout="false"

configure_git_global "${git_config_payload}"

destination=$TMPDIR/git-resource-repo-cache
Expand All @@ -49,10 +65,14 @@ fi
# We're just checking for commits; we don't ever need to fetch LFS files here!
export GIT_LFS_SKIP_SMUDGE=1

log "DEBUG" "before destination check" $PERFLOG_FILE
if [ -d $destination ]; then
cd $destination
log "DEBUG" "before git fetch" $PERFLOG_FILE
git fetch $tagflag -f
log "DEBUG" "before git reset" $PERFLOG_FILE
git reset --hard FETCH_HEAD
log "DEBUG" "after git reset" $PERFLOG_FILE
else
branchflag=""
if [ -n "$branch" ]; then
Expand All @@ -68,13 +88,18 @@ else
git sparse-checkout set $sparse_paths
git checkout $branch
else
log "DEBUG" "before git clone" $PERFLOG_FILE
git clone --single-branch $uri $branchflag $destination $tagflag
log "DEBUG" "after git clone" $PERFLOG_FILE
cd $destination
fi
fi

log "DEBUG" "before ref" $PERFLOG_FILE
if [ -n "$ref" ] && git cat-file -e "$ref"; then
log "DEBUG" "before git rev-list --max-parents=0" $PERFLOG_FILE
init_commit=$(git rev-list --max-parents=0 HEAD | tail -n 1)
log "DEBUG" "after git rev-list --max-parents=0" $PERFLOG_FILE
if [ "${ref}" = "${init_commit}" ]; then
reverse=true
log_range="HEAD"
Expand All @@ -87,12 +112,14 @@ else
ref=""
fi

log "DEBUG" "before paths_search" $PERFLOG_FILE
if [ "$paths" = "." ] && [ -z "$ignore_paths" ]; then
paths_search=""
else
paths_search=`echo "-- $paths $ignore_paths" | tr "\n\r" " "`
fi

log "DEBUG" "before filter_whitelist" $PERFLOG_FILE
list_command="git rev-list --all --first-parent $log_range $paths_search"
if [ `echo $filter_whitelist | jq -r '. | length'` -gt 0 ]
then
Expand All @@ -103,7 +130,7 @@ then
list_command+=" --grep=\"$wli\""
done
fi

log "DEBUG" "before filter_blacklist" $PERFLOG_FILE
if [ `echo $filter_blacklist | jq -r '. | length'` -gt 0 ]
then
list_command+=" | git rev-list --stdin --date-order --invert-grep --first-parent --no-walk=unsorted "
Expand All @@ -129,24 +156,29 @@ lines_including_and_after() {
}

get_commit(){
log "DEBUG" "start get_commit" $PERFLOG_FILE
for tag in $*; do
commit=$(git rev-list -n 1 $tag)
jq -n '{ref: $tag, commit: $commit}' --arg tag $tag --arg commit $commit
done
log "DEBUG" "end get_commit" $PERFLOG_FILE
}

log "DEBUG" "before log_range" $PERFLOG_FILE
#if no range is selected just grab the last commit that fits the filter
if [ -z "$log_range" ]
then
list_command+="| git rev-list --stdin --date-order --no-walk=unsorted -$version_depth --reverse"
fi

log "DEBUG" "before reverse check" $PERFLOG_FILE
if [ "$reverse" == "true" ]
then
list_command+="| git rev-list --stdin --date-order --first-parent --no-walk=unsorted --reverse"
fi

if [ -n "$tag_filter" ]; then
log "DEBUG" "start use tag_filter" $PERFLOG_FILE
{
if [ -n "$ref" ] && [ -n "$branch" ]; then
tags=$(git tag --list "$tag_filter" --sort=creatordate --contains $ref --merged $branch)
Expand All @@ -163,7 +195,11 @@ if [ -n "$tag_filter" ]; then
get_commit $tag
fi
} | jq -s "map(.)" >&3
log "DEBUG" "end tag filter" $PERFLOG_FILE

elif [ -n "$tag_regex" ]; then
log "DEBUG" "start use tag_regex" $PERFLOG_FILE

{
if [ -n "$ref" ] && [ -n "$branch" ]; then
tags=$(git tag --list --sort=creatordate --contains $ref --merged $branch | grep -Ex "$tag_regex")
Expand All @@ -180,10 +216,14 @@ elif [ -n "$tag_regex" ]; then
get_commit $tag
fi
} | jq -s "map(.)" >&3
log "DEBUG" "end - use tag_regex" $PERFLOG_FILE
else
{
set -f
eval "$list_command"
set +f
} | jq -R '.' | jq -s "map({ref: .})" >&3
log "DEBUG" "Starting check" $PERFLOG_FILE
fi

log "INFO" "End check" $PERFLOG_FILE

0 comments on commit 2fbd4ec

Please sign in to comment.