Profiling of script commands

Hello, :wave:

I’m often interested in knowing how long individual lines in a script take to complete and end up with definitions like this one:

build-windows: &BUILD_WINDOWS
  stage: build
  needs: ["check"]
  <<: *OP_BUILD_RULES
  <<: *WINDOWS_DOCKER_RUNNER_TAG
  script:
    - bash -c "time make test"
    - bash -c "time make op"
    - bash -c "time make js-bootstrap"
    - bash -c "time make -C js/oph package"

This works fine but as you’d expect each result is shown in the logs with minimal decoration and require searching for the timing results.

It would be tremendous if there was a way to include the individual script items so they could be grouped, summarized, and collapsible in the logs individually. Visually it would be great if each command was available alongside the step_script results.

Is there a way to do this already? The grouping of stages is so very helpful for getting a quick overview of the time taken. Right now I search for the time results and it’s less fun than using the GitLab UI. :slightly_smiling_face:

Thank you in advance!

++dave;

There’s a Bash utility called ts which comes with moreutils in Debian-based distros that can do what you want. In a Ubuntu based image would use it like this:

stages:
    - build

build:
    before_script:
        - apt-get install moreutils
    script:
         - long_running_command | ts '[%Y-%m-%d %H:%M:%S]'

I’m not sure if that quite works for your use case, but perhaps it might get you a step closer.