Skip to content

Commit 8057e11

Browse files
committed
Python: CG trace: Add ./helper.sh metrics command
1 parent 779a82e commit 8057e11

File tree

1 file changed

+29
-5
lines changed
  • python/tools/recorded-call-graph-metrics

1 file changed

+29
-5
lines changed

python/tools/recorded-call-graph-metrics/helper.sh

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@ set -Eeuo pipefail # see https://vaneyckt.io/posts/safer_bash_scripts_with_set_e
55
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
66
PROJECTS_FILE="$SCRIPTDIR/projects.json"
77

8-
PROJECT_BASE_DIR="$SCRIPTDIR/projects"
8+
METRICS_QUERY="ql/query/Metrics.ql"
9+
10+
PROJECTS_BASE_DIR="$SCRIPTDIR/projects"
911

1012
repo_dir() {
11-
echo "$PROJECT_BASE_DIR/$1/repo"
13+
echo "$PROJECTS_BASE_DIR/$1/repo"
1214
}
1315

1416
venv_dir() {
15-
echo "$PROJECT_BASE_DIR/$1/venv"
17+
echo "$PROJECTS_BASE_DIR/$1/venv"
1618
}
1719

1820
trace_dir() {
19-
echo "$PROJECT_BASE_DIR/$1/traces"
21+
echo "$PROJECTS_BASE_DIR/$1/traces"
2022
}
2123

2224
db_path() {
23-
echo "$PROJECT_BASE_DIR/$1/$1-db"
25+
echo "$PROJECTS_BASE_DIR/$1/$1-db"
26+
}
27+
28+
query_result_base_path() {
29+
echo "$PROJECTS_BASE_DIR/$1/$2"
2430
}
2531

2632
help() {
@@ -31,6 +37,7 @@ $0 repo <projects> Fetch repo for projects
3137
$0 setup <projects> Perform setup steps for projects (install dependencies)
3238
$0 trace <projects> Trace projects
3339
$0 db <projects> Build databases for projects
40+
$0 metrics <projects> Run $METRICS_QUERY on projects
3441
$0 all <projects> Perform all the above steps for projects
3542
"""
3643
}
@@ -146,6 +153,22 @@ db() {
146153
done
147154
}
148155

156+
metrics() {
157+
for project in $@; do
158+
check_project_exists $project
159+
160+
echo "Running $METRICS_QUERY on '$project'"
161+
162+
RESULTS_BASE=$(query_result_base_path $project Metrics)
163+
DB=$(db_path $project)
164+
165+
codeql query run "$SCRIPTDIR/$METRICS_QUERY" --database "$DB" --output "${RESULTS_BASE}.bqrs"
166+
codeql bqrs decode "${RESULTS_BASE}.bqrs" --format text --output "${RESULTS_BASE}.txt"
167+
168+
echo "Results available in '${RESULTS_BASE}.txt'"
169+
done
170+
}
171+
149172
all() {
150173
for project in $@; do
151174
check_project_exists $project
@@ -154,6 +177,7 @@ all() {
154177
setup $project
155178
trace $project
156179
db $project
180+
metrics $project
157181
done
158182
}
159183

0 commit comments

Comments
 (0)