forkrun icon indicating copy to clipboard operation
forkrun copied to clipboard

add functions to get cpu usage from /proc/stat

Open jkool702 opened this issue 1 year ago • 1 comments

Summary by Sourcery

Add functions to measure and report CPU usage by reading from /proc/stat, enabling the recording and calculation of average CPU load over time.

New Features:

  • Introduce load_tic function to set the start time for recording the average CPU load.
  • Introduce load_toc function to print the average CPU load since load_tic was last run, outputting a value between 0 and 1,000,000 representing the average load across all logical CPU cores.

jkool702 avatar Aug 09 '24 07:08 jkool702

Reviewer's Guide by Sourcery

This pull request adds functions to measure and report CPU usage by reading from /proc/stat, enabling the recording and calculation of average CPU load over time. It also introduces dynamic worker coproc spawning based on CPU usage and read queue length, adds the ability to read input from a file descriptor other than stdin, and implements a custom bash loadable builtin for more efficient stdin reading on x86_64 platforms.

File-Level Changes

Change Details Files
Added functions to measure and report CPU usage
  • Introduced load_tic function to set the start time for recording average CPU load
  • Introduced load_toc function to print the average CPU load since load_tic was last run
  • Implemented _forkrun_get_load function to compute smoothed average system CPU load
forkrun.bash
Implemented dynamic worker coproc spawning based on CPU usage and read queue length
  • Modified -j
-P flag to accept negative numbers for dynamic coproc count
  • Added logic to spawn new worker coprocs based on CPU load and read queue length
  • Introduced pLOAD variable to represent current average load level estimate
  • Added ability to read input from a file descriptor other than stdin
    • Introduced -u flag to specify input file descriptor
    • Modified input reading logic to use specified file descriptor
    forkrun.bash
    Implemented custom bash loadable builtin for efficient stdin reading on x86_64 platforms
    • Added logic to use lseek for efficient stdin reading on x86_64 platforms
    • Removed dd from required dependencies list when using NULL-delimited input
    forkrun.bash
    Updated documentation and benchmarking scripts
    • Updated README.md with new version information and feature descriptions
    • Modified hyperfine_benchmark script to accommodate new features and improve testing
    README.md
    hyperfine_benchmark/forkrun.speedtest.hyperfine.bash
    Made minor API changes and improvements
    • Changed -u flag for unescaping to -U or --UNESCAPE
    • Improved error handling and default value setting
    • Added new command-line options to the help text
    forkrun.bash

    Tips
    • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
    • Continue your discussion with Sourcery by replying directly to review comments.
    • You can change your review settings at any time by accessing your dashboard:
      • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
      • Change the review language;
    • You can always contact us if you have any questions or feedback.

    sourcery-ai[bot] avatar Aug 09 '24 07:08 sourcery-ai[bot]

    @sourcery-ai review

    jkool702 avatar Sep 06 '24 18:09 jkool702

    @sourcery-ai can you combine the various "typo correction" edits you just suggested into a single commit?

    jkool702 avatar Sep 06 '24 19:09 jkool702

    I'm sorry, I don't understand the command @sourcery-ai can you combine the various "typo correction" edits you just suggested into a single commit?

    Please use @sourcery-ai review to request a review

    sourcery-ai[bot] avatar Sep 06 '24 19:09 sourcery-ai[bot]