How long has my Cylc task been running?

Hi there

I currently have a suite with the running tasks as listed in the attached screenshot.

What’s the easiest way of finding out how long each task has been running for?

Thanks!

Jonny

Hi,

The easiest option is probably to open the Cylc GUI in the “tree view” and sort by the start time. Doesn’t really give you the run time but does make it easy to pick out long running tasks.

Otherwise for more advanced analysis the information you need is in the database. This quick script will list all running tasks along with their calculated run time:

#!/bin/bash

echo 'task|cycle|run-time'

while IFS= read -r line; do
    if [[ -n "$line" ]]; then
        start_time="$(cut -d '|' -f 3 <<< "${line}")"
        run_time="$(isodatetime "${start_time}" now)"
        sed "s/${start_time}/${run_time}/" <<< "${line}"
    fi
done <<< $(sqlite3 \
    "${HOME}/cylc-run/generic/log/db" \
    'SELECT name, cycle, time_run FROM task_jobs WHERE time_run IS NOT NULL AND time_run_exit IS NULL')
1 Like

Thanks a lot for that! I put that in a script called howlongcylc and ran it but it hung (hence the control+c, ^C below). I got a permission denied error for some reason, even though I own it.

> ./howlongcylc
task|cycle|run-time

w-clim01.maui.niwa.co.nz|Mon Dec 09|21:17:29|scripts> ./howlongcylc: line 15: /home/williamsjh/cylc-run/u-bo721/log/db: Permission denied
^C
> ls -l /home/williamsjh/cylc-run/u-bo721/log/db
-rw-rw-r--+ 1 williamsjh niwa00013 983040 Dec  9 21:06 /home/williamsjh/cylc-run/u-bo721/log/db

Hi Jonny,

I wonder if you didn’t copy over the line continuation characters properly from Oliver’a script - are they in your script just as above and with no trailing whitespace? From your error message, it looks like you’re trying to execute the db file as if it were command (rather than pass it as an input parameter to the sqlite3 command as intended).

Hilary

1 Like

Ah, yup! Thanks Hilary.

I’m now getting this different error…

> ./howlongcylc
task|cycle|run-time
./howlongcylc: line 8: isodatetime: command not found
coupled|20060101T0000Z||20050101T0000Z|2019-12-10T09:39:26Z

Is isodatetime a different utility that I need to install or point to?

Thanks again

Jonny

The isodatetime command is quite recent so it might not be in your installation, however, it is really just the old rose date command which we rebranded and moved into isodatetime.

1 Like

OK awesome, thanks. It now works when I replace isodatetime with rose date. :smiley:

The script is on GitHub here.

One more thing though, if you look at the output below, what are the final entries in the lines? They seem to be random numbers?..

w-clim01.maui.niwa.co.nz|Wed Dec 11|23:09:11|scripts> howlongcylc
task|cycle|run-time
coupled|20080101T0000Z|PT7H27M21,0659780502S
w-clim01.maui.niwa.co.nz|Wed Dec 11|23:09:34|scripts> howlongcylc
task|cycle|run-time
coupled|20080101T0000Z|PT7H27M30,3806409836S
w-clim01.maui.niwa.co.nz|Wed Dec 11|23:09:43|scripts> howlongcylc
task|cycle|run-time
coupled|20080101T0000Z|PT7H28M33,6980140209S
w-clim01.maui.niwa.co.nz|Wed Dec 11|23:10:46|scripts> howlongcylc
task|cycle|run-time
coupled|20080101T0000Z|PT7H28M35,2833590508S
w-clim01.maui.niwa.co.nz|Wed Dec 11|23:10:48|scripts> howlongcylc
task|cycle|run-time
coupled|20080101T0000Z|PT7H29M50,6736791134S

Cheers

Jonny

If you mean the bit after the comma that’s the decimal second.

So in this example:

PT7H29M50,6736791134S

That’s a period of:

  • 7 hours
  • 29 minutes
  • 50.6736791134 seconds

I think you can change the output format to get rid of this unnecessary precision.

Hey Oliver

Thanks a lot for that. I wasn’t aware that that level of precision was even possible in these circumstances.

All the best

Jonny

I think the precision comes from the isodatetime now.

1 Like

OK awesome, thanks Oliver and Hilary too!

Jonny