How do I time a program executing in Windows? - windows

I want to be able to do the Windows equivalent of this Unix/Linux command:
time fooenter code here
foo
x cpu time
y real time
z wallclock time

timeit from the Windows Server 2003 Resource Kit should do the trick.

Related

Best way to track CPU% of one process over time

I want to print the cpu% of one running process every seconds in the terminal.
In addition to the cpu%, I would like to print the corresponding time stamps as well.
Example:
$
13:00:00 34,0%
13:00:01 35,2%
13:00:02 36,1%
What would be best approach for this?
Remark:
top -pid PID -s 1
Executing this command is close to what I want to achieve, except that:
It will update the output on one single line, and won't print new lines every second.
It will not print system time stamps.
I am using zsh shells in macOS.
Computer: MacBook Pro (16-inch, 2019)
Processor: 2,6 GHz 6-Core Intel Core i7
Memory: 16 GB 2667 MHz DDR4

Porting a Bash while loop to Python 2

I'm an intern porting a Linux Bash script to Python 2.6. This script basically powers an intranet dashboard that displays data about servers. It updates every minute, and is constantly running, pretty much 24/7.
I would like some help converting the below Bash line to Python:
(while sleep 30; do custom_cmd > tmp.txt; cp tmp.txt index.html; rm tmp.txt; done) &
I have confusion converting the '&', which I know turns the while loop into a background process. The while sleep 30 runs infinitely (as long as the user is active), and does work every 30 seconds (sleeping until then). I have already ported custom_cmd (which generates the html for the dashboard) to Python 2.6.
The Bash script is configured with "nohup", which I believe means the script will run even after the user logs out of the Linux machine.
That being said, how could I convert the above Bash line to Python, so that it runs as a background process, forever? Thank you very much.
The simple bash script can be written like this:
from subprocess import call, PIPE
from tempfile import SpooledTemporaryFile
from time import sleep
def myfunc():
while True:
sleep(30)
handle = SpooledTemporaryFile()
if call(['custom_cmd'], stdout=handle) == 0:
handle.seek(0)
open('index.html', 'w').write(handle.read())
handle.close()
You should then use the daemonize to daemonize the function.

What sleep command in Ubuntu do Hardwarewize?

Say I have a very simple script that does the
sleep 0.001
command in Ubuntu.
I want to know if this command effect the c state of the core or the package somehow. Does it force a c state on the hardware?
Thanks!
Code example:
/bin/sh
sleep 0.01
sleep 0.01
The sleep is purely software, the process executing it is not eligible for the CPU/cores during at least the specified time, but all your Ubuntu is not frozen and the CPU/cores are available for other processes. After if there is nothing to do during the sleep perhaps the CPU/cores save energy, but this is not directly required by the command sleep itself

Measure the shell script execution time in milliseconds on Mac OS

I was wondering if there is the way to get time in milliseconds from shell script on Mac OS.
I need it to time how much certain query runs.
Now I can only get the time in seconds:
Start=`date +%s`
End =`date +%s`
Time=$Start-$End
You could use the benchmarking-tool hyperfine (https://github.com/sharkdp/hyperfine).
It is more elaborate than time, by default runs your command multiple times and gives you mean runtime, deviation, min, and max.
Simple usage
hyperfine your_command
Result looks like this (result of hyperfine 'sleep 0.5'):
bash-3.2$ hyperfine 'sleep 0.5'
Benchmark #1: sleep 0.5
Time (mean ± σ): 505.6 ms ± 1.5 ms [User: 0.8 ms, System: 1.2 ms]
Range (min … max): 503.1 ms … 508.8 ms 10 runs
There is one caveat, the minimum number of runs is 2 (hyperfine -r 2 'your command').
Installation
Hyperfine can be installed via Homebrew:
brew install hyperfine
For more info see: https://github.com/sharkdp/hyperfine#on-macos
just use the 'time' command:
time something
something could be a shell, or a command (find, etc)
the "real" time is the total elapsed time you want, and includes milliseconds
Since Mac OS is BSD-like system, its date does not support the %N parameter you need.
You could though consider installing the GNU Core Utils.
It will allow you to get the time in the usual Linux way.
I suppose, the time something command will also output the result with milliseconds then.

How to check CPU Utilization of system calls used in a shell script while script is executing?

I Have a shell script which uses couple of system calls (grep,ps etc). I need to find CPU utilization for each system call used inside a script. I am using AIX unix version 5.1.Please help.
I have already tried Topas, vmstat , iostat commands, but they display overall cpu utilization of processes.
use below commnad
ps -aef | grep "process_name"
there would be a column 'C' in ouptut, which display cpu utilization for that process.
Thanks,
Gopal
I'm not sure if it's available on AIX, but on Linux the time command is what you would use
time wc /etc/hosts
9 26 235 /etc/hosts
real 0m0.075s
user 0m0.002s
sys 0m0.004s
sys is the amount of system call time, user is not system call time used by the process

Resources