Tool which generates json trace file from GitLab pipeline to be used in chrome://tracing/ or https://ui.perfetto.dev/
Useful when you need to optimize pipeline time and you have multiple runners running jobs in parallel.
- Python >3.2
- GitLab (can be self hosted)
- GitLab Personal Access Token
To obtain Access Token go to YOUR_GITLAB_URL/-/user_settings/personal_access_tokens
and generate a token with api
scope.
You can provide GitLab URL and Access Token in two ways:
-
Environment variables:
GITLAB_URL
,GITLAB_PRIVATE_TOKEN
-
.secret.json
file in the script directory:
{
"GITLAB_URL": "https://YOUR_GITLAB_URL.com",
"GITLAB_PRIVATE_TOKEN": "glpat-XXXXXXXXXXXXXX-XXXXX"
}
Then use the tool:
py tracing.py <PROJECT_ID> <PIPELINE_ID>
If your project ID is 123, and pipeline ID which you want to investigate is 1234567, then:
py tracing.py 123 1234567
By default result is written to a file pipeline_trace_<PROJECT_ID>_<PIPELINE_ID>.json
:
Success: pipeline_trace_123_1234567.json
Load file in chrome://tracing/ or https://ui.perfetto.dev/
Then open chrome://tracing/ in your Chrome, and load generated json file. You can also use https://ui.perfetto.dev/
Use --out-file
parameter to output result to different file.
Use --to-stdout
switch to output result to standard output.
Jobs are coloured basing on chosen runner. Then you can see which runner picked the job and what other jobs the same runner was processing in the same time. Custom coloring functionality does not seem to be working on https://ui.perfetto.dev/ though.
Only started and finished jobs are added to a trace. If your job is not finished, it will be skipped and warning will be issued in standard error.