Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tasks): add --timings option for run command #1536

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

Ajpantuso
Copy link
Contributor

Summary

Closed #1265

Adds a --show-timings option to the mise run command to display elapsed time after each task.

Open Questions

  • Should timings be shown even after failure?
  • Should total time also be displayed after all tasks have run?
  • What style/format would look best for the new output?

@Ajpantuso Ajpantuso force-pushed the apantuso/timed_run branch 3 times, most recently from fcc8c3b to 9c17be8 Compare January 26, 2024 22:39
@jdx
Copy link
Owner

jdx commented Jan 26, 2024

let's just call it --timings—with a hidden alias --timing

@Ajpantuso Ajpantuso changed the title feat(tasks): add --show-timings option for run command feat(tasks): add --timings option for run command Jan 26, 2024
src/cmd.rs Outdated Show resolved Hide resolved
@Ajpantuso Ajpantuso marked this pull request as ready for review January 28, 2024 17:50
@roele
Copy link
Contributor

roele commented Jan 29, 2024

Since tasks might run in parallel the task prefix should probably be added to be able to tell which timing belongs to what task.
The current output does not make that clear.
Screenshot 2024-01-29 at 10 45 12

@Ajpantuso
Copy link
Contributor Author

@roele yeah I figured that would happen since we are streaming stdout/stderr; was just getting lucky on my test runs.

How would you feel about just adding a summary report of timings after all parallel execution?
I already added a metrics recorder for this purpose so there could eventually be structured output options. I guess prefixed output would be okay as well just think it may be hard to read with many tasks or lots of output.

@roele
Copy link
Contributor

roele commented Jan 29, 2024

Yes prefixed will help a little but with many tasks could still be hard to read. An overall summary at the end might be better. Maybe we can find some good examples from other tools.

Screenshot 2024-01-29 at 11 10 57

@Ajpantuso
Copy link
Contributor Author

@roele cool, added prefixes for now just so folks can review what it would look like. In parallel I'll play around with summary formats.

src/cli/run.rs Outdated Show resolved Hide resolved
@Ajpantuso
Copy link
Contributor Author

@roele I have a quick summary table implementation here if you wanted to review/refine it.

After looking at it I feel like hacking a table on to the default output doesn't look right. I think a --summarize or --summary option in the future would feel more natural. The default summary could just be a user-consumable table with no stdout/stderr from tasks while additional output options like ---output={json,yaml,...} could dump stdout/stderr from tasks into a structured format for processing by CI runners.

src/cli/run.rs Outdated Show resolved Hide resolved
src/cli/run.rs Outdated Show resolved Hide resolved
@@ -107,8 +108,15 @@ pub struct Run {
#[clap(long, short, verbatim_doc_comment)]
pub raw: bool,

/// Shows elapsed time after each task
#[clap(long, alias = "timing", verbatim_doc_comment)]
pub timings: bool,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after looking at this I am considering if maybe we just want to always display the timings. Not sure though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel in either case it should interfere less with the actual command output by maybe showing the entire line (after prefix) dimmed?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still undecided on this. I think I'm leaning towards always displaying though curious if you all have any thoughts.

Copy link
Owner

@jdx jdx Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm maybe not. Let's keep it optional for now, I think we should err on the side of less noise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the other choice is optional, but default to enabled. Seems reasonable however to just take user feedback and make a final decision before tasks are a GA feature.

@jdx
Copy link
Owner

jdx commented Jan 29, 2024

I might be not understanding this so much but I think this could be simplified by doing something like this:

fn run_all() {
  let start = time::Instant::now()
  for task in tasks {
    task.run();
  }
  println!("elapsed all: ...")
}

fn run_task() {
  let start = time::Instant::now()
  run()
  println!("elapsed: ...")
}

then we wouldn't need to modify anything outside of the cli command or use any mutexes or anything

@Ajpantuso
Copy link
Contributor Author

then we wouldn't need to modify anything outside of the cli command or use any mutexes or anything

Correct, the only reason to have Mutexes or Channels would be to capture summaries. If there is no appetite for having some kind of summary report I can drop this to the simplest implementation. Really just playing around with possibilities to scope this out.

@roele
Copy link
Contributor

roele commented Jan 29, 2024

After looking at it I feel like hacking a table on to the default output doesn't look right.

@Ajpantuso you're right it looks a bit odd. So i guess we should start small by refining the current inline approach.

@Ajpantuso Ajpantuso force-pushed the apantuso/timed_run branch 2 times, most recently from 8797e92 to 3f69d58 Compare January 29, 2024 18:51
@Ajpantuso
Copy link
Contributor Author

@jdx @roele I've reset this back to barebones incorporating some suggestions.

Making it so timings are always displayed would have some implications for testing so leaving the flag in for now.

src/cli/run.rs Outdated Show resolved Hide resolved
src/cli/run.rs Outdated
@@ -195,6 +201,11 @@ impl Run {
run(&task);
}
});

if self.timings {
miseprintln!("finished in {}", format_duration(timer.elapsed()));
Copy link
Owner

@jdx jdx Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's wrap this in style::edim() also we should only display it if there are >1 tasks. Lastly, let's put it on stderr. I could make a case for stderr or stdout but we're already using stderr for the task start message so I think stderr makes sense for this to match.

info_unprefix_trunc is what you'll want to use for this since that will respect the log level and hide the output under --quiet EDIT: we probably only want to do that if we make it non-optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, used info! so the dim mise prefix is added, but I think that makes sense.

@jdx jdx enabled auto-merge (squash) January 30, 2024 02:40
@jdx jdx merged commit 6a16dc0 into jdx:main Jan 30, 2024
7 checks passed
@Ajpantuso Ajpantuso deleted the apantuso/timed_run branch January 30, 2024 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tasks: show elapsed time of tasks
3 participants