InvokeAI/scripts/generate_profile_graphs.sh
psychedelicious 4602efd598
feat: add profiler util (#5601)
* feat(config): add profiling config settings

- `profile_graphs` enables graph profiling with cProfile
- `profiles_dir` sets the output for profiles

* feat(nodes): add Profiler util

Simple wrapper around cProfile.

* feat(nodes): use Profiler in invocation processor

* scripts: add generate_profile_graphs.sh script

Helper to generate graphs for profiles.

* pkg: add snakeviz and gprof2dot to dev deps

These are useful for profiling.

* tests: add tests for profiler util

* fix(profiler): handle previous profile not stopped cleanly

* feat(profiler): add profile_prefix config setting

The prefix is used when writing profile output files. Useful to organise profiles into sessions.

* tidy(profiler): add `_` to private API

* feat(profiler): simplify API

* feat(profiler): use child logger for profiler logs

* chore(profiler): update docstrings

* feat(profiler): stop() returns output path

* chore(profiler): fix docstring

* tests(profiler): update tests

* chore: ruff
2024-01-31 10:51:57 +00:00

28 lines
894 B
Bash
Executable File

#!/bin/bash
# Accepts a path to a directory containing .prof files and generates a graphs
# for each of them. The default output format is pdf, but can be changed by
# providing a second argument.
# Usage: ./generate_profile_graphs.sh <path_to_profiles> <type>
# <path_to_profiles> is the path to the directory containing the .prof files
# <type> is the type of graph to generate. Defaults to 'pdf' if not provided.
# Valid types are: 'svg', 'png' and 'pdf'.
# Requires:
# - graphviz: https://graphviz.org/download/
# - gprof2dot: https://github.com/jrfonseca/gprof2dot
if [ -z "$1" ]; then
echo "Missing path to profiles directory"
exit 1
fi
type=${2:-pdf}
for file in $1/*.prof; do
base_name=$(basename "$file" .prof)
gprof2dot -f pstats "$file" | dot -T$type -Glabel="Session ID ${base_name}" -Glabelloc="t" -o "$1/$base_name.$type"
echo "Generated $1/$base_name.$type"
done