0

Normally using grep would do the trick

sudo intel_gpu_top | grep xyz

But in this case intel_gpu_top is like htop and runs constantly.

How would i extract the needed information inside a bash script?

I want to get my average iGPU usage and it seems like this is the only tool that can do that. While there is an option to output the results into a file, sudo intel_gpu_top -o file.txt it is rather weirdly made, it has different statistics and it doesnt override the old result manually but rather adds more to the file making it difficult to read the information needed from that file (atleast for a bash noobie like me)

EDIT:

Here is the output from sudo intel_gpu_top -o test.txt

Freq MHz      IRQ RC6 Power     IMC MiB/s           RCS/0           BCS/0           VCS/0          VECS/0
 req  act       /s   %     W     rd     wr       %  se  wa       %  se  wa       %  se  wa       %  se  wa
   0    0        0   0  0.00    170     48    0.00   0   0    0.00   0   0    0.00   0   0    0.00   0   0
   6    6       12  99  0.01    545    134    0.81   0   0    0.00   0   0    0.00   0   0    0.00   0   0
   9    9       14  98  0.01    411     78    1.14   0   0    0.00   0   0    0.00   0   0    0.00   0   0
   5    5       10  99  0.01    436     74    0.72   0   0    0.00   0   0    0.00   0   0    0.00   0   0
  12   12       21  98  0.01    431    100    0.76   0   0    0.00   0   0    0.00   0   0    0.00   0   0
   3    3        8 100  0.00    391     52    0.16   0   0    0.00   0   0    0.00   0   0    0.00   0   0

and here from the sudo intel_gpu_top, dont forget that this will display like htop or top

intel-gpu-top -    9/   9 MHz;   98% RC6;  0.02 Watts;       17 irqs/s

      IMC reads:      732 MiB/s
     IMC writes:      247 MiB/s

          ENGINE      BUSY                                                                                             MI_SEMA MI_WAIT
     Render/3D/0    1.65% |█▍                                                                                        |      0%      0%
       Blitter/0    0.00% |                                                                                          |      0%      0%
         Video/0    0.00% |                                                                                          |      0%      0%
  VideoEnhance/0    0.00% |                                                                                          |      0%      0%

Im interrested in the Render/3D/0, Blitter/0, Video/0 and VideoEnhance/0 values. I have actually no idea how both outputs are relative to each other but yeah, if you are getting an idea please let me know.

EDIT: EDIT: it would be nice to get the results every "tick" i think its every second the sudo intel_gpu_top updates itself but i could be wrong

1
  • @Cbhihe I've added it, sorry that i didnt include it in the first place, totally forgot about that!
    – Crylia
    Commented Jul 5, 2021 at 22:17

1 Answer 1

2

I am not familiar with that GPU version of top, but judging from the provided output, it looks like sudo intel_gpu_top captures some of the output of sudo intel_gpu_top -o outfile.

The one to one correspondence seems to be:

  • Render/3D/0 <>RCS/0 % value
  • Blitter/0 <> BCS/0 % value
  • Video/0 <> VCS/0 % value
  • VideoEnhance/0 <> VECS/0 % value

Using info garnered from GeorgeUdosen's answer on this site, borrowed from that answer on SO, and correctly attributed to F.X.:

  • the "Render" (space) seems to be about space usage for regular 3D operations.
  • the "Blitter" (engine) seems responsible for hardware acceleration of 2D operations (blitting).
  • "Video Command Streamer (VCS)":

The VCS unit primarily serves as a software programming interface between the OS-driver and the Multi-Format-Decoder (MFD) engine [...] (fetching, decoding and dispatching data packets).

see this for more info

  • "Video Enhance Command Streamer (VECS)": This command streamer unit is an addition/enhancement to VCS in that it

allows offloading of video post processing to another new component, VEBOX. The VEBOX engine is used for the hardware-based video post processing with supported user-space code.

To get your values at regular update intervals, try:

$ sudo intel_gpu_top -o - \
       | awk 'BEGIN {print "\tRender/3D/0 (%)","Blitter/0 (%)","Video/0 (%)","VideoEnhance/0 (%)\n"} 
              NR>=3 {printf "\t%11s%14s%12s%%19s\n" $4,$7,$10,$13}'

Edit: I respond here to OP's author's request to limit the output to 1, i.e. to not use intel_gpu_top the way it's designed, that is to display its updated output at regular intervals:

To do so you can transform the above one-liner to:

timeout 1s sudo intel_gpu_top -s 1 -o - \
       | awk 'BEGIN {print "\tRender/3D/0 (%)","Blitter/0 (%)","Video/0 (%)","VideoEnhance/0 (%)\n"} 
              NR>=3 {printf "\t%11s%14s%12s%%19s\n" $4,$7,$10,$13}'
  • timeout 1s: permits the subsequent command to time-out after one second (1s)
  • the intel_gpu_top flag and parameter -s 1 disposes that output occurs once per second.
8
  • Thanks this is pretty much what i need! But how can i make the command only output once?
    – Crylia
    Commented Jul 6, 2021 at 19:28
  • 1
    Hi @Crylia: I thought you wanted the output from the command to be updated "at every "tick" as you put it . You wrote: "EDIT: EDIT: it would be nice to get the results every "tick". Is not that so ?
    – Cbhihe
    Commented Jul 6, 2021 at 21:23
  • Yes, but i meant inside a script. I might've mixed up some wordings, my bad. I've only picked up bash scripting a few days ago. This command needs to run inside a xyz.sh file that will be called by polybar every x seconds, hence the "it would be nice to get the results every "tick"". At this point i only need those four outputs saved as a variable and the rest should be easily done by myself. I'm just having a hard time using awk, sed like patterns or stringing multiple commands together. Again, my bad.
    – Crylia
    Commented Jul 6, 2021 at 23:49
  • When i try to execute the command inside a script it does not timeout and is stuck. Also the option -s 1 gives me a weird result with hundrets or lines peeing printed in one second. gpu=$(timeout 1s sudo intel_gpu_top -o - | awk 'NR>=3{printf "\t%11s%14s%12s%\n" $8,$11,$14,$17}') this is how i currently have it, it stripped away some formating stuff btw
    – Crylia
    Commented Jul 8, 2021 at 0:19
  • Ok,sorry about this @Crylia, but i am really working in the dark on this one, since i cannot run test on my side. How about: gpu=( $(timeout 1s sudo intel_gpu_top -o - | awk 'NR>=3{print $8,$11,$14,$17}') ). Then you can use gpu as you would any Bash array ...
    – Cbhihe
    Commented Jul 8, 2021 at 5:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.