Score:0

Benchmark script performance against CPU/RAM consumption for different parameters

ke flag

I have an image processing shell script that can be provided with different sets of parameters that all produce a valid output for me. I'm trying to identity the set of parameters that has the lowest resources (CPU/RAM) usage as this script is going to run on the cloud. Are there any tools I can use to benchmark? I'm looking for something that would give me the total cpu cycles used by the script or any other relevant data/metric that I could compare.

OS: Ubuntu 20.04, Shell: BASH

Example of what I am looking for:

magical-benchmark-tool -c pdftoppm -png test.pdf test

Output

time (seconds)   processor cycles   max memory used (MB)    mean memory used (MB)
--------------   ----------------   --------------------    --------------------
19               1253               250                     128

Thank you!

John Mahowald avatar
cn flag
Please edit your question to add operating system, version, and which imaging processing library, if you want specific discussion on tools.
Score:0
us flag

You didn't specify which shell you use, so I'm going to assume Bash.


For CPU ustage you can use strace.

strace -c script.sh

For a simple Hello World script

#!/bin/bash
echo "Hello World"

Output

Hello World
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 17.70    0.000253          14        18           mmap
 11.69    0.000167          20         8           openat
  9.59    0.000137           9        14           rt_sigaction
  7.35    0.000105          13         8           fstat
  6.30    0.000090          15         6           mprotect
  5.60    0.000080          10         8           close
  5.32    0.000076          12         6           read
  5.11    0.000073          14         5           stat
  4.90    0.000070          70         1           execve
  3.50    0.000050          10         5           rt_sigprocmask
  2.59    0.000037          37         1           write
  2.24    0.000032          10         3           lseek
  2.24    0.000032          10         3           brk
  2.10    0.000030          10         3         2 ioctl
  1.89    0.000027           9         3         1 fcntl
  1.40    0.000020          20         1           munmap
  1.40    0.000020          20         1         1 access
  1.33    0.000019           9         2           getpid
  1.26    0.000018           9         2           prlimit64
  0.77    0.000011          11         1           dup2
  0.70    0.000010          10         1           sysinfo
  0.70    0.000010          10         1           getppid
  0.70    0.000010          10         1           arch_prctl
  0.63    0.000009           9         1           uname
  0.63    0.000009           9         1           getuid
  0.63    0.000009           9         1           getgid
  0.63    0.000009           9         1           getpgrp
  0.56    0.000008           8         1           geteuid
  0.56    0.000008           8         1           getegid
------ ----------- ----------- --------- --------- ----------------
100.00    0.001429                   108         4 total

For memory you can use top.
While runnig top press o and type e.g. COMMAND=bash to show entries from the COMMAND column that are equal to bash.

user728899 avatar
ke flag
Thanks! strace gives me what I want regarding CPU. Now I need to get some numbers regarding memory (max memory used, mean memory used during processing) from the command line.
p10l avatar
us flag
Like I said in my answer, you can use `top`. It's not perfect, but I'm not aware of any onther free solutions. Also, if you find my answer useful, consider [accepting and/or upvoting it](https://serverfault.com/help/someone-answers).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.