Code Monkey home page Code Monkey logo

gnomon's Introduction

gnomon

A command line utility, a bit like moreutils's ts, to prepend timestamp information to the standard output of another command. Useful for long-running processes where you'd like a historical record of what's taking so long.

Example

basic

Piping anything to gnomon will prepend a timestamp to each line, indicating how long that line was the last line in the buffer--that is, how long it took the next line to appear. By default, gnomon will display the seconds elapsed between each line, but that is configurable.

You can display total time elapsed since the process began: total

You can display an absolute timestamp: absolute

You can also use the --high and/or --medium options to specify a length threshold in seconds, over which gnomon will highlight the timestamp in red or yellow. And you can do a few other things, too.

fancy

If the realtime timestamp updating is distracting or incompatible with your terminal, it can be disabled:

norealtime

Options

--type=<elapsed-line|elapsed-total|absolute>        [default: elapsed-line]
-t <elapsed-line|elapsed-total|absolute>

  Type of timestamp to display.
    elapsed-line: Number of seconds that displayed line was the last line.
    elapsed-total: Number of seconds since the start of the process.
    absolute: An absolute timestamp in UTC.

--format="format"                                   [default: "H:i:s.u O"]
-f "format"

  Format the absolute timestamp, using PHP date format strings. If the type
  is elapsed-line or elapsed-total, this option is ignored.

--ignore-blank                                      [default: false]
--quiet
-q
-i

  Do not prepend a timestamp to blank lines; just pass them through. When
  this option is active, blank lines will not trigger an update of elapsed
  time. Therefore, if a lot of blank lines appear, the prior timestamp will
  display the total time between that line and the next non-blank line
  (if the type is elapsed-time was selected).

--real-time=<number|false>                          [default: 500]
-r                                                  [non-tty default: false]

  Time increment to use when updating timestamp for the current line, in
  milliseconds. Pass `false` to this option to disable realtime entirely,
  if you need an extra performance boost or you find it distracting. When
  realtime is disabled, the log will always appear one line "behind" the
  original piped output, since it can't display the line until it's
  finished timing it.

--high=seconds
-h seconds

  High threshold. If the elapsed time for a line is equal to or higher than
  this value in seconds, then the timestamp will be colored bright red.
  This works for all timestamp types, including elapsed-total and absolute,
  where the elapsed line time is not actually displayed.

--medium=seconds
-m seconds

  Medium threshold. Works just like the high threshold described above, but
  colors the timestamp bright yellow instead. Can be used in conjunction
  with a high threshold for three levels.

Notes

  • If a high and/or a medium threshold are specified, then all timestamps not meeting that threshold will be colored bright green.
  • If you pipe the output of gnomon into another command or a file (that is, not a tty) then the real-time option will be disabled by default and each line will appear only after it has been timed. You can force realtime by sending a --real-time=<ms> argument explicitly, but the ANSI codes would probably interfere with whatever you were trying to do. The sane default is to omit fancy stuff, like colors and escape sequences, when logging text directly to a file.

Installation

with npm do:

npm install -g gnomon

License

gnomon uses the MIT license.

gnomon's People

Contributors

zetlen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gnomon's Issues

Question about --type absolute

When running w/ --type absolute, the time displayed by gnomon on line N is the time that line N+1 appeared.

Is this not confusing? E.g.,

» bash -c 'echo a && sleep 5 && echo b' | ./node_modules/gnomon/bin/gnomon -t absolute
19:46:25.000273 +0000   a
19:46:25.000276 +0000   b
19:46:25.000276 +0000

                Total   4.8277s

despite there being a 5s difference in the output times of a and b, gnomon's timestamps are nearly identical. (because of the above.)

No output on OS X when piping through grep

I have a use case which looks something like this:

run_program_with_verbose_output | grep StuffICareAbout | gnomon

When I run this with gnomon I get no output at all, but if I don't pipe through gnomon I get output. I was able to repro in the following way using two terminals:

  1. On terminal 1 run echo "test" > test.txt
  2. On terminal 2 run tail -f test.txt | grep asdf | gnomon
  3. On terminal 1 run echo "asdf" >> test.txt

Expected results: terminal 2 should show asdf with timing info
Observed results: no output at all in terminal 2

I'm running on OS X 10.12.6 in bash

Running grep asdf test.txt | gnomon works as expected, so it must have something to do with the pipes?

Maximum call stack size exceeded

I tried to use gnomon in combination with rg (ripgrep) as in: rg -i commonWord|gnomon, in order to find the commonWord inside a very large repository.

If there is a notSoCommonWord, it works without any issues.
If that commonWord is pretty common and there are too many results, apparently gnomon crashes with the following error:

var through = require('through');
                        ^
RangeError: Maximum call stack size exceeded
    at RegExp.[Symbol.replace] (native)
    at RegExp.[Symbol.replace] (native)
    at String.replace (native)
    at Chalk.module.exports [as stripColor] (/usr/local/lib/node_modules/gnomon/node_modules/strip-ansi/index.js:5:39)
    at stampLine (/usr/local/lib/node_modules/gnomon/index.js:81:28)
    at stampLine (/usr/local/lib/node_modules/gnomon/index.js:84:9)
    at stampLine (/usr/local/lib/node_modules/gnomon/index.js:84:9)
    at stampLine (/usr/local/lib/node_modules/gnomon/index.js:84:9)
    at stampLine (/usr/local/lib/node_modules/gnomon/index.js:84:9)
    at stampLine (/usr/local/lib/node_modules/gnomon/index.js:84:9)```

Hide Insignificant Times

It would be nice to have a flag that prevents the output of insignificant times.

Docs:

--low=seconds
-l seconds

  Lower threshold. Works just like quiet, but only hides timestamps that are
  lower than this value in seconds.

Example:

> ./test.sh | gnomon
   0.0072s █ Building javascript bundles...
   2.2550s █  * Bundling eiLib.js...
   4.2045s █  * Bundling qq.entry.js...
   0.0023s █ Done!
           █ 
     Total █ 6.4696s
> ./test.sh | gnomon --low=0.05
           █ Building javascript bundles...
   2.2550s █  * Bundling eiLib.js...
   4.2045s █  * Bundling qq.entry.js...
           █ Done!
           █ 
     Total █ 6.4696s

How to monitor output from `git clone` of large repository?

When I try gnomon with git clone, the output is not as expected.

git clone https://github.com/kubernetes/kubernetes.git | gnomon
   6.0172s   Cloning into 'kubernetes'...
remote: Enumerating objects: 219, done.
remote: Counting objects: 100% (219/219), done.
  35.0951s   Cloning into 'kubernetes'...8), done.
remote: Total 1072377 (delta 112), reused 91 (delta 91), pack-reused 1072158
  97.6902s   Cloning into 'kubernetes'..., 663.71 MiB | 24.69 MiB/s, done.
 112.3532s   Cloning into 'kubernetes'...one.
 112.6458s   Cloning into 'kubernetes'...one.
   0.0007s

     Total   112.6467s

The original output was

Cloning into 'kubernetes'...
remote: Enumerating objects: 219, done.
remote: Counting objects: 100% (219/219), done.
remote: Compressing objects: 100% (128/128), done.
remote: Total 1072377 (delta 112), reused 91 (delta 91), pack-reused 1072158
Receiving objects: 100% (1072377/1072377), 663.93 MiB | 24.68 MiB/s, done.
Resolving deltas: 100% (765877/765877), done.
Checking out files: 100% (21981/21981), done.

How do I configure to make it work with such output? I want to measure the time cost of each stage.

want to work correctly with \r or \b in right message

The following ruby script will output messages overwriting outputted messages in the same line.

------------------ test.rb ------------------

#!/usr/bin/env ruby
# encoding: utf-8
#

space = "                          "
print space

1.upto(30) { |x|
    print "[" + '*' * x + "]"
    sleep 0.2
    print "\b" * (x + 2)
}

puts

Execute

ruby test.rb 

will output like this

                      [****************]

and will dynamically become longer.

However, execute

ruby test.rb | gnomon --medium=1 --high=5 --real-time=100

will produce nothing but wait

Document large second inaccuracy

I think this could be related to the startup taking about 0.2 seconds on my machine, but it would be nice to have it documented, as this is often seen as an alternative to time(1).

$ (sleep 0.2; echo line) | gnomon   
   0.0227s   line
   0.0014s   
             
     Total   0.0253s
$ (sleep 0.2; echo line) | time cat
line
cat  0.00s user 0.00s system 0% cpu 0.202 total

Why is the duration next to "line" and in total so low? I am using version 1.5.0.

Echo Without Newline Causes Offset

echo -n seem to cause an off by one issue.

# test.sh

for x in {1,2,3}; do
  echo -n " * Sleeping ${x}s... "
  sleep $x
  echo "Done!"
done
jared@jared-slate:~/src/equity_web> ./test.sh | gnomon
   2.6452s    * Sleeping 1s... Done!
   3.0025s    * Sleeping 2s... Done!
   0.0046s    * Sleeping 3s... Done!
   0.0005s   
             
     Total   5.6534s

gnomon swallows errors

just an example during linting

without gnomon:

  cmd: 'npm run lint',
  timedOut: false,
  exitCode: 1 }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Exit status 1
npm ERR! 
...

Process finished with exit code 1

with gnomon:

  cmd: 'npm run lint',
  timedOut: false,
  exitCode: 1 }
   0.3374s   project: Lint errors found in the listed files.
             
     Total   37.5537s

Process finished with exit code 0

Send ANSI colors to non-tty output

Awesome tool!

It would be nice if there was an option to force ANSI colors to non-tty output. In particular, I'd like to use the tool like this:

command | gnomon --force-ansi --medium=1.0 | tee /tmp/log

I'm fine with having some ANSI jibberish in the log file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.