I create my browser stats by feeding the output of a batch invocation of top into an awk program that rolls up all of the resources used by sub-processes to the main browser invocations. Secret sauce: I've tweaked which fields top displays, and I've toggled forest view ( capital "V"). The awk program has a lot of comments and sample data to explain how it works. Note: In the awk, I only do the rollup on specific programs, so I have to add the name of each new browser to the code.
If you want to try this on your own machine, first, replace your toprc with mine, this is much easier than me trying to explain how to make all of my changes via the top interface. Deploy this file to /home/pi/.config/procps/toprc (remember to save yours first!):**NOTE** THIS WILL CHANGE HOW TOP WORKS FROM THE COMMAND LINE TOO!
The changed columns aren't too annoying, but if you can't stand how the programs get sorted, toggle "forest view" back to the way it was, via typing a capital "V" in a running top. If you want this change to be permanent, type a capital "W" to write the configuration out. Of course, this breaks my stat process. You did back up your toprc, didn't you?
Second, put this awk program somewhere on your path as "sumtop", and make it executable:Run it all via this command:This run tops in batch mode, one time only, and sets the width wide enough that it outputs all of the columns.
Edit: its capital "V" to switch "forest view".
If you want to try this on your own machine, first, replace your toprc with mine, this is much easier than me trying to explain how to make all of my changes via the top interface. Deploy this file to /home/pi/.config/procps/toprc (remember to save yours first!):
Code:
top's Config File (Linux processes with windows)Id:k, Mode_altscr=0, Mode_irixps=1, Delay_time=3.0, Curwin=0Deffieldscur= 77 75 81 102 104 119 123 128 136 121 163 111 117 115 139 78 82 84 86 88 90 92 94 96 98 100 106 108 112 124 126 130 132 134 140 142 144 146 148 150 152 154 156 158 160 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 winflags=193846, sortindx=18, maxtasks=0, graph_cpus=0, graph_mems=0, double_up=0, combine_cpus=0, core_types=0summclr=1, msgsclr=1, headclr=3, taskclr=1Jobfieldscur= 75 77 115 111 117 80 103 105 137 119 123 128 120 79 139 82 84 86 88 90 92 94 96 98 100 106 108 112 124 126 130 132 134 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 winflags=193844, sortindx=0, maxtasks=0, graph_cpus=0, graph_mems=0, double_up=0, combine_cpus=0, core_types=0summclr=6, msgsclr=6, headclr=7, taskclr=6Memfieldscur= 75 117 119 120 123 125 127 129 131 154 132 156 135 136 102 104 111 139 76 78 80 82 84 86 88 90 92 94 96 98 100 106 108 112 114 140 142 144 146 148 150 152 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 winflags=193844, sortindx=21, maxtasks=0, graph_cpus=0, graph_mems=0, double_up=0, combine_cpus=0, core_types=0summclr=5, msgsclr=5, headclr=4, taskclr=5Usrfieldscur= 75 77 79 81 85 97 115 111 117 137 139 82 86 88 90 92 94 98 100 102 104 106 108 112 118 120 122 124 126 128 130 132 134 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 winflags=193844, sortindx=3, maxtasks=0, graph_cpus=0, graph_mems=0, double_up=0, combine_cpus=0, core_types=0summclr=3, msgsclr=3, headclr=2, taskclr=3Fixed_widest=0, Summ_mscale=1, Task_mscale=0, Zero_suppress=0, Tics_scaled=0The changed columns aren't too annoying, but if you can't stand how the programs get sorted, toggle "forest view" back to the way it was, via typing a capital "V" in a running top. If you want this change to be permanent, type a capital "W" to write the configuration out. Of course, this breaks my stat process. You did back up your toprc, didn't you?
Second, put this awk program somewhere on your path as "sumtop", and make it executable:
Code:
#!/usr/bin/awk -f# program to sum up the modified top output# to attribute all processes to each browser# top -bn1 -w200 | sumtop# requires the "V" (forest view) option to be on # as well as particular columns being on:# top - 11:06:20 up 48 min, 1 user, load average: 0.11, 0.22, 0.28# Tasks: 228 total, 1 running, 227 sleeping, 0 stopped, 0 zombie# %Cpu(s): 7.3 us, 15.6 sy, 0.0 ni, 77.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st# MiB Mem : 7811.5 total, 4214.7 free, 844.0 used, 2752.8 buff/cache# MiB Swap: 100.0 total, 100.0 free, 0.0 used. 6657.0 avail Mem # # PPID PID USER VIRT RES SWAP USED %CPU %MEM TIME+ COMMAND# 0 1 root 164964 10140 0 10140 0.0 0.1 0:03.55 systemd# 1 149 root 49244 17320 0 17320 0.0 0.2 0:01.36 `- systemd-journal# 1 169 root 22140 6580 0 6580 0.0 0.1 0:01.39 `- systemd-udevd# ...# 941 1045 pi 1111004 52740 0 52740 0.0 0.7 0:42.32 `- lxpanel# 1045 2830 pi 16.4g 179392 0 179392 0.0 2.2 0:24.47 `- chromium-browse# 2830 2857 pi 16.2g 57636 0 57636 0.0 0.7 0:00.09 `- chromium-browse# 2857 2886 pi 16.5g 116168 0 116168 0.0 1.5 0:12.31 `- chromium-browse# 2886 2996 pi 16.3g 23284 0 23284 0.0 0.3 0:00.00 `- chromium-browse# 2830 2860 pi 16.2g 57080 0 57080 0.0 0.7 0:00.09 `- chromium-browse# 2860 2862 pi 16.2g 15956 0 15956 0.0 0.2 0:00.03 `- chromium-browse# 2862 2896 pi 16.3g 45204 0 45204 0.0 0.6 0:00.27 `- chromium-browse# 2862 2950 pi 24.5g 104000 0 104000 0.0 1.3 0:06.58 `- chromium-browse# 2862 2985 pi 24.4g 108596 0 108596 0.0 1.4 0:02.96 `- chromium-browse# 2862 3781 pi 24.4g 60560 0 60560 0.0 0.8 0:00.13 `- chromium-browse# 2830 2887 pi 16.3g 84332 0 84332 0.0 1.1 0:01.78 `- chromium-browse# 1045 3083 pi 99036 14892 0 14892 0.0 0.2 0:00.57 `- dillo# 1045 3100 pi 2898200 279456 0 279456 0.0 3.5 1:00.68 `- firefox-esr# 3100 3172 pi 2390432 103228 0 103228 0.0 1.3 0:07.22 `- Web Content# 3100 3215 pi 2408440 107680 0 107680 0.0 1.3 0:04.41 `- WebExtensions# 3100 3273 pi 2383064 82236 0 82236 0.0 1.0 0:00.62 `- Web Content# 1045 3337 pi 82.4g 84520 0 84520 0.0 1.1 0:09.77 `- midori# 3337 3347 pi 98.6g 49000 0 49000 0.0 0.6 0:00.78 `- WebKitNetworkPr# 3337 3364 pi 98.4g 132516 0 132516 0.0 1.7 0:08.78 `- WebKitWebProces# 1045 3390 pi 416632 56116 0 56116 0.0 0.7 0:13.69 `- netsurf-gtk# 1045 3439 pi 83.3g 105828 0 105828 0.0 1.3 0:10.22 `- epiphany# 3439 3446 pi 82.7g 50392 0 50392 0.0 0.6 0:01.09 `- WebKitNetworkPr# 3439 3466 pi 3196 796 0 796 0.0 0.0 0:00.00 `- bwrap# 3466 3467 pi 3196 1260 0 1260 0.0 0.0 0:00.01 `- bwrap# 3467 3468 pi 156324 4752 0 4752 0.0 0.1 0:00.01 `- xdg-dbus-proxy# 3439 3470 pi 3196 784 0 784 0.0 0.0 0:00.01 `- bwrap# 3470 3471 pi 3328 1080 0 1080 0.0 0.0 0:00.02 `- bwrap# 3471 3473 pi 98.4g 89004 0 89004 0.0 1.1 0:05.39 `- WebKitWebProces# 1045 3845 pi 389684 41036 0 41036 4.8 0.5 0:18.53 `- lxterminal# 3845 3851 pi 7984 4712 0 4712 0.0 0.1 0:00.03 `- bash# 3851 3866 pi 7988 4780 0 4780 0.0 0.1 0:00.04 `- bash# 3866 3867 pi 5452 1652 0 1652 0.0 0.0 0:00.03 `- ssh-agent# 3866 4375 pi 17668 8952 0 8952 0.0 0.1 0:02.02 `- mc# 4375 4377 pi 7988 4824 0 4824 0.0 0.1 0:00.08 `- bash# 4377 9813 pi 9980 3476 0 3476 9.5 0.0 0:00.09 `- top# 4377 9814 pi 4940 484 0 484 0.0 0.0 0:00.00 `- tee# 4377 9815 pi 8376 3328 0 3328 0.0 0.0 0:00.01 `- sumtop2# 3845 9307 pi 7984 4720 0 4720 0.0 0.1 0:00.04 `- bash# 941 1046 pi 486476 63800 0 63800 0.0 0.8 0:05.09 `- pcmanfm# # PPID PID USER VIRT RES SWAP USED %CPU %MEM TIME+ COMMAND# 0 0 pi 218.7G 872.7M 0.0 872.7M 0.0 10.8 48.71 chromium-browse# 0 0 pi 101.4M 15.2M 0.0 15.2M 0.0 0.2 0.57 dillo# 0 0 pi 10.3G 586.3M 0.0 586.3M 0.0 7.1 72.93 firefox-esr# 0 0 pi 300.0G 272.4M 0.0 272.4M 0.0 3.4 19.33 midori# 0 0 pi 426.6M 57.5M 0.0 57.5M 0.0 0.7 13.69 netsurf-gtk# 0 0 pi 284.1G 260.0M 0.0 260.0M 0.0 3.1 16.75 epiphany# SIDEBAR: using the column utility to produce a tree-like report when V tree-view is off...# top -bn1 | awk '$1 ~ /^([0-9]|PPID)/' | column --tree-parent 1 --tree-id 2 --tree 11 | less{ position = index($0,$NF) }# break when lines stop being indented from parentposition <= parent_position{ write_and_clear_totals() }# if not currently in a desired block ...parent_position == 0 {if ( match($NF, /^(rpi-conXnectd|apache2|x-www-browser|chrome|bwrap|chromium(-browse)?|dillo|epiphany|firefox(-esr)?|lynx|midori|netsurf(-gtk)?|falkon|konqueror|surf|luakit|basilisk|min|qutebrowser|stress)$/) )parent_position = index($0,$NF) # first line of a block is the "parent" if ( parent_position > 0 ) {parent = $NF sum_line()}next}position > parent_position {if ( parent == "bwrap" && match($NF, /^(chrome|chromium(-browse)?|midori|netsurf(-gtk)?)$/ ) )parent = "\"" $NF "\"" sum_line()next}END { if ( parent_position ) write_and_clear_totals() }# process data lines by summing up columnsfunction sum_line() {sum4+=processgig($4)sum5+=processgig($5)sum6+=processgig($6)sum7+=processgig($7)sum8+=$8sum9+=$9sum10+=processtime($10)}# function write totals (and then clear them)function write_and_clear_totals() {if (!header) {header = 1printf(" %6s %6s %6s %6s %5s %5s %9s %s\n", "VIRT", "RES", "SWAP", "USED", "%CPU", "%MEM", "TIME+", "COMMAND")}if ( parent != "bwrap" )printf(" %6s %6s %6s %6s %5.1f %5.1f %9.2f %s\n", hr(sum4), hr(sum5), hr(sum6), hr(sum7), sum8, sum9, sum10, parent)sum4 = sum5 = sum6 = sum7 = sum8 = sum9 = sum10 = 0parent = ""parent_position = 0}# function process gigabytes# if input has a "g" appended - interpret as gibibytes# if input has no "g" appended - interpret as kibibytesfunction processgig(x, work) {if (match(x, /g$/)) {work = substr(x,1,length(x)-1)return work * 1024 * 1024 * 1024}elsereturn x * 1024}# function process time of the form "0:22.70"# which I think is M:SS.ss# convert to a real number of secondsfunction processtime(x, work) {split(x,work,/:/)return work[1] * 60.0 + work[2]}# function human_readable# convert numbers to human readable equivalents# decimal ones not binary !!!!!!!!!!!# 1 decimal placefunction hr(n, ix) {ix = 0while ( n>=1000 ) {ix++n/=1000}return (sprintf("%5.1f",n) substr(" kMGTPEZY",ix+1,1))}Code:
top -bn1 -w200 | sumtopEdit: its capital "V" to switch "forest view".
Statistics: Posted by tinker2much — Fri Feb 13, 2026 11:59 pm