├── atop.spec ├── atop.default ├── atop.cronsysv ├── .gitignore ├── atop-rotate.timer ├── version.h ├── atop-rotate.service ├── atop-pm.sh ├── atopgpu.service ├── atop.rc.openrc ├── mkdate ├── atopacct.service ├── AUTHORS ├── version.c ├── atop.service ├── atopacct.rc.openrc ├── man ├── atophide.1 ├── atopconvert.1 ├── atopcat.1 ├── atopgpud.8 └── atopacctd.8 ├── 45atoppm ├── json.h ├── parseable.h ├── prev ├── netstats_wrong.h ├── cgroups_211.h ├── cgroups_212.h ├── photoproc_200.h ├── photoproc_201.h ├── photoproc_202.h ├── photoproc_203.h ├── photoproc_204.h ├── photoproc_205.h ├── photoproc_206.h ├── photoproc_207.h ├── photoproc_211.h ├── photoproc_212.h ├── photoproc_208.h ├── photoproc_209.h ├── photoproc_210.h ├── photosyst_200.h └── photosyst_201.h ├── atop.init ├── atop.daily ├── gpucom.h ├── ifprop.h ├── netatopd.h ├── atopacct.init ├── atopacctd.h ├── netatop.h ├── README ├── rpmspec ├── atop.specsysv └── atop.specsystemd ├── cgroups.h ├── README.md ├── rawlog.h ├── netstats.h ├── netatopbpfif.c ├── acctproc.h ├── utsnames.c ├── netlink.c ├── atop.h ├── photoproc.h ├── showgeneric.h ├── procdbase.c └── Makefile /atop.spec: -------------------------------------------------------------------------------- 1 | rpmspec/atop.specsystemd -------------------------------------------------------------------------------- /atop.default: -------------------------------------------------------------------------------- 1 | LOGOPTS="" 2 | LOGINTERVAL=600 3 | LOGGENERATIONS=28 4 | LOGPATH=/var/log/atop 5 | -------------------------------------------------------------------------------- /atop.cronsysv: -------------------------------------------------------------------------------- 1 | # daily restart of atop at midnight 2 | 0 0 * * * root /usr/share/atop/atop.daily& 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | atop 3 | atopsar 4 | atopacctd 5 | atopcat 6 | atopconvert 7 | atophide 8 | versdate.h 9 | mkdistr 10 | rpmbuilder 11 | -------------------------------------------------------------------------------- /atop-rotate.timer: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Daily atop restart 3 | Documentation=man:atop(1) 4 | 5 | [Timer] 6 | OnCalendar=daily 7 | 8 | [Install] 9 | WantedBy=timers.target 10 | -------------------------------------------------------------------------------- /version.h: -------------------------------------------------------------------------------- 1 | #ifndef __ATOP_VERSION__ 2 | #define __ATOP_VERSION__ 3 | 4 | #define ATOPVERS "2.12.0" 5 | 6 | char *getstrvers(void); 7 | unsigned short getnumvers(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /atop-rotate.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Restart atop daemon to rotate logs 3 | Documentation=man:atop(1) 4 | 5 | [Service] 6 | Type=oneshot 7 | ExecStart=/usr/bin/systemctl restart atop.service 8 | -------------------------------------------------------------------------------- /atop-pm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case "$1" in 4 | pre) /usr/bin/systemctl stop atop 5 | exit 0 6 | ;; 7 | post) /usr/bin/systemctl start atop 8 | exit 0 9 | ;; 10 | *) exit 1 11 | ;; 12 | esac 13 | -------------------------------------------------------------------------------- /atopgpu.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Atop GPU stats daemon 3 | Documentation=man:atopgpud(8) 4 | Before=atop.service 5 | 6 | [Service] 7 | ExecStart=/usr/sbin/atopgpud 8 | Type=oneshot 9 | RemainAfterExit=yes 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /atop.rc.openrc: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | # Copyright 1999-2021 Gentoo Authors 3 | # Distributed under the terms of the GNU General Public License v2 4 | 5 | description="Resource-specific view of processes" 6 | pidfile="/var/run/atop.pid" 7 | command="/usr/share/atop/atop.daily" 8 | command_background="true" 9 | -------------------------------------------------------------------------------- /mkdate: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Make a new versdate.h with the current date filled 4 | # 5 | CURDATE=$(date +%Y/%m/%d\ %H:%M:%S) 6 | 7 | echo "#ifndef __ATOP_VERSDATA__" > versdate.h 8 | echo "#define __ATOP_VERSDATA__" >> versdate.h 9 | echo "#define ATOPDATE \"$CURDATE\"" >> versdate.h 10 | echo "#endif" >> versdate.h 11 | -------------------------------------------------------------------------------- /atopacct.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Atop process accounting daemon 3 | Documentation=man:atopacctd(8) 4 | Before=atop.service 5 | 6 | [Service] 7 | Type=forking 8 | PIDFile=/run/atopacctd.pid 9 | ExecStartPre=/bin/sh -c 'if systemctl -q is-active acct psacct; then echo "Process accounting already in use by (ps)acct"; exit 1; fi' 10 | ExecStart=/usr/sbin/atopacctd 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Created and maintained by: 2 | Gerlof Langeveld 3 | 4 | Contributions by: 5 | Jan-Christiaan van Winkel 6 | Zhenwei Pi 7 | Fei Li 8 | Nathan Scott 9 | rpungartnik (Roberto) 10 | Vincent Lefèvre 11 | Hunter1016 12 | Fabrice Fontaine 13 | Georgiy Komarov 14 | gleventhal 15 | SjonHortensius 16 | sylmarch (Sylvian) 17 | 0pointerexception (Wilko) 18 | 7h3w1zz (Jacob) 19 | Sam James 20 | Peter Wang 21 | Meinhard Zhou 22 | Zachary P. Landau 23 | Daniel Brooks 24 | Ike Devolder 25 | codebling 26 | Justin Kromlinger 27 | Alastair Young 28 | roadrunner2 29 | liutingjieni 30 | Algebra970 31 | Donatas Abraitis 32 | Marc Haber 33 | -------------------------------------------------------------------------------- /version.c: -------------------------------------------------------------------------------- 1 | /* No manual changes in this file */ 2 | #include 3 | #include 4 | #include "version.h" 5 | #include "versdate.h" 6 | 7 | static char atopversion[] = ATOPVERS; 8 | static char atopdate[] = ATOPDATE; 9 | 10 | char * 11 | getstrvers(void) 12 | { 13 | static char vers[256]; 14 | 15 | snprintf(vers, sizeof vers, 16 | "Version: %s - %s ", 17 | atopversion, atopdate); 18 | 19 | return vers; 20 | } 21 | 22 | unsigned short 23 | getnumvers(void) 24 | { 25 | int vers1, vers2; 26 | 27 | sscanf(atopversion, "%u.%u", &vers1, &vers2); 28 | 29 | return (unsigned short) ((vers1 << 8) + vers2); 30 | } 31 | -------------------------------------------------------------------------------- /atop.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Atop advanced performance monitor 3 | Documentation=man:atop(1) 4 | 5 | [Service] 6 | Type=simple 7 | Environment="LOGOPTS=" 8 | Environment="LOGINTERVAL=600" 9 | Environment="LOGGENERATIONS=28" 10 | Environment="LOGPATH=/var/log/atop" 11 | EnvironmentFile=/etc/default/atop 12 | ExecStartPre=/bin/sh -c 'test -d "${LOGPATH}" || mkdir -p "${LOGPATH}"' 13 | ExecStartPre=/bin/sh -c 'test -n "$LOGINTERVAL" -a "$LOGINTERVAL" -eq "$LOGINTERVAL"' 14 | ExecStartPre=/bin/sh -c 'test -n "$LOGGENERATIONS" -a "$LOGGENERATIONS" -eq "$LOGGENERATIONS"' 15 | ExecStart=/bin/sh -c 'exec /usr/bin/atop ${LOGOPTS} -w "${LOGPATH}/atop_$(date +%%Y%%m%%d)" ${LOGINTERVAL}' 16 | ExecStartPost=/usr/bin/find "${LOGPATH}" -name "atop_*" -mtime +${LOGGENERATIONS} -exec rm -v {} \; 17 | KillSignal=SIGUSR2 18 | 19 | [Install] 20 | WantedBy=multi-user.target 21 | -------------------------------------------------------------------------------- /atopacct.rc.openrc: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | # Copyright 1999-2021 Gentoo Authors 3 | # Distributed under the terms of the GNU General Public License v2 4 | 5 | description="Resource-specific view of processes" 6 | command="/usr/sbin/atopacctd" 7 | lockfile="/var/lock/subsys/atopacctd" 8 | 9 | start_pre() { 10 | # Check if process accounting already in use via psacct 11 | for PACCTFILE in /var/account/pacct /var/log/pacct ; do 12 | if [ -f "${PACCTFILE}" ] ; then 13 | BEFORSIZE=$(stat -c %s "${PACCTFILE}") 14 | AFTERSIZE=$(stat -c %s "${PACCTFILE}") 15 | 16 | # verify if accounting file grows, so is in use 17 | if [ ${BEFORSIZE} -lt ${AFTERSIZE} ] ; then 18 | ewarn "Process accounting already used by psacct!" 19 | return 1 20 | fi 21 | fi 22 | done 23 | 24 | checkpath -d -q ${lockfile%/*} || return 1 25 | } 26 | 27 | start() { 28 | ebegin "Starting atopacctd" 29 | start-stop-daemon --start --exec ${command} 30 | touch ${lockfile} 31 | eend $? 32 | } 33 | 34 | stop() { 35 | ebegin "Stopping atopacctd" 36 | start-stop-daemon --stop --exec ${command} 37 | rm ${lockfile} 38 | eend $? 39 | } 40 | -------------------------------------------------------------------------------- /man/atophide.1: -------------------------------------------------------------------------------- 1 | .TH ATOPHIDE 1 "January 2024" "Linux" 2 | .SH NAME 3 | .B atophide 4 | - partly copy raw log file and/or anonymize raw log 5 | .SH SYNOPSIS 6 | .P 7 | .B atophide 8 | [-a] 9 | [\-b 10 | .I YYYYMMDDhhmm 11 | ] 12 | [\-e 13 | .I YYYYMMDDhhmm 14 | ] rawinput rawoutput 15 | .P 16 | .SH DESCRIPTION 17 | The program 18 | .I atophide 19 | can be used to make an extraction from an input raw log to an output raw log, 20 | specifying a begin time with the 21 | .B -b 22 | and/or an end time with the 23 | .B -e 24 | flag. 25 | 26 | With the 27 | .B -a 28 | flag the output rawlog will be anonymized: 29 | .PP 30 | .TP 5 31 | .B Host name 32 | The host name in the header line will be replaced by 'anonymized'. 33 | .PP 34 | .TP 5 35 | .B Command names 36 | Command names will be replaced by place holders, except the names of 37 | the standard commands and the names of kernel processes. 38 | .PP 39 | .TP 5 40 | .B Command arguments 41 | The command line arguments of 42 | .I all 43 | commands will be wiped. 44 | .PP 45 | .TP 5 46 | .B Logical volumes 47 | Logical volume names will be replaced by place holders. 48 | .PP 49 | .TP 5 50 | .B NFS shares 51 | NFS mounted shared volume names will be replaced by place holders. 52 | .SH SEE ALSO 53 | .B atop(1), 54 | .B atopsar(1), 55 | .B atopcat(1), 56 | .B atopconvert(1) 57 | .br 58 | .B https://www.atoptool.nl 59 | .SH AUTHOR 60 | Gerlof Langeveld (gerlof.langeveld@atoptool.nl) 61 | -------------------------------------------------------------------------------- /45atoppm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . "${PM_FUNCTIONS}" 4 | 5 | LOGPATH=/var/log/atop 6 | BINPATH=/usr/bin 7 | PIDFILE=/var/run/atop.pid 8 | INTERVAL=600 # interval 10 minutes 9 | CURDAY=`date +%Y%m%d` # current date in same format 10 | 11 | # If the system suspends, one final sample will be taken for the logfile 12 | # 13 | suspend_atop() 14 | { 15 | if [ -e $PIDFILE ] && ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null 16 | then 17 | kill -USR2 `cat $PIDFILE` # final sample and terminate 18 | 19 | CNT=0 20 | 21 | while ps -p `cat $PIDFILE` > /dev/null 22 | do 23 | let CNT+=1 24 | 25 | if [ $CNT -gt 5 ] 26 | then 27 | break; 28 | fi 29 | 30 | sleep 1 31 | done 32 | fi 33 | } 34 | 35 | # If the system resumes, a new atop will be started (similar to boot) 36 | # 37 | resume_atop() 38 | { 39 | # in case atop is running, stop it 40 | # 41 | if [ -e $PIDFILE ] && ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null 42 | then 43 | kill -TERM `cat $PIDFILE` 44 | rm $PIDFILE 45 | sleep 1 46 | fi 47 | 48 | # start atop 49 | # 50 | $BINPATH/atop -R -w $LOGPATH/atop_$CURDAY $INTERVAL \ 51 | > $LOGPATH/daily.log 2>&1 & 52 | echo $! > $PIDFILE 53 | 54 | # delete logfiles older than four weeks 55 | # 56 | ( 57 | sleep 3; 58 | find $LOGPATH -name 'atop_*' -mtime +28 -exec rm {} \; 59 | )& 60 | 61 | exit 0 62 | } 63 | 64 | case "$1" in 65 | hibernate|suspend) 66 | suspend_atop 67 | ;; 68 | thaw|resume) 69 | resume_atop 70 | ;; 71 | *) exit $NA 72 | ;; 73 | esac 74 | -------------------------------------------------------------------------------- /json.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** ========================================================================== 7 | ** Author: Fei Li & zhenwei pi 8 | ** E-mail: lifei.shirley@bytedance.com, pizhenwei@bytedance.com 9 | ** Date: August 2019 10 | ** -------------------------------------------------------------------------- 11 | ** Copyright (C) Copyright (C) 2019-2022 bytedance.com 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | ** 23 | ** You should have received a copy of the GNU General Public License 24 | ** along with this program; if not, write to the Free Software 25 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | ** -------------------------------------------------------------------------- 27 | */ 28 | int jsondef(char *); 29 | char jsonout(time_t, int, 30 | struct devtstat *, struct sstat *, 31 | struct cgchainer *, int, int, 32 | int, unsigned int, char); 33 | -------------------------------------------------------------------------------- /parseable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** ========================================================================== 7 | ** Author: Gerlof Langeveld 8 | ** E-mail: gerlof.langeveld@atoptool.nl 9 | ** Date: September 2002 10 | ** -------------------------------------------------------------------------- 11 | ** Copyright (C) 2000-2010 Gerlof Langeveld 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | ** 23 | ** You should have received a copy of the GNU General Public License 24 | ** along with this program; if not, write to the Free Software 25 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | ** -------------------------------------------------------------------------- 27 | */ 28 | #ifndef __PARSEABLE__ 29 | #define __PARSEABLE__ 30 | 31 | int parsedef(char *); 32 | char parseout(time_t, int, 33 | struct devtstat *, struct sstat *, 34 | struct cgchainer *, int, int, 35 | int, unsigned int, char); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /man/atopconvert.1: -------------------------------------------------------------------------------- 1 | .TH ATOPCONVERT 1 "January 2024" "Linux" 2 | .SH NAME 3 | .B atopconvert 4 | - convert raw log file to newer version 5 | .SH SYNOPSIS 6 | .P 7 | .B atopconvert 8 | [\-t 9 | .I version 10 | ] rawinput [rawoutput] 11 | .P 12 | .SH DESCRIPTION 13 | The program 14 | .I atopconvert 15 | can be used to convert the layout of a raw log file to a newer version. 16 | The only mandatory argument is the name of the raw input file. When no 17 | output file is specified on the command line, 18 | .I atopconvert 19 | only shows the version of the input file. 20 | When the name of an output file is specified, the input file will 21 | be converted to the output file, or just copied when the input file 22 | already has the required version. 23 | 24 | The program 25 | .I atopconvert 26 | converts the input file (by default) to the format used by the 27 | newest version of 28 | .I atop 29 | and writes to the output file. With the 30 | .B -t 31 | option, an alternative target version can be specified for the output file 32 | (instead of the newest version) in the format 33 | .I major.minor 34 | (example: 2.3). 35 | .br 36 | After the conversion is finished, the output file can be read by 37 | the newer version of 38 | .I atop 39 | or can even be extended by that 40 | .I atop 41 | version. 42 | .SH NOTES 43 | The raw input file should be at least of version 2.0! 44 | 45 | Files can only be upgraded to higher version, but not downgraded. 46 | .SH SEE ALSO 47 | .B atop(1), 48 | .B atopsar(1), 49 | .B atopcat(1), 50 | .B atophide(1) 51 | .br 52 | .B https://www.atoptool.nl 53 | .SH AUTHOR 54 | Gerlof Langeveld (gerlof.langeveld@atoptool.nl) 55 | -------------------------------------------------------------------------------- /prev/netstats_wrong.h: -------------------------------------------------------------------------------- 1 | struct tcp_stats_without_InCsumErrors { 2 | count_t RtoAlgorithm; 3 | count_t RtoMin; 4 | count_t RtoMax; 5 | count_t MaxConn; 6 | count_t ActiveOpens; 7 | count_t PassiveOpens; 8 | count_t AttemptFails; 9 | count_t EstabResets; 10 | count_t CurrEstab; 11 | count_t InSegs; 12 | count_t OutSegs; 13 | count_t RetransSegs; 14 | count_t InErrs; 15 | count_t OutRsts; 16 | }; 17 | 18 | struct icmpv4_stats_without_InCsumErrors { 19 | count_t InMsgs; 20 | count_t InErrors; 21 | count_t InDestUnreachs; 22 | count_t InTimeExcds; 23 | count_t InParmProbs; 24 | count_t InSrcQuenchs; 25 | count_t InRedirects; 26 | count_t InEchos; 27 | count_t InEchoReps; 28 | count_t InTimestamps; 29 | count_t InTimestampReps; 30 | count_t InAddrMasks; 31 | count_t InAddrMaskReps; 32 | count_t OutMsgs; 33 | count_t OutErrors; 34 | count_t OutDestUnreachs; 35 | count_t OutTimeExcds; 36 | count_t OutParmProbs; 37 | count_t OutSrcQuenchs; 38 | count_t OutRedirects; 39 | count_t OutEchos; 40 | count_t OutEchoReps; 41 | count_t OutTimestamps; 42 | count_t OutTimestampReps; 43 | count_t OutAddrMasks; 44 | count_t OutAddrMaskReps; 45 | }; 46 | 47 | struct netstat_wrong { 48 | struct ipv4_stats ipv4; 49 | struct icmpv4_stats_without_InCsumErrors icmpv4; 50 | struct udpv4_stats udpv4; 51 | 52 | struct ipv6_stats ipv6; 53 | struct icmpv6_stats icmpv6; 54 | struct udpv6_stats udpv6; 55 | 56 | struct tcp_stats_without_InCsumErrors tcp; 57 | }; 58 | 59 | -------------------------------------------------------------------------------- /atop.init: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # atop Startup script for the Atop process logging in background 4 | # 5 | # chkconfig: 2345 96 4 6 | # description: Advanced system and process activity monitor 7 | # 8 | ### BEGIN INIT INFO 9 | # Provides: atop 10 | # Required-Start: $local_fs $remote_fs 11 | # Required-Stop: $local_fs $remote_fs 12 | # Default-Start: 2 3 4 5 13 | # Default-Stop: 0 1 6 14 | # Short-Description: Advanced system and process activity monitor 15 | # Description: Advanced system and process activity monitor 16 | ### END INIT INFO 17 | 18 | # Check existance of binaries 19 | [ -f /usr/bin/atop ] || exit 0 20 | 21 | PIDFILE=/var/run/atop.pid 22 | RETVAL=0 23 | 24 | # See how we were called. 25 | case "$1" in 26 | start) 27 | # Check if atop runs already 28 | # 29 | if [ -e $PIDFILE ] && ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null 30 | then 31 | : 32 | else 33 | # Start atop 34 | /usr/share/atop/atop.daily& 35 | fi 36 | touch /var/lock/subsys/atop 37 | ;; 38 | 39 | stop) 40 | # Check if atop runs 41 | # 42 | if [ -e $PIDFILE ] && ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null 43 | then 44 | kill -USR2 `cat $PIDFILE` # final sample and terminate 45 | 46 | CNT=0 47 | 48 | while ps -p `cat $PIDFILE` > /dev/null 49 | do 50 | CNT=$((CNT + 1)) 51 | 52 | if [ $CNT -gt 5 ] 53 | then 54 | break; 55 | fi 56 | 57 | sleep 1 58 | done 59 | 60 | rm $PIDFILE 61 | fi 62 | rm -f /var/lock/subsys/atop 63 | ;; 64 | 65 | status) 66 | ;; 67 | 68 | reload) 69 | /usr/share/atop/atop.daily& 70 | ;; 71 | 72 | restart) 73 | /usr/share/atop/atop.daily& 74 | ;; 75 | 76 | *) 77 | echo "Usage: $0 [start|stop|status|reload|restart]" 78 | exit 1 79 | esac 80 | 81 | exit $RETVAL 82 | -------------------------------------------------------------------------------- /atop.daily: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | LOGOPTS="" # default options 4 | LOGINTERVAL=600 # default interval in seconds 5 | LOGGENERATIONS=28 # default number of days 6 | LOGPATH=/var/log/atop # default log location 7 | 8 | mkdir -p "$LOGPATH" 9 | 10 | # allow administrator to overrule the variables 11 | # defined above 12 | # 13 | DEFAULTSFILE=/etc/default/atop # possibility to overrule vars 14 | 15 | if [ -e "$DEFAULTSFILE" ] 16 | then 17 | . "$DEFAULTSFILE" 18 | 19 | # validate overruled variables 20 | # (LOGOPTS and LOGINTERVAL are implicitly by atop) 21 | # 22 | case "$LOGGENERATIONS" in 23 | ''|*[!0-9]*) 24 | echo non-numerical value for LOGGENERATIONS >&2 25 | exit 1;; 26 | esac 27 | fi 28 | 29 | CURDAY=`date +%Y%m%d` 30 | BINPATH=/usr/bin 31 | PIDFILE=/var/run/atop.pid 32 | 33 | # verify if atop still runs for daily logging 34 | # 35 | if [ -e "$PIDFILE" ] && ps -p `cat "$PIDFILE"` | grep 'atop$' > /dev/null 36 | then 37 | kill -USR2 `cat "$PIDFILE"` # final sample and terminate 38 | 39 | CNT=0 40 | 41 | while ps -p `cat "$PIDFILE"` > /dev/null 42 | do 43 | CNT=$((CNT + 1)) 44 | 45 | if [ $CNT -gt 5 ] 46 | then 47 | break; 48 | fi 49 | 50 | sleep 1 51 | done 52 | 53 | rm "$PIDFILE" 54 | fi 55 | 56 | # delete logfiles older than N days (configurable) 57 | # start a child shell that activates another child shell in 58 | # the background to avoid a zombie 59 | # 60 | ( (sleep 3; find "$LOGPATH" -name 'atop_*' -mtime +"$LOGGENERATIONS" -exec rm {} \;)& ) 61 | 62 | # activate atop with an interval of S seconds (configurable), 63 | # replacing the current shell 64 | # 65 | echo $$ > $PIDFILE 66 | exec $BINPATH/atop $LOGOPTS -w "$LOGPATH"/atop_"$CURDAY" "$LOGINTERVAL" > "$LOGPATH/daily.log" 2>&1 67 | -------------------------------------------------------------------------------- /gpucom.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** ========================================================================== 7 | ** Author: Gerlof Langeveld 8 | ** E-mail: gerlof.langeveld@atoptool.nl 9 | ** Date: September 2002 10 | ** -------------------------------------------------------------------------- 11 | ** Copyright (C) 2000-2010 Gerlof Langeveld 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | ** 23 | ** You should have received a copy of the GNU General Public License 24 | ** along with this program; if not, write to the Free Software 25 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | ** -------------------------------------------------------------------------- 27 | */ 28 | 29 | #ifndef __GPUCOM__ 30 | #define __GPUCOM__ 31 | 32 | #define APIVERSION 2 33 | 34 | struct gpupidstat { 35 | long pid; 36 | struct gpu gpu; 37 | }; 38 | 39 | int gpud_init(void); 40 | int gpud_statrequest(void); 41 | int gpud_statresponse(int, struct pergpu *, struct gpupidstat **); 42 | 43 | void gpumergeproc(struct tstat *, int, 44 | struct tstat *, int, 45 | struct gpupidstat *, int); 46 | #endif 47 | -------------------------------------------------------------------------------- /ifprop.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** ========================================================================== 7 | ** Author: Gerlof Langeveld 8 | ** E-mail: gerlof.langeveld@atoptool.nl 9 | ** Date: September 2002 10 | ** -------------------------------------------------------------------------- 11 | ** Copyright (C) 2000-2010 Gerlof Langeveld 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | ** 23 | ** You should have received a copy of the GNU General Public License 24 | ** along with this program; if not, write to the Free Software 25 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | ** -------------------------------------------------------------------------- 27 | */ 28 | 29 | #ifndef __IFPROP__ 30 | #define __IFPROP__ 31 | 32 | struct ifprop { 33 | char type; /* type: 'e' - ethernet */ 34 | /* 'w' - wireless */ 35 | /* 'v' - virtual */ 36 | char name[31]; /* name of interface */ 37 | long int speed; /* in megabits per second */ 38 | char fullduplex; /* boolean */ 39 | 40 | struct ifprop *next; /* next in hash list */ 41 | }; 42 | 43 | int getifprop(struct ifprop *); 44 | void initifprop(void); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /netatopd.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** ========================================================================== 7 | ** Author: Gerlof Langeveld 8 | ** E-mail: gerlof.langeveld@atoptool.nl 9 | ** Date: September 2002 10 | ** -------------------------------------------------------------------------- 11 | ** Copyright (C) 2000-2010 Gerlof Langeveld 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | ** 23 | ** You should have received a copy of the GNU General Public License 24 | ** along with this program; if not, write to the Free Software 25 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | ** -------------------------------------------------------------------------- 27 | */ 28 | 29 | #ifndef __NETATOPD__ 30 | #define __NETATOPD__ 31 | 32 | #define SEMAKEY 1541961 33 | 34 | #define NETEXITFILE "/run/netatop.log" 35 | #define MYMAGIC (unsigned int) 0xfeedb0b0 36 | 37 | struct naheader { 38 | u_int32_t magic; // magic number MYMAGIC 39 | u_int32_t curseq; // sequence number of last netpertask 40 | u_int16_t hdrlen; // length of this header 41 | u_int16_t ntplen; // length of netpertask structure 42 | pid_t mypid; // PID of netatopd itself 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /atopacct.init: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # atopacctd Startup script for the atopacctd daemon 4 | # 5 | # chkconfig: 2345 91 9 6 | # description: Process accounting control 7 | # 8 | ### BEGIN INIT INFO 9 | # Provides: atopacct 10 | # Required-Start: $local_fs $remote_fs 11 | # Required-Stop: $local_fs $remote_fs 12 | # Default-Start: 2 3 4 5 13 | # Default-Stop: 0 1 6 14 | # Short-Description: This daemon switches on process accounting and 15 | # transfers the process accounting records 'realtime' 16 | # to small shadow files to avoid huge disk space usage 17 | # Description: Process accounting control 18 | ### END INIT INFO 19 | 20 | # Check existance of binaries 21 | [ -f /usr/sbin/atopacctd ] || exit 0 22 | 23 | RETVAL=0 24 | 25 | # See how we were called. 26 | case "$1" in 27 | start) 28 | # Check if process accounting already in use via separate psacct package 29 | # 30 | for PACCTFILE in /var/account/pacct /var/log/pacct /var/log/account/pacct 31 | do 32 | if [ -f "$PACCTFILE" ] # file exists? 33 | then 34 | BEFORSIZE=$(ls -lL "$PACCTFILE" | awk '{print $5}') 35 | AFTERSIZE=$(ls -lL "$PACCTFILE" | awk '{print $5}') 36 | 37 | # verify if accounting file grows, so is in use 38 | # 39 | if [ $BEFORSIZE -lt $AFTERSIZE ] 40 | then 41 | echo Process accounting already used by psacct! >&2 42 | exit $RETVAL # do not start atopacctd 43 | fi 44 | fi 45 | done 46 | 47 | 48 | # Check if atopacctd runs already 49 | # 50 | if ps -e | grep -q atopacctd$ 51 | then 52 | : 53 | else 54 | # Start atopacctd 55 | rm -rf /run/pacct_shadow.d 2> /dev/null 56 | /usr/sbin/atopacctd 57 | fi 58 | 59 | touch /var/lock/subsys/atopacctd 60 | ;; 61 | 62 | stop) 63 | # Check if atopacctd runs 64 | # 65 | if ps -e | grep -q atopacctd$ 66 | then 67 | kill $(ps -e | grep atopacctd$ | sed 's/^ *//' | cut -d' ' -f1) 68 | fi 69 | rm -f /var/lock/subsys/atopacctd 70 | ;; 71 | 72 | status) 73 | ;; 74 | 75 | reload) 76 | ;; 77 | 78 | restart) 79 | ;; 80 | 81 | *) 82 | echo "Usage: $0 [start|stop]" 83 | exit 1 84 | esac 85 | 86 | exit $RETVAL 87 | -------------------------------------------------------------------------------- /prev/cgroups_211.h: -------------------------------------------------------------------------------- 1 | // structure containing general info and metrics per cgroup (directory) 2 | // 3 | struct cstat_211 { 4 | // GENERAL INFO 5 | struct cggen_211 { 6 | int structlen; // struct length including rounded name 7 | int sequence; // sequence number in chain/array 8 | int parentseq; // parent sequence number in chain/array 9 | int depth; // cgroup tree depth starting from 0 10 | int nprocs; // number of processes in cgroup 11 | int procsbelow; // number of processes in cgroups below 12 | int namelen; // cgroup name length (at end of struct) 13 | int fullnamelen; // cgroup path length 14 | int ifuture[4]; 15 | 16 | long namehash; // cgroup name hash of 17 | // full path name excluding slashes 18 | long lfuture[4]; 19 | } gen; 20 | 21 | // CONFIGURATION INFO 22 | struct cgconf_211 { 23 | int cpuweight; // -1=max, -2=undefined 24 | int cpumax; // -1=max, -2=undefined (perc) 25 | 26 | count_t memmax; // -1=max, -2=undefined (pages) 27 | count_t swpmax; // -1=max, -2=undefined (pages) 28 | 29 | int dskweight; // -1=max, -2=undefined 30 | 31 | int ifuture[5]; 32 | count_t cfuture[5]; 33 | } conf; 34 | 35 | // CPU STATISTICS 36 | struct cgcpu_211 { 37 | count_t utime; // time user text (usec) -1=undefined 38 | count_t stime; // time system text (usec) -1=undefined 39 | 40 | count_t somepres; // some pressure (microsec) 41 | count_t fullpres; // full pressure (microsec) 42 | 43 | count_t cfuture[5]; 44 | } cpu; 45 | 46 | // MEMORY STATISTICS 47 | struct cgmem_211 { 48 | count_t current; // current memory (pages) -1=undefined 49 | count_t anon; // anonymous memory (pages) -1=undefined 50 | count_t file; // file memory (pages) -1=undefined 51 | count_t kernel; // kernel memory (pages) -1=undefined 52 | count_t shmem; // shared memory (pages) -1=undefined 53 | 54 | count_t somepres; // some pressure (microsec) 55 | count_t fullpres; // full pressure (microsec) 56 | 57 | count_t cfuture[5]; 58 | } mem; 59 | 60 | // DISK I/O STATISTICS 61 | struct cgdsk_211 { 62 | count_t rbytes; // total bytes read on all physical disks 63 | count_t wbytes; // total bytes written on all physical disks 64 | count_t rios; // total read I/Os on all physical disks 65 | count_t wios; // total write I/Os on all physical disks 66 | 67 | count_t somepres; // some pressure (microsec) 68 | count_t fullpres; // full pressure (microsec) 69 | 70 | count_t cfuture[5]; 71 | } dsk; 72 | 73 | // cgroup name with variable length 74 | char cgname[]; 75 | }; 76 | -------------------------------------------------------------------------------- /prev/cgroups_212.h: -------------------------------------------------------------------------------- 1 | // structure containing general info and metrics per cgroup (directory) 2 | // 3 | struct cstat_212 { 4 | // GENERAL INFO 5 | struct cggen_212 { 6 | int structlen; // struct length including rounded name 7 | int sequence; // sequence number in chain/array 8 | int parentseq; // parent sequence number in chain/array 9 | int depth; // cgroup tree depth starting from 0 10 | int nprocs; // number of processes in cgroup 11 | int procsbelow; // number of processes in cgroups below 12 | int namelen; // cgroup name length (at end of struct) 13 | int fullnamelen; // cgroup path length 14 | int ifuture[4]; 15 | 16 | long namehash; // cgroup name hash of 17 | // full path name excluding slashes 18 | long lfuture[4]; 19 | } gen; 20 | 21 | // CONFIGURATION INFO 22 | struct cgconf_212 { 23 | int cpuweight; // -1=max, -2=undefined 24 | int cpumax; // -1=max, -2=undefined (perc) 25 | 26 | count_t memmax; // -1=max, -2=undefined (pages) 27 | count_t swpmax; // -1=max, -2=undefined (pages) 28 | 29 | int dskweight; // -1=max, -2=undefined 30 | 31 | int ifuture[5]; 32 | count_t cfuture[5]; 33 | } conf; 34 | 35 | // CPU STATISTICS 36 | struct cgcpu_212 { 37 | count_t utime; // time user text (usec) -1=undefined 38 | count_t stime; // time system text (usec) -1=undefined 39 | 40 | count_t somepres; // some pressure (microsec) 41 | count_t fullpres; // full pressure (microsec) 42 | 43 | count_t cfuture[5]; 44 | } cpu; 45 | 46 | // MEMORY STATISTICS 47 | struct cgmem_212 { 48 | count_t current; // current memory (pages) -1=undefined 49 | count_t anon; // anonymous memory (pages) -1=undefined 50 | count_t file; // file memory (pages) -1=undefined 51 | count_t kernel; // kernel memory (pages) -1=undefined 52 | count_t shmem; // shared memory (pages) -1=undefined 53 | 54 | count_t somepres; // some pressure (microsec) 55 | count_t fullpres; // full pressure (microsec) 56 | 57 | count_t cfuture[5]; 58 | } mem; 59 | 60 | // DISK I/O STATISTICS 61 | struct cgdsk_212 { 62 | count_t rbytes; // total bytes read on all physical disks 63 | count_t wbytes; // total bytes written on all physical disks 64 | count_t rios; // total read I/Os on all physical disks 65 | count_t wios; // total write I/Os on all physical disks 66 | 67 | count_t somepres; // some pressure (microsec) 68 | count_t fullpres; // full pressure (microsec) 69 | 70 | count_t cfuture[5]; 71 | } dsk; 72 | 73 | // cgroup name with variable length 74 | char cgname[]; 75 | }; 76 | -------------------------------------------------------------------------------- /atopacctd.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** ========================================================================== 7 | ** Author: Gerlof Langeveld 8 | ** E-mail: gerlof.langeveld@atoptool.nl 9 | ** Date: September 2002 10 | ** -------------------------------------------------------------------------- 11 | ** Copyright (C) 2000-2010 Gerlof Langeveld 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | ** 23 | ** You should have received a copy of the GNU General Public License 24 | ** along with this program; if not, write to the Free Software 25 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | ** -------------------------------------------------------------------------- 27 | */ 28 | 29 | #ifndef __ATOPACCTD__ 30 | #define __ATOPACCTD__ 31 | 32 | /* 33 | ** keys to access the semaphores 34 | */ 35 | #define PACCTPUBKEY 1071980 // # clients using shadow files 36 | #define PACCTPRVKEY (PACCTPUBKEY-1) // # atopacctd daemons busy (max. 1) 37 | 38 | /* 39 | ** name of the PID file 40 | */ 41 | #define PIDFILE "/run/atopacctd.pid" 42 | 43 | /* 44 | ** directory containing the source accounting file and 45 | ** the subdirectory (PACCTSHADOWD) containing the shadow file(s) 46 | ** this directory can be overruled by a command line parameter (atopacctd) 47 | ** or by a keyword in the /etc/atoprc file (atop) 48 | */ 49 | #define PACCTDIR "/run" 50 | 51 | /* 52 | ** accounting file (source file to which kernel writes records) 53 | */ 54 | #define PACCTORIG "pacct_source" // file name in PACCTDIR 55 | 56 | #define MAXORIGSZ (1024*1024) // maximum size of source file 57 | 58 | /* 59 | ** file and directory names for shadow files 60 | */ 61 | #define PACCTSHADOWD "pacct_shadow.d" // directory name in PACCTDIR 62 | #define PACCTSHADOWF "%s/%s/%010ld.paf" // file name of shadow file 63 | #define PACCTSHADOWC "current" // file containining current 64 | // sequence and MAXSHADOWREC 65 | 66 | #define MAXSHADOWREC 10000 // number of accounting records per shadow file 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /man/atopcat.1: -------------------------------------------------------------------------------- 1 | .TH ATOPCAT 1 "January 2024" "Linux" 2 | .SH NAME 3 | .B atopcat 4 | - concatenate raw log files to stdout 5 | .SH SYNOPSIS 6 | .P 7 | .B atopcat [-dv] rawfile [rawfile]... 8 | .P 9 | .SH DESCRIPTION 10 | The program 11 | .I atopcat 12 | can be used to concatenate several raw log files into one stream (stdout). 13 | In this way, raw log files can be merged into one larger file by redirecting 14 | stdout to a file. Alternatively, merged data from several raw log files 15 | can be transferred directly into 16 | .I atop 17 | or 18 | .I atopsar 19 | via a pipe. 20 | 21 | Options: 22 | .PP 23 | .TP 5 24 | .B -d 25 | dry-run: read logfile(s) but do not generate output on stdout 26 | .PP 27 | .TP 5 28 | .B -v 29 | verbose: print one line per sample containing date/time, interval length 30 | in seconds, compressed length of the system-level information, 31 | compressed length of the process-level information, 32 | compressed length of the cgroup-level information, and 33 | compressed length of the PID list. 34 | .SH EXAMPLES 35 | Concatenate the raw log files of five contiguous working days, 36 | write it into a new raw log file for that week and 37 | view that week interactively: 38 | .PP 39 | .TP 12 40 | .B \ atopcat /var/log/atop/atop_2024021[0-4] > week_2024_7 41 | .TP 12 42 | .B \ atop -r week_2024_7 43 | .PP 44 | Concatenate the raw log files of a week and view that week interactively 45 | (since 46 | .I atop 47 | reads from a pipe, previous intervals can not be retrieved while viewing): 48 | .PP 49 | .TP 12 50 | .B \ atopcat /var/log/atop/atop_2024021[0-6] | atop -r - 51 | .PP 52 | Concatenate all raw log files of January 2024 and generate parsable 53 | output about the CPU utilization: 54 | .PP 55 | .TP 12 56 | .B \ atopcat /var/log/atop/atop_202401?? | atop -r - -PCPU 57 | .PP 58 | Concatenate the daily raw log files of February 3 and 4, 59 | and generate a report about memory utilization from 14:00h on the first day 60 | till 11:00h on the second day: 61 | .PP 62 | .TP 12 63 | .B \ atopcat /var/log/atop/atop_2024020[34] | 64 | .B \ atopsar -m -r - -b 202402031400 -e 202402041100 65 | .PP 66 | Repair a raw log file from which the last interval has not been 67 | completely written (e.g. if you intend to expand the file with new samples): 68 | .PP 69 | .TP 12 70 | .B \ atopcat /var/log/atop/atop_20240303 > /tmp/repaired 71 | .PP 72 | In the latter case, 73 | .B atopcat 74 | reports that the input file is incomplete and stops after the last consistent 75 | sample. 76 | .SH SEE ALSO 77 | .B atop(1), 78 | .B atopsar(1), 79 | .B atophide(1), 80 | .B atopconvert(1) 81 | .br 82 | .B https://www.atoptool.nl 83 | .SH AUTHOR 84 | Gerlof Langeveld (gerlof.langeveld@atoptool.nl) 85 | -------------------------------------------------------------------------------- /netatop.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** ========================================================================== 7 | ** Author: Gerlof Langeveld 8 | ** E-mail: gerlof.langeveld@atoptool.nl 9 | ** Date: September 2002 10 | ** -------------------------------------------------------------------------- 11 | ** Copyright (C) 2000-2010 Gerlof Langeveld 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | ** 23 | ** You should have received a copy of the GNU General Public License 24 | ** along with this program; if not, write to the Free Software 25 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | ** -------------------------------------------------------------------------- 27 | */ 28 | 29 | #ifndef __NETATOP__ 30 | #define __NETATOP__ 31 | 32 | #define COMLEN 16 33 | 34 | struct taskcount { 35 | unsigned long long tcpsndpacks; 36 | unsigned long long tcpsndbytes; 37 | unsigned long long tcprcvpacks; 38 | unsigned long long tcprcvbytes; 39 | 40 | unsigned long long udpsndpacks; 41 | unsigned long long udpsndbytes; 42 | unsigned long long udprcvpacks; 43 | unsigned long long udprcvbytes; 44 | 45 | /* space for future extensions */ 46 | }; 47 | 48 | struct netpertask { 49 | pid_t id; // tgid or tid (depending on command) 50 | unsigned long btime; 51 | char command[COMLEN]; 52 | 53 | struct taskcount tc; 54 | }; 55 | 56 | 57 | /* 58 | ** getsocktop commands 59 | */ 60 | #define NETATOP_BASE_CTL 15661 61 | 62 | // just probe if the netatop module is active 63 | #define NETATOP_PROBE (NETATOP_BASE_CTL) 64 | 65 | // force garbage collection to make finished processes available 66 | #define NETATOP_FORCE_GC (NETATOP_BASE_CTL+1) 67 | 68 | // wait until all finished processes are read (blocks until done) 69 | #define NETATOP_EMPTY_EXIT (NETATOP_BASE_CTL+2) 70 | 71 | // get info for finished process (blocks until available) 72 | #define NETATOP_GETCNT_EXIT (NETATOP_BASE_CTL+3) 73 | 74 | // get counters for thread group (i.e. process): input is 'id' (pid) 75 | #define NETATOP_GETCNT_TGID (NETATOP_BASE_CTL+4) 76 | 77 | // get counters for thread: input is 'id' (tid) 78 | #define NETATOP_GETCNT_PID (NETATOP_BASE_CTL+5) 79 | 80 | #define NETATOPBPF_SOCKET "/run/netatop-bpf-socket" 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /prev/photoproc_200.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_20 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_20 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | int ifuture[4]; /* reserved */ 31 | } gen; 32 | 33 | /* CPU STATISTICS */ 34 | struct cpu_20 { 35 | count_t utime; /* time user text (ticks) */ 36 | count_t stime; /* time system text (ticks) */ 37 | int nice; /* nice value */ 38 | int prio; /* priority */ 39 | int rtprio; /* realtime priority */ 40 | int policy; /* scheduling policy */ 41 | int curcpu; /* current processor */ 42 | int sleepavg; /* sleep average percentage */ 43 | int ifuture[4]; /* reserved for future use */ 44 | count_t cfuture[4]; /* reserved for future use */ 45 | } cpu; 46 | 47 | /* DISK STATISTICS */ 48 | struct dsk_20 { 49 | count_t rio; /* number of read requests */ 50 | count_t rsz; /* cumulative # sectors read */ 51 | count_t wio; /* number of write requests */ 52 | count_t wsz; /* cumulative # sectors written */ 53 | count_t cwsz; /* cumulative # written sectors */ 54 | /* being cancelled */ 55 | count_t cfuture[4]; /* reserved for future use */ 56 | } dsk; 57 | 58 | /* MEMORY STATISTICS */ 59 | struct mem_20 { 60 | count_t minflt; /* number of page-reclaims */ 61 | count_t majflt; /* number of page-faults */ 62 | count_t vexec; /* virtmem execfile (Kb) */ 63 | count_t vmem; /* virtual memory (Kb) */ 64 | count_t rmem; /* resident memory (Kb) */ 65 | count_t vgrow; /* virtual growth (Kb) */ 66 | count_t rgrow; /* resident growth (Kb) */ 67 | count_t vdata; /* virtmem data (Kb) */ 68 | count_t vstack; /* virtmem stack (Kb) */ 69 | count_t vlibs; /* virtmem libexec (Kb) */ 70 | count_t vswap; /* swap space used (Kb) */ 71 | } mem; 72 | 73 | /* NETWORK STATISTICS */ 74 | struct net_20 { 75 | count_t tcpsnd; /* number of TCP-packets sent */ 76 | count_t tcpssz; /* cumulative size packets sent */ 77 | count_t tcprcv; /* number of TCP-packets recved */ 78 | count_t tcprsz; /* cumulative size packets rcvd */ 79 | count_t udpsnd; /* number of UDP-packets sent */ 80 | count_t udpssz; /* cumulative size packets sent */ 81 | count_t udprcv; /* number of UDP-packets recved */ 82 | count_t udprsz; /* cumulative size packets sent */ 83 | count_t avail1; /* */ 84 | count_t avail2; /* */ 85 | count_t cfuture[4]; /* reserved for future use */ 86 | } net; 87 | }; 88 | -------------------------------------------------------------------------------- /prev/photoproc_201.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_21 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_21 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | int envid; /* OpenVZ support */ 31 | int ifuture[4]; /* reserved */ 32 | } gen; 33 | 34 | /* CPU STATISTICS */ 35 | struct cpu_21 { 36 | count_t utime; /* time user text (ticks) */ 37 | count_t stime; /* time system text (ticks) */ 38 | int nice; /* nice value */ 39 | int prio; /* priority */ 40 | int rtprio; /* realtime priority */ 41 | int policy; /* scheduling policy */ 42 | int curcpu; /* current processor */ 43 | int sleepavg; /* sleep average percentage */ 44 | int ifuture[4]; /* reserved for future use */ 45 | count_t cfuture[4]; /* reserved for future use */ 46 | } cpu; 47 | 48 | /* DISK STATISTICS */ 49 | struct dsk_21 { 50 | count_t rio; /* number of read requests */ 51 | count_t rsz; /* cumulative # sectors read */ 52 | count_t wio; /* number of write requests */ 53 | count_t wsz; /* cumulative # sectors written */ 54 | count_t cwsz; /* cumulative # written sectors */ 55 | /* being cancelled */ 56 | count_t cfuture[4]; /* reserved for future use */ 57 | } dsk; 58 | 59 | /* MEMORY STATISTICS */ 60 | struct mem_21 { 61 | count_t minflt; /* number of page-reclaims */ 62 | count_t majflt; /* number of page-faults */ 63 | count_t vexec; /* virtmem execfile (Kb) */ 64 | count_t vmem; /* virtual memory (Kb) */ 65 | count_t rmem; /* resident memory (Kb) */ 66 | count_t pmem; /* resident memory (Kb) */ 67 | count_t vgrow; /* virtual growth (Kb) */ 68 | count_t rgrow; /* resident growth (Kb) */ 69 | count_t vdata; /* virtmem data (Kb) */ 70 | count_t vstack; /* virtmem stack (Kb) */ 71 | count_t vlibs; /* virtmem libexec (Kb) */ 72 | count_t vswap; /* swap space used (Kb) */ 73 | count_t cfuture[4]; /* reserved for future use */ 74 | } mem; 75 | 76 | /* NETWORK STATISTICS */ 77 | struct net_21 { 78 | count_t tcpsnd; /* number of TCP-packets sent */ 79 | count_t tcpssz; /* cumulative size packets sent */ 80 | count_t tcprcv; /* number of TCP-packets recved */ 81 | count_t tcprsz; /* cumulative size packets rcvd */ 82 | count_t udpsnd; /* number of UDP-packets sent */ 83 | count_t udpssz; /* cumulative size packets sent */ 84 | count_t udprcv; /* number of UDP-packets recved */ 85 | count_t udprsz; /* cumulative size packets sent */ 86 | count_t avail1; /* */ 87 | count_t avail2; /* */ 88 | count_t cfuture[4]; /* reserved for future use */ 89 | } net; 90 | }; 91 | -------------------------------------------------------------------------------- /prev/photoproc_202.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_22 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_22 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | 31 | int ctid; /* OpenVZ container ID */ 32 | int vpid; /* OpenVZ virtual PID */ 33 | 34 | int ifuture[5]; /* reserved */ 35 | } gen; 36 | 37 | /* CPU STATISTICS */ 38 | struct cpu_22 { 39 | count_t utime; /* time user text (ticks) */ 40 | count_t stime; /* time system text (ticks) */ 41 | int nice; /* nice value */ 42 | int prio; /* priority */ 43 | int rtprio; /* realtime priority */ 44 | int policy; /* scheduling policy */ 45 | int curcpu; /* current processor */ 46 | int sleepavg; /* sleep average percentage */ 47 | int ifuture[4]; /* reserved for future use */ 48 | count_t cfuture[4]; /* reserved for future use */ 49 | } cpu; 50 | 51 | /* DISK STATISTICS */ 52 | struct dsk_22 { 53 | count_t rio; /* number of read requests */ 54 | count_t rsz; /* cumulative # sectors read */ 55 | count_t wio; /* number of write requests */ 56 | count_t wsz; /* cumulative # sectors written */ 57 | count_t cwsz; /* cumulative # written sectors */ 58 | /* being cancelled */ 59 | count_t cfuture[4]; /* reserved for future use */ 60 | } dsk; 61 | 62 | /* MEMORY STATISTICS */ 63 | struct mem_22 { 64 | count_t minflt; /* number of page-reclaims */ 65 | count_t majflt; /* number of page-faults */ 66 | count_t vexec; /* virtmem execfile (Kb) */ 67 | count_t vmem; /* virtual memory (Kb) */ 68 | count_t rmem; /* resident memory (Kb) */ 69 | count_t pmem; /* resident memory (Kb) */ 70 | count_t vgrow; /* virtual growth (Kb) */ 71 | count_t rgrow; /* resident growth (Kb) */ 72 | count_t vdata; /* virtmem data (Kb) */ 73 | count_t vstack; /* virtmem stack (Kb) */ 74 | count_t vlibs; /* virtmem libexec (Kb) */ 75 | count_t vswap; /* swap space used (Kb) */ 76 | count_t cfuture[4]; /* reserved for future use */ 77 | } mem; 78 | 79 | /* NETWORK STATISTICS */ 80 | struct net_22 { 81 | count_t tcpsnd; /* number of TCP-packets sent */ 82 | count_t tcpssz; /* cumulative size packets sent */ 83 | count_t tcprcv; /* number of TCP-packets recved */ 84 | count_t tcprsz; /* cumulative size packets rcvd */ 85 | count_t udpsnd; /* number of UDP-packets sent */ 86 | count_t udpssz; /* cumulative size packets sent */ 87 | count_t udprcv; /* number of UDP-packets recved */ 88 | count_t udprsz; /* cumulative size packets sent */ 89 | count_t avail1; /* */ 90 | count_t avail2; /* */ 91 | count_t cfuture[4]; /* reserved for future use */ 92 | } net; 93 | }; 94 | -------------------------------------------------------------------------------- /prev/photoproc_203.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_23 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_23 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | 31 | int ctid; /* OpenVZ container ID */ 32 | int vpid; /* OpenVZ virtual PID */ 33 | 34 | int wasinactive; /* boolean: task inactive */ 35 | 36 | char container[16]; /* Docker container id (12 pos) */ 37 | } gen; 38 | 39 | /* CPU STATISTICS */ 40 | struct cpu_23 { 41 | count_t utime; /* time user text (ticks) */ 42 | count_t stime; /* time system text (ticks) */ 43 | int nice; /* nice value */ 44 | int prio; /* priority */ 45 | int rtprio; /* realtime priority */ 46 | int policy; /* scheduling policy */ 47 | int curcpu; /* current processor */ 48 | int sleepavg; /* sleep average percentage */ 49 | int ifuture[4]; /* reserved for future use */ 50 | count_t cfuture[4]; /* reserved for future use */ 51 | } cpu; 52 | 53 | /* DISK STATISTICS */ 54 | struct dsk_23 { 55 | count_t rio; /* number of read requests */ 56 | count_t rsz; /* cumulative # sectors read */ 57 | count_t wio; /* number of write requests */ 58 | count_t wsz; /* cumulative # sectors written */ 59 | count_t cwsz; /* cumulative # written sectors */ 60 | /* being cancelled */ 61 | count_t cfuture[4]; /* reserved for future use */ 62 | } dsk; 63 | 64 | /* MEMORY STATISTICS */ 65 | struct mem_23 { 66 | count_t minflt; /* number of page-reclaims */ 67 | count_t majflt; /* number of page-faults */ 68 | count_t vexec; /* virtmem execfile (Kb) */ 69 | count_t vmem; /* virtual memory (Kb) */ 70 | count_t rmem; /* resident memory (Kb) */ 71 | count_t pmem; /* resident memory (Kb) */ 72 | count_t vgrow; /* virtual growth (Kb) */ 73 | count_t rgrow; /* resident growth (Kb) */ 74 | count_t vdata; /* virtmem data (Kb) */ 75 | count_t vstack; /* virtmem stack (Kb) */ 76 | count_t vlibs; /* virtmem libexec (Kb) */ 77 | count_t vswap; /* swap space used (Kb) */ 78 | count_t cfuture[4]; /* reserved for future use */ 79 | } mem; 80 | 81 | /* NETWORK STATISTICS */ 82 | struct net_23 { 83 | count_t tcpsnd; /* number of TCP-packets sent */ 84 | count_t tcpssz; /* cumulative size packets sent */ 85 | count_t tcprcv; /* number of TCP-packets recved */ 86 | count_t tcprsz; /* cumulative size packets rcvd */ 87 | count_t udpsnd; /* number of UDP-packets sent */ 88 | count_t udpssz; /* cumulative size packets sent */ 89 | count_t udprcv; /* number of UDP-packets recved */ 90 | count_t udprsz; /* cumulative size packets sent */ 91 | count_t avail1; /* */ 92 | count_t avail2; /* */ 93 | count_t cfuture[4]; /* reserved for future use */ 94 | } net; 95 | }; 96 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | COPYRIGHT NOTICE 2 | ---------------- 3 | For all files that are not marked differently: 4 | 5 | Copyright Gerlof Langeveld 2007-2024 and licensed under the GPL v2 (or any later version). 6 | 7 | 8 | DEPENDENCIES 9 | ------------ 10 | 11 | Install the following packages to be able to build atop (package name 12 | can be different depending on the Linux distro): 13 | 14 | * zlib-devel or libz-dev or zlib1g-dev 15 | * ncurses-devel or libncurses5-dev/libncursesw5-dev 16 | * glib2-devel or libglib2.0-dev 17 | 18 | 19 | Install the following packages to be able to execute atop (package name 20 | can be different depending on the Linux distro): 21 | 22 | * zlib or zlib1g 23 | * ncurses or libncurses5/libncursesw5 24 | * glib2 or libglib2.0 25 | 26 | 27 | INSTALLING AND USING ATOP FROM TARBALL 28 | -------------------------------------- 29 | 30 | For interactive use, it is sufficient to install ATOP with the command 31 | (as root): 32 | 33 | make install (systemd based) 34 | 35 | or 36 | 37 | make sysvinstall (System V init based) 38 | 39 | For automatic logging in compressed binary format, see the 40 | description in the manual-page. 41 | 42 | 43 | NETWORK-RELATED COUNTERS PER PROCESS/THREAD 44 | ------------------------------------------- 45 | 46 | The kernel module 'netatop' can be downloaded and installed separately 47 | from www.atoptool.nl/downloadnetatop.php 48 | This module is optional and can be used to gather network statistics 49 | per process/thread as described in www.atoptool.nl/netatop.php 50 | 51 | Alternatively, the BPF implementation 'netatop-bpf' can be downloaded 52 | and installed from https://github.com/bytedance/netatop-bpf 53 | 54 | 55 | PROCESS ACCOUNTING WITH PSACCT/ACCT PACKAGE 56 | ------------------------------------------- 57 | 58 | Preferably, process accounting should be handled by the atopacctd daemon 59 | which is implicitly installed when installing atop. This daemon takes 60 | care that process accounting is only active when at least one atop 61 | process is running. Besides, when process accounting is activated, 62 | atopacctd takes care that the disk utilization is minimal. 63 | See the man page of atopacctd for further details. 64 | 65 | When the psacct or acct package is installed in parallel with the 66 | atop package and you want to enable/start the (ps)acct service for 67 | permanent process accounting, the atopacct.service refuses to activate 68 | the atopacctd daemon to avoid clashes. 69 | When the (ps)acct service is enabled, atop automatically uses the 70 | process accounting file that is used by this package. 71 | See also the section PROCESS ACCOUNTING in the man page of atop. 72 | 73 | 74 | OVERVIEW OF RELATED PROGRAMS 75 | ---------------------------- 76 | 77 | When installing atop the following programs are provided: 78 | 79 | atop - System and process monitor (live and from raw log) 80 | atopacctd - Daemon: handles process accounting records to be used by atop 81 | atopgpud - Daemon: gathers metrics from Nvidia GPUs to be used by atop 82 | atopsar - System activity reports (live and from raw log) 83 | atopcat - Concatenate raw log files and provide raw log information 84 | atophide - Make extractions from raw logs and/or anonymize raw logs 85 | atopconvert - Convert raw log to newer version 86 | 87 | 88 | SERVICE ACTIVATION AFTER INSTALLATING PACKAGE 89 | --------------------------------------------- 90 | 91 | After the package has been installed, be sure that the related services 92 | are activated. 93 | To support handling of terminated processes using process accounting, 94 | enable the atopacct service: 95 | 96 | systemctl enable --now atopacct 97 | 98 | Notice that this service should not be enabled when the package 99 | psacct or acct (depends on the Linux distribution) has been installed 100 | and enabled. In that case atop uses the daily process accounting file 101 | created via that package. 102 | 103 | To support maintaining daily log files to keep track of long-term analysis 104 | information, enable the atop service and the related timer: 105 | 106 | systemctl enable --now atop 107 | systemctl enable --now atop-rotate.timer 108 | 109 | 110 | 111 | 112 | Gerlof Langeveld 113 | gerlof.langeveld@atoptool.nl 114 | -------------------------------------------------------------------------------- /man/atopgpud.8: -------------------------------------------------------------------------------- 1 | .TH ATOPGPUD 8 "September 2025" "Linux" 2 | .SH NAME 3 | .B atopgpud 4 | - GPU statistics daemon 5 | .SH SYNOPSIS 6 | .P 7 | .B atopgpud [-v] 8 | .PP 9 | .SH DESCRIPTION 10 | The 11 | .I atopgpud 12 | daemon gathers statistical information from all NVIDIA GPUs in the 13 | current system. With a sampling rate of one second, it maintains 14 | the statistics of every GPU, globally (system level) and per process. 15 | When 16 | .I atopgpud 17 | is active on the target system, 18 | .I atop 19 | (with the flag -k) connects to this daemon via a UNIX domain socket and 20 | obtains GPU statistics for each interval. 21 | .PP 22 | The approach to gather all GPU statistics in a separate daemon is required, 23 | because the NVIDIA driver only offers the GPU busy 24 | percentage of the last second. Suppose that 25 | .I atop 26 | runs with a 10-minute interval and would fetch the GPU busy percentage 27 | directly from the NVIDIA driver, it would reflect the busy percentage of 28 | the last second instead of the average busy percentage during 600 seconds. 29 | Therefore, the 30 | .I atopgpud 31 | daemon fetches the GPU busy percentage every second and accumulates this 32 | into a counter that can be retrieved by 33 | .I atop 34 | regularly. The same approach applies to other GPU statistics. 35 | .PP 36 | There is no need to run the 37 | .I atopgpud 38 | daemon with root privileges. 39 | .PP 40 | Notice that certain GPU statistics are only delivered for specific GPU types. 41 | For older or less sophisticated GPUs, the value -1 is returned for counters 42 | that are not maintained. In the output of 43 | .I atop 44 | these counters are shown as 'N/A'. 45 | .PP 46 | When no NVIDIA GPUs can be found in the target system, 47 | .I atopgpud 48 | immediately terminates with exit code 0. 49 | .PP 50 | Log messages are written via the 51 | .I rsyslogd 52 | daemon with facility 'daemon'. 53 | With the -v flag (verbose), 54 | .I atopgpud 55 | also logs debug messages. 56 | .PP 57 | .SH INSTALLATION 58 | The 59 | .I atopgpud 60 | daemon is written in Python, so 61 | a Python 3 interpreter should be installed on the target system. 62 | The daemon depends on the Python module 63 | .I pynvml 64 | to interface with the Nvidia driver. 65 | This module can be installed by the 66 | .I pip 67 | or 68 | .I pip3 69 | command and is usually packaged under the name 70 | .I nvidia-ml-py 71 | .br 72 | The 73 | .I pynvml 74 | module is a Python wrapper around the 75 | .I libnvidia-ml 76 | shared library that needs to be installed as well. 77 | .PP 78 | After installing the 79 | .I atop 80 | package, the 81 | .I atopgpud 82 | is not automatically started, nor will 83 | the service be enabed by default. 84 | When you want to activate this service (permanently), 85 | enter the following commands (as root): 86 | .PP 87 | .B \ systemctl enable atopgpu 88 | .br 89 | .B \ systemctl start atopgpu 90 | .PP 91 | .SH INTERFACE DESCRIPTION 92 | Client processes can connect to the 93 | .I atopgpud 94 | daemon using the abstract socket name 'atopgpud_nvidia'. 95 | Subsequently, such client can send a request of two bytes, 96 | consisting of one byte request code followed by one byte 97 | integer being the API version number. 98 | .br 99 | The request code in the first byte can be 'T' to obtain information 100 | about the GPU types installed in this system (usually only requested once). 101 | .br 102 | The request code can be 'S' to obtain all statistical counter values 103 | (requested for every interval). 104 | .PP 105 | The response of the daemon starts with a 4-byte integer. The 106 | first byte is the API version number that determines the response format 107 | while the subsequent three bytes indicate the length (big endian order) of the 108 | response string that follows. 109 | .br 110 | In the response strings the character '@' introduces system level information 111 | of one specific GPU and the character '#' introduces process level information 112 | related to that GPU. 113 | .br 114 | For further details about the meaning of the counters in a response string, 115 | please consult the source code. 116 | .PP 117 | .SH SEE ALSO 118 | .B atop(1), 119 | .B atopsar(1), 120 | .B atoprc(5), 121 | .B netatop(4), 122 | .B netatopd(8), 123 | .B atopacctd(8) 124 | .br 125 | .B https://www.atoptool.nl 126 | .SH AUTHOR 127 | Gerlof Langeveld (gerlof.langeveld@atoptool.nl) 128 | -------------------------------------------------------------------------------- /rpmspec/atop.specsysv: -------------------------------------------------------------------------------- 1 | Name: atop 2 | Version: XVERSX 3 | Release: XRELX 4 | Source0: %{name}-%{version}.tar.gz 5 | URL: https://www.atoptool.nl 6 | Packager: Gerlof Langeveld 7 | Summary: Advanced System and Process Monitor 8 | License: GPL 9 | Group: System Environment 10 | Requires: zlib, ncurses 11 | BuildRequires: zlib-devel, ncurses-devel 12 | BuildRoot: /var/tmp/rpm-buildroot-atop 13 | 14 | %description 15 | The program atop is an interactive monitor to view the load on 16 | a Linux-system. It shows the occupation of the most critical 17 | hardware-resources (from a performance point of view) on system-level, 18 | i.e. cpu, memory, disk and network. It also shows which processess 19 | (and threads) are responsible for the indicated load (again cpu-, 20 | memory-, disk- and network-load on process-level). 21 | The program atop can also be used to log system- and process-level 22 | information in raw format for long-term analysis. 23 | 24 | The program atopsar can be used to view system-level statistics 25 | as reports. 26 | 27 | %prep 28 | %setup -q 29 | 30 | %build 31 | make 32 | 33 | %install 34 | rm -rf $RPM_BUILD_ROOT 35 | 36 | # generic build 37 | install -Dp -m 04711 atop $RPM_BUILD_ROOT/usr/bin/atop 38 | ln -s atop $RPM_BUILD_ROOT/usr/bin/atopsar 39 | install -Dp -m 0711 atopconvert $RPM_BUILD_ROOT/usr/bin/atopconvert 40 | install -Dp -m 0711 atopcat $RPM_BUILD_ROOT/usr/bin/atopcat 41 | install -Dp -m 0700 atopacctd $RPM_BUILD_ROOT/usr/sbin/atopacctd 42 | 43 | install -Dp -m 0711 atop.daily $RPM_BUILD_ROOT/usr/share/atop/atop.daily 44 | 45 | install -Dp -m 0644 man/atop.1 $RPM_BUILD_ROOT/usr/share/man/man1/atop.1 46 | install -Dp -m 0644 man/atopsar.1 $RPM_BUILD_ROOT/usr/share/man/man1/atopsar.1 47 | install -Dp -m 0644 man/atopconvert.1 $RPM_BUILD_ROOT/usr/share/man/man1/atopconvert.1 48 | install -Dp -m 0644 man/atopcat.1 $RPM_BUILD_ROOT/usr/share/man/man1/atopcat.1 49 | install -Dp -m 0644 man/atoprc.5 $RPM_BUILD_ROOT/usr/share/man/man5/atoprc.5 50 | install -Dp -m 0644 man/atopacctd.8 $RPM_BUILD_ROOT/usr/share/man/man8/atopacctd.8 51 | 52 | # systemv-specific build 53 | install -Dp -m 0755 atop.init $RPM_BUILD_ROOT/etc/init.d/atop 54 | install -Dp -m 0755 atopacct.init $RPM_BUILD_ROOT/etc/init.d/atopacct 55 | install -Dp -m 0644 atop.cronsysv $RPM_BUILD_ROOT/etc/cron.d/atop 56 | install -Dp -m 0711 45atoppm $RPM_BUILD_ROOT/etc/atop/45atoppm 57 | install -d -m 0755 $RPM_BUILD_ROOT/var/log/atop 58 | 59 | touch $RPM_BUILD_ROOT/etc/default/atop 60 | chmod 0644 $RPM_BUILD_ROOT/etc/default/atop 61 | 62 | %clean 63 | rm -rf $RPM_BUILD_ROOT 64 | 65 | %post 66 | /sbin/chkconfig --add atopacct 67 | /sbin/chkconfig --add atop 68 | 69 | # save today's logfile (format might be incompatible) 70 | mv /var/log/atop/atop_`date +%Y%m%d` /var/log/atop/atop_`date +%Y%m%d`.save \ 71 | 2> /dev/null || : 72 | 73 | # create dummy files to be rotated 74 | touch /var/log/atop/dummy_before /var/log/atop/dummy_after 75 | 76 | # install Power Management for suspend/hibernate 77 | if [ -d /usr/lib/pm-utils/sleep.d ] 78 | then 79 | cp /etc/atop/45atoppm /usr/lib/pm-utils/sleep.d 80 | fi 81 | 82 | if [ -d /usr/lib64/pm-utils/sleep.d ] 83 | then 84 | cp /etc/atop/45atoppm /usr/lib64/pm-utils/sleep.d 85 | fi 86 | 87 | # activate daily logging for today 88 | /usr/sbin/atopacctd 89 | sleep 2 90 | /usr/share/atop/atop.daily& 91 | 92 | %preun 93 | killall atopacctd 2> /dev/null || : 94 | killall atop 2> /dev/null || : 95 | 96 | if [ $1 -eq 0 ] 97 | then 98 | /sbin/chkconfig --del atopacct 99 | /sbin/chkconfig --del atop 100 | fi 101 | 102 | rm -f /usr/lib/pm-utils/sleep.d/45atoppm 2> /dev/null 103 | rm -f /usr/lib64/pm-utils/sleep.d/45atoppm 2> /dev/null 104 | 105 | # atop-XVERSX and atopsar-XVERSX will remain for old logfiles 106 | cp -f /usr/bin/atop /usr/bin/atop-XVERSX 107 | ln -sf /usr/bin/atop-XVERSX /usr/bin/atopsar-XVERSX 108 | 109 | %files 110 | %defattr(-,root,root) 111 | %doc README COPYING AUTHOR ChangeLog 112 | /usr/bin/atop 113 | /usr/bin/atopsar 114 | /usr/bin/atopconvert 115 | /usr/bin/atopcat 116 | /usr/sbin/atopacctd 117 | /usr/share/man/man1/atop.1* 118 | /usr/share/man/man1/atopsar.1* 119 | /usr/share/man/man1/atopconvert.1* 120 | /usr/share/man/man1/atopcat.1* 121 | /usr/share/man/man5/atoprc.5* 122 | /usr/share/man/man8/atopacctd.8* 123 | %config /etc/init.d/atop 124 | %config /etc/init.d/atopacct 125 | %config(noreplace) /etc/default/atop 126 | /usr/share/atop/atop.daily 127 | /etc/atop/45atoppm 128 | /etc/cron.d/atop 129 | %dir /var/log/atop/ 130 | -------------------------------------------------------------------------------- /prev/photoproc_204.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_24 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_24 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | 31 | int ctid; /* OpenVZ container ID */ 32 | int vpid; /* OpenVZ virtual PID */ 33 | 34 | int wasinactive; /* boolean: task inactive */ 35 | 36 | char container[16]; /* Docker container id (12 pos) */ 37 | } gen; 38 | 39 | /* CPU STATISTICS */ 40 | struct cpu_24 { 41 | count_t utime; /* time user text (ticks) */ 42 | count_t stime; /* time system text (ticks) */ 43 | int nice; /* nice value */ 44 | int prio; /* priority */ 45 | int rtprio; /* realtime priority */ 46 | int policy; /* scheduling policy */ 47 | int curcpu; /* current processor */ 48 | int sleepavg; /* sleep average percentage */ 49 | int ifuture[4]; /* reserved for future use */ 50 | count_t cfuture[4]; /* reserved for future use */ 51 | } cpu; 52 | 53 | /* DISK STATISTICS */ 54 | struct dsk_24 { 55 | count_t rio; /* number of read requests */ 56 | count_t rsz; /* cumulative # sectors read */ 57 | count_t wio; /* number of write requests */ 58 | count_t wsz; /* cumulative # sectors written */ 59 | count_t cwsz; /* cumulative # written sectors */ 60 | /* being cancelled */ 61 | count_t cfuture[4]; /* reserved for future use */ 62 | } dsk; 63 | 64 | /* MEMORY STATISTICS */ 65 | struct mem_24 { 66 | count_t minflt; /* number of page-reclaims */ 67 | count_t majflt; /* number of page-faults */ 68 | count_t vexec; /* virtmem execfile (Kb) */ 69 | count_t vmem; /* virtual memory (Kb) */ 70 | count_t rmem; /* resident memory (Kb) */ 71 | count_t pmem; /* resident memory (Kb) */ 72 | count_t vgrow; /* virtual growth (Kb) */ 73 | count_t rgrow; /* resident growth (Kb) */ 74 | count_t vdata; /* virtmem data (Kb) */ 75 | count_t vstack; /* virtmem stack (Kb) */ 76 | count_t vlibs; /* virtmem libexec (Kb) */ 77 | count_t vswap; /* swap space used (Kb) */ 78 | count_t cfuture[4]; /* reserved for future use */ 79 | } mem; 80 | 81 | /* NETWORK STATISTICS */ 82 | struct net_24 { 83 | count_t tcpsnd; /* number of TCP-packets sent */ 84 | count_t tcpssz; /* cumulative size packets sent */ 85 | count_t tcprcv; /* number of TCP-packets recved */ 86 | count_t tcprsz; /* cumulative size packets rcvd */ 87 | count_t udpsnd; /* number of UDP-packets sent */ 88 | count_t udpssz; /* cumulative size packets sent */ 89 | count_t udprcv; /* number of UDP-packets recved */ 90 | count_t udprsz; /* cumulative size packets sent */ 91 | count_t avail1; /* */ 92 | count_t avail2; /* */ 93 | count_t cfuture[4]; /* reserved for future use */ 94 | } net; 95 | 96 | struct gpu_24 { 97 | char state; // A - active, E - Exit, '\0' - no use 98 | char cfuture[3]; // 99 | short nrgpus; // number of GPUs for this process 100 | int32_t gpulist; // bitlist with GPU numbers 101 | 102 | int gpubusy; // gpu busy perc process lifetime -1 = n/a 103 | int membusy; // memory busy perc process lifetime -1 = n/a 104 | count_t timems; // milliseconds accounting -1 = n/a 105 | // value 0 for active process, 106 | // value > 0 after termination 107 | 108 | count_t memnow; // current memory consumption in KiB 109 | count_t memcum; // cumulative memory consumption in KiB 110 | count_t sample; // number of samples 111 | } gpu; 112 | }; 113 | -------------------------------------------------------------------------------- /prev/photoproc_205.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_25 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_25 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | 31 | int ctid; /* OpenVZ container ID */ 32 | int vpid; /* OpenVZ virtual PID */ 33 | 34 | int wasinactive; /* boolean: task inactive */ 35 | 36 | char container[16]; /* Docker container id (12 pos) */ 37 | } gen; 38 | 39 | /* CPU STATISTICS */ 40 | struct cpu_25 { 41 | count_t utime; /* time user text (ticks) */ 42 | count_t stime; /* time system text (ticks) */ 43 | int nice; /* nice value */ 44 | int prio; /* priority */ 45 | int rtprio; /* realtime priority */ 46 | int policy; /* scheduling policy */ 47 | int curcpu; /* current processor */ 48 | int sleepavg; /* sleep average percentage */ 49 | int ifuture[4]; /* reserved for future use */ 50 | count_t cfuture[4]; /* reserved for future use */ 51 | } cpu; 52 | 53 | /* DISK STATISTICS */ 54 | struct dsk_25 { 55 | count_t rio; /* number of read requests */ 56 | count_t rsz; /* cumulative # sectors read */ 57 | count_t wio; /* number of write requests */ 58 | count_t wsz; /* cumulative # sectors written */ 59 | count_t cwsz; /* cumulative # written sectors */ 60 | /* being cancelled */ 61 | count_t cfuture[4]; /* reserved for future use */ 62 | } dsk; 63 | 64 | /* MEMORY STATISTICS */ 65 | struct mem_25 { 66 | count_t minflt; /* number of page-reclaims */ 67 | count_t majflt; /* number of page-faults */ 68 | count_t vexec; /* virtmem execfile (Kb) */ 69 | count_t vmem; /* virtual memory (Kb) */ 70 | count_t rmem; /* resident memory (Kb) */ 71 | count_t pmem; /* resident memory (Kb) */ 72 | count_t vgrow; /* virtual growth (Kb) */ 73 | count_t rgrow; /* resident growth (Kb) */ 74 | count_t vdata; /* virtmem data (Kb) */ 75 | count_t vstack; /* virtmem stack (Kb) */ 76 | count_t vlibs; /* virtmem libexec (Kb) */ 77 | count_t vswap; /* swap space used (Kb) */ 78 | count_t cfuture[4]; /* reserved for future use */ 79 | } mem; 80 | 81 | /* NETWORK STATISTICS */ 82 | struct net_25 { 83 | count_t tcpsnd; /* number of TCP-packets sent */ 84 | count_t tcpssz; /* cumulative size packets sent */ 85 | count_t tcprcv; /* number of TCP-packets recved */ 86 | count_t tcprsz; /* cumulative size packets rcvd */ 87 | count_t udpsnd; /* number of UDP-packets sent */ 88 | count_t udpssz; /* cumulative size packets sent */ 89 | count_t udprcv; /* number of UDP-packets recved */ 90 | count_t udprsz; /* cumulative size packets sent */ 91 | count_t avail1; /* */ 92 | count_t avail2; /* */ 93 | count_t cfuture[4]; /* reserved for future use */ 94 | } net; 95 | 96 | struct gpu_25 { 97 | char state; // A - active, E - Exit, '\0' - no use 98 | char cfuture[3]; // 99 | short nrgpus; // number of GPUs for this process 100 | int32_t gpulist; // bitlist with GPU numbers 101 | 102 | int gpubusy; // gpu busy perc process lifetime -1 = n/a 103 | int membusy; // memory busy perc process lifetime -1 = n/a 104 | count_t timems; // milliseconds accounting -1 = n/a 105 | // value 0 for active process, 106 | // value > 0 after termination 107 | 108 | count_t memnow; // current memory consumption in KiB 109 | count_t memcum; // cumulative memory consumption in KiB 110 | count_t sample; // number of samples 111 | } gpu; 112 | }; 113 | -------------------------------------------------------------------------------- /rpmspec/atop.specsystemd: -------------------------------------------------------------------------------- 1 | Name: atop 2 | Version: XVERSX 3 | Release: XRELX 4 | Source0: %{name}-%{version}.tar.gz 5 | URL: https://www.atoptool.nl 6 | Packager: Gerlof Langeveld 7 | Summary: Advanced System and Process Monitor 8 | License: GPL 9 | Group: System Environment 10 | Requires: zlib, ncurses, python3 11 | BuildRequires: zlib-devel, ncurses-devel, glib2-devel 12 | BuildRoot: /var/tmp/rpm-buildroot-atop 13 | 14 | %description 15 | The program atop is an interactive monitor to view the load on 16 | a Linux-system. It shows the occupation of the most critical 17 | hardware-resources (from a performance point of view) on system-level, 18 | i.e. cpu, memory, disk and network. It also shows which processess 19 | (and threads) are responsible for the indicated load (again cpu-, 20 | memory-, disk- and network-load on process-level). 21 | The program atop can also be used to log system- and process-level 22 | information in raw format for long-term analysis. 23 | 24 | The program atopsar can be used to view system-level statistics 25 | as reports. 26 | 27 | %prep 28 | %setup -q 29 | 30 | %build 31 | make 32 | 33 | %install 34 | rm -rf $RPM_BUILD_ROOT 35 | 36 | # generic build 37 | install -Dp -m 0711 atop $RPM_BUILD_ROOT/usr/bin/atop 38 | ln -s atop $RPM_BUILD_ROOT/usr/bin/atopsar 39 | install -Dp -m 0711 atopconvert $RPM_BUILD_ROOT/usr/bin/atopconvert 40 | install -Dp -m 0711 atopcat $RPM_BUILD_ROOT/usr/bin/atopcat 41 | install -Dp -m 0711 atophide $RPM_BUILD_ROOT/usr/bin/atophide 42 | install -Dp -m 0700 atopacctd $RPM_BUILD_ROOT/usr/sbin/atopacctd 43 | install -Dp -m 0700 atopgpud $RPM_BUILD_ROOT/usr/sbin/atopgpud 44 | install -Dp -m 0644 atop.default $RPM_BUILD_ROOT/etc/default/atop 45 | 46 | install -Dp -m 0644 man/atop.1 $RPM_BUILD_ROOT/usr/share/man/man1/atop.1 47 | install -Dp -m 0644 man/atopsar.1 $RPM_BUILD_ROOT/usr/share/man/man1/atopsar.1 48 | install -Dp -m 0644 man/atopconvert.1 $RPM_BUILD_ROOT/usr/share/man/man1/atopconvert.1 49 | install -Dp -m 0644 man/atopcat.1 $RPM_BUILD_ROOT/usr/share/man/man1/atopcat.1 50 | install -Dp -m 0644 man/atophide.1 $RPM_BUILD_ROOT/usr/share/man/man1/atophide.1 51 | install -Dp -m 0644 man/atoprc.5 $RPM_BUILD_ROOT/usr/share/man/man5/atoprc.5 52 | install -Dp -m 0644 man/atopacctd.8 $RPM_BUILD_ROOT/usr/share/man/man8/atopacctd.8 53 | install -Dp -m 0644 man/atopgpud.8 $RPM_BUILD_ROOT/usr/share/man/man8/atopgpud.8 54 | 55 | install -d -m 0755 $RPM_BUILD_ROOT/var/log/atop 56 | 57 | # systemd-specific build 58 | install -Dp -m 0644 atop.service $RPM_BUILD_ROOT/usr/lib/systemd/system/atop.service 59 | install -Dp -m 0644 atop-rotate.service $RPM_BUILD_ROOT/usr/lib/systemd/system/atop-rotate.service 60 | install -Dp -m 0644 atop-rotate.timer $RPM_BUILD_ROOT/usr/lib/systemd/system/atop-rotate.timer 61 | install -Dp -m 0644 atopacct.service $RPM_BUILD_ROOT/usr/lib/systemd/system/atopacct.service 62 | install -Dp -m 0644 atopgpu.service $RPM_BUILD_ROOT/usr/lib/systemd/system/atopgpu.service 63 | install -Dp -m 0711 atop-pm.sh $RPM_BUILD_ROOT/usr/lib/systemd/system-sleep/atop-pm.sh 64 | 65 | %clean 66 | rm -rf $RPM_BUILD_ROOT 67 | 68 | %post 69 | # save today's logfile (format might be incompatible) 70 | mv /var/log/atop/atop_`date +%Y%m%d` /var/log/atop/atop_`date +%Y%m%d`.save \ 71 | 2> /dev/null || : 72 | 73 | /bin/systemctl daemon-reload 74 | /bin/systemctl enable atopacct 75 | /bin/systemctl enable atop 76 | /bin/systemctl enable atop-rotate.timer 77 | 78 | %preun 79 | if [ $1 -eq 0 ] 80 | then 81 | /bin/systemctl disable --now atop 82 | /bin/systemctl disable --now atopacct 83 | /bin/systemctl disable --now atopgpu 84 | /bin/systemctl disable --now atop-rotate.timer 85 | fi 86 | 87 | # atop-XVERSX and atopsar-XVERSX will remain for old logfiles 88 | cp -f /usr/bin/atop /usr/bin/atop-XVERSX 89 | ln -sf /usr/bin/atop-XVERSX /usr/bin/atopsar-XVERSX 90 | 91 | %files 92 | %defattr(-,root,root) 93 | %doc README COPYING AUTHORS ChangeLog 94 | /usr/bin/atop 95 | /usr/bin/atopconvert 96 | /usr/bin/atopcat 97 | /usr/bin/atophide 98 | /usr/bin/atopsar 99 | /usr/sbin/atopacctd 100 | /usr/sbin/atopgpud 101 | /usr/share/man/man1/atop.1* 102 | /usr/share/man/man1/atopsar.1* 103 | /usr/share/man/man1/atopconvert.1* 104 | /usr/share/man/man1/atopcat.1* 105 | /usr/share/man/man1/atophide.1* 106 | /usr/share/man/man5/atoprc.5* 107 | /usr/share/man/man8/atopacctd.8* 108 | /usr/share/man/man8/atopgpud.8* 109 | /usr/lib/systemd/system/atop.service 110 | /usr/lib/systemd/system/atop-rotate.service 111 | /usr/lib/systemd/system/atop-rotate.timer 112 | /usr/lib/systemd/system/atopacct.service 113 | /usr/lib/systemd/system/atopgpu.service 114 | /usr/lib/systemd/system-sleep/atop-pm.sh 115 | %config(noreplace) /etc/default/atop 116 | %dir /var/log/atop/ 117 | -------------------------------------------------------------------------------- /prev/photoproc_206.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_26 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_26 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | 31 | int ctid; /* OpenVZ container ID */ 32 | int vpid; /* OpenVZ virtual PID */ 33 | 34 | int wasinactive; /* boolean: task inactive */ 35 | 36 | char container[16]; /* Docker container id (12 pos) */ 37 | } gen; 38 | 39 | /* CPU STATISTICS */ 40 | struct cpu_26 { 41 | count_t utime; /* time user text (ticks) */ 42 | count_t stime; /* time system text (ticks) */ 43 | int nice; /* nice value */ 44 | int prio; /* priority */ 45 | int rtprio; /* realtime priority */ 46 | int policy; /* scheduling policy */ 47 | int curcpu; /* current processor */ 48 | int sleepavg; /* sleep average percentage */ 49 | int ifuture[4]; /* reserved for future use */ 50 | char wchan[16]; /* wait channel string */ 51 | count_t rundelay; /* schedstat rundelay (nanosec) */ 52 | count_t cfuture[1]; /* reserved for future use */ 53 | } cpu; 54 | 55 | /* DISK STATISTICS */ 56 | struct dsk_26 { 57 | count_t rio; /* number of read requests */ 58 | count_t rsz; /* cumulative # sectors read */ 59 | count_t wio; /* number of write requests */ 60 | count_t wsz; /* cumulative # sectors written */ 61 | count_t cwsz; /* cumulative # written sectors */ 62 | /* being cancelled */ 63 | count_t cfuture[4]; /* reserved for future use */ 64 | } dsk; 65 | 66 | /* MEMORY STATISTICS */ 67 | struct mem_26 { 68 | count_t minflt; /* number of page-reclaims */ 69 | count_t majflt; /* number of page-faults */ 70 | count_t vexec; /* virtmem execfile (Kb) */ 71 | count_t vmem; /* virtual memory (Kb) */ 72 | count_t rmem; /* resident memory (Kb) */ 73 | count_t pmem; /* resident memory (Kb) */ 74 | count_t vgrow; /* virtual growth (Kb) */ 75 | count_t rgrow; /* resident growth (Kb) */ 76 | count_t vdata; /* virtmem data (Kb) */ 77 | count_t vstack; /* virtmem stack (Kb) */ 78 | count_t vlibs; /* virtmem libexec (Kb) */ 79 | count_t vswap; /* swap space used (Kb) */ 80 | count_t vlock; /* virtual locked (Kb) */ 81 | count_t cfuture[3]; /* reserved for future use */ 82 | } mem; 83 | 84 | /* NETWORK STATISTICS */ 85 | struct net_26 { 86 | count_t tcpsnd; /* number of TCP-packets sent */ 87 | count_t tcpssz; /* cumulative size packets sent */ 88 | count_t tcprcv; /* number of TCP-packets recved */ 89 | count_t tcprsz; /* cumulative size packets rcvd */ 90 | count_t udpsnd; /* number of UDP-packets sent */ 91 | count_t udpssz; /* cumulative size packets sent */ 92 | count_t udprcv; /* number of UDP-packets recved */ 93 | count_t udprsz; /* cumulative size packets sent */ 94 | count_t avail1; /* */ 95 | count_t avail2; /* */ 96 | count_t cfuture[4]; /* reserved for future use */ 97 | } net; 98 | 99 | struct gpu_26 { 100 | char state; // A - active, E - Exit, '\0' - no use 101 | char cfuture[3]; // 102 | short nrgpus; // number of GPUs for this process 103 | int32_t gpulist; // bitlist with GPU numbers 104 | 105 | int gpubusy; // gpu busy perc process lifetime -1 = n/a 106 | int membusy; // memory busy perc process lifetime -1 = n/a 107 | count_t timems; // milliseconds accounting -1 = n/a 108 | // value 0 for active process, 109 | // value > 0 after termination 110 | 111 | count_t memnow; // current memory consumption in KiB 112 | count_t memcum; // cumulative memory consumption in KiB 113 | count_t sample; // number of samples 114 | } gpu; 115 | }; 116 | -------------------------------------------------------------------------------- /prev/photoproc_207.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_27 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_27 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | 31 | int ctid; /* OpenVZ container ID */ 32 | int vpid; /* OpenVZ virtual PID */ 33 | 34 | int wasinactive; /* boolean: task inactive */ 35 | 36 | char container[16]; /* Docker container id (12 pos) */ 37 | } gen; 38 | 39 | /* CPU STATISTICS */ 40 | struct cpu_27 { 41 | count_t utime; /* time user text (ticks) */ 42 | count_t stime; /* time system text (ticks) */ 43 | int nice; /* nice value */ 44 | int prio; /* priority */ 45 | int rtprio; /* realtime priority */ 46 | int policy; /* scheduling policy */ 47 | int curcpu; /* current processor */ 48 | int sleepavg; /* sleep average percentage */ 49 | int ifuture[4]; /* reserved for future use */ 50 | char wchan[16]; /* wait channel string */ 51 | count_t rundelay; /* schedstat rundelay (nanosec) */ 52 | count_t cfuture[1]; /* reserved for future use */ 53 | } cpu; 54 | 55 | /* DISK STATISTICS */ 56 | struct dsk_27 { 57 | count_t rio; /* number of read requests */ 58 | count_t rsz; /* cumulative # sectors read */ 59 | count_t wio; /* number of write requests */ 60 | count_t wsz; /* cumulative # sectors written */ 61 | count_t cwsz; /* cumulative # written sectors */ 62 | /* being cancelled */ 63 | count_t cfuture[4]; /* reserved for future use */ 64 | } dsk; 65 | 66 | /* MEMORY STATISTICS */ 67 | struct mem_27 { 68 | count_t minflt; /* number of page-reclaims */ 69 | count_t majflt; /* number of page-faults */ 70 | count_t vexec; /* virtmem execfile (Kb) */ 71 | count_t vmem; /* virtual memory (Kb) */ 72 | count_t rmem; /* resident memory (Kb) */ 73 | count_t pmem; /* resident memory (Kb) */ 74 | count_t vgrow; /* virtual growth (Kb) */ 75 | count_t rgrow; /* resident growth (Kb) */ 76 | count_t vdata; /* virtmem data (Kb) */ 77 | count_t vstack; /* virtmem stack (Kb) */ 78 | count_t vlibs; /* virtmem libexec (Kb) */ 79 | count_t vswap; /* swap space used (Kb) */ 80 | count_t vlock; /* virtual locked (Kb) */ 81 | count_t cfuture[3]; /* reserved for future use */ 82 | } mem; 83 | 84 | /* NETWORK STATISTICS */ 85 | struct net_27 { 86 | count_t tcpsnd; /* number of TCP-packets sent */ 87 | count_t tcpssz; /* cumulative size packets sent */ 88 | count_t tcprcv; /* number of TCP-packets recved */ 89 | count_t tcprsz; /* cumulative size packets rcvd */ 90 | count_t udpsnd; /* number of UDP-packets sent */ 91 | count_t udpssz; /* cumulative size packets sent */ 92 | count_t udprcv; /* number of UDP-packets recved */ 93 | count_t udprsz; /* cumulative size packets sent */ 94 | count_t avail1; /* */ 95 | count_t avail2; /* */ 96 | count_t cfuture[4]; /* reserved for future use */ 97 | } net; 98 | 99 | struct gpu_27 { 100 | char state; // A - active, E - Exit, '\0' - no use 101 | char cfuture[3]; // 102 | short nrgpus; // number of GPUs for this process 103 | int32_t gpulist; // bitlist with GPU numbers 104 | 105 | int gpubusy; // gpu busy perc process lifetime -1 = n/a 106 | int membusy; // memory busy perc process lifetime -1 = n/a 107 | count_t timems; // milliseconds accounting -1 = n/a 108 | // value 0 for active process, 109 | // value > 0 after termination 110 | 111 | count_t memnow; // current memory consumption in KiB 112 | count_t memcum; // cumulative memory consumption in KiB 113 | count_t sample; // number of samples 114 | } gpu; 115 | }; 116 | -------------------------------------------------------------------------------- /man/atopacctd.8: -------------------------------------------------------------------------------- 1 | .TH ATOPACCTD 8 "January 2024" "Linux" 2 | .SH NAME 3 | .B atopacctd 4 | - process accounting daemon 5 | .SH SYNOPSIS 6 | .P 7 | .B atopacctd 8 | [-v | topdirectory] 9 | .P 10 | .SH DESCRIPTION 11 | The 12 | .I atopacctd 13 | daemon switches on the process accounting feature in the kernel 14 | and let the process accounting records be written to a file, 15 | called the source file from now. 16 | After process accounting is activated, the 17 | .I atopacctd 18 | daemon transfers every process accounting record that is available 19 | in the source file to a shadow file. 20 | Client processes (like 21 | .I atop 22 | processes) will read the shadow files instead of the 23 | process accounting source file. 24 | .br 25 | In this way, the 26 | .I atopacctd 27 | daemon operates as a 'layer' between the process accounting file 28 | that is written by the kernel and the shadow accounting files that are read by 29 | .I atop 30 | processes. 31 | .PP 32 | This approach has the following advantages: 33 | .PP 34 | .TP 3 35 | .B o 36 | The 37 | .I atopacctd 38 | daemon takes care that the source file is kept to a limited size. 39 | As soon as its maximum size is reached, it is truncated to a size 40 | of zero again (this is not noticed by the 41 | .I atop 42 | processes). 43 | .PP 44 | .TP 3 45 | .B o 46 | The 47 | .I atopacct 48 | daemon takes care that a shadow file is kept to a limited size. 49 | As soon as the current shadow file reaches this maximum size, the 50 | .I atopacctd 51 | daemon creates a new (subsequent) shadow file. 52 | While client processes still have the possibility to read the previous 53 | shadow file(s), the 54 | .I atopacctd 55 | daemon continues writing accounting records to the newest (current) 56 | shadow file. 57 | For this reason, the name of a shadow file consists of a 10-digit 58 | sequence number followed by the extension '.paf' (process acounting file). 59 | Old shadow files that are not used by client processes any more, are 60 | automatically removed by the garbage collector in the 61 | .I atopacctd 62 | daemon. 63 | .PP 64 | .TP 3 65 | .B o 66 | When no client processes are active (any more), all shadow files 67 | will be deleted and no records will be transferred to a shadow file 68 | any more. As soon as at least one client is activate again, the 69 | .I atopacctd 70 | daemon continues writing shadow files. 71 | .PP 72 | The directory 73 | .B /var/run 74 | is used as the default topdirectory. 75 | Below this top-directory, the source file 76 | .B pacct_source 77 | is created to which the kernel writes the process accounting records. 78 | .br 79 | Furthermore, the subdirectory 80 | .B pacct_shadow.d 81 | is created as a 'container' for the shadow files. 82 | Apart from the shadow files, also the file 83 | .B current 84 | is maintained in this subdirectory, containing the sequence number of the 85 | current (newest) shadow file and the maximum number of records that will be 86 | written in each shadow file. 87 | .PP 88 | An alternative topdirectory can be specified as command line argument. 89 | When an alternative topdirectory is defined, also modify the 90 | configuration file 91 | .B /etc/atoprc 92 | to inform 93 | .I atop 94 | clients about this alternative location (see the 95 | .B atoprc 96 | man page). 97 | Such alternative topdirectory should be owned by root and may not be 98 | writable for the group or others (security reasons). 99 | .PP 100 | Notice that the kernel suspends writing process accounting records 101 | when the free space of the filesystem on which the process accounting file 102 | resides drops below 2%. Writing is resumed when the free space is 4% or more. 103 | These lowwater and highwater percentages can be configured via the 104 | .B /proc/sys/kernel/acct 105 | pseudo-file. 106 | .br 107 | The 108 | .I atopacctd 109 | daemon suspends transferring process accounting records to shadow files 110 | when the free space of the filesystem on which the process accounting file 111 | resides drops below 5%. Transfer is resumed when the free space is 5% or more. 112 | Log messages are generated via syslog when writing to the current shadow 113 | file is suspended or resumed. 114 | .PP 115 | The 116 | .B -v 117 | flag can be used to verify the version of the 118 | .I atopacctd 119 | daemon. 120 | .PP 121 | .SH FILES 122 | .PP 123 | .TP 5 124 | .B /var/run/pacct_source 125 | Regular file to which the kernel writes the process accounting records. 126 | This file will be regularly truncated. 127 | .PP 128 | .TP 5 129 | .B /var/run/pacct_shadow.d/current 130 | Regular file containing the sequence number of the current shadow file 131 | and the maximum number of records per shadow file. 132 | .PP 133 | .TP 5 134 | .B /var/run/pacct_shadow.d/N.paf 135 | Regular files containing the process accounting records that have 136 | been copied transparently from the source file (N represents a 10-digit 137 | sequence number). 138 | .SH SEE ALSO 139 | .B atop(1), 140 | .B atopsar(1), 141 | .B atoprc(5), 142 | .B netatop(4), 143 | .B netatopd(8) 144 | .br 145 | .B https://www.atoptool.nl 146 | .SH AUTHOR 147 | Gerlof Langeveld (gerlof.langeveld@atoptool.nl) 148 | -------------------------------------------------------------------------------- /cgroups.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** 7 | ** Include-file describing cgroup-level counters to be maintained. 8 | ** ================================================================ 9 | ** Author: Gerlof Langeveld 10 | ** E-mail: gerlof.langeveld@atoptool.nl 11 | ** Date: January/February 2024 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | */ 23 | 24 | #ifndef __CGROUPS__ 25 | #define __CGROUPS__ 26 | 27 | // structure containing general info and metrics per cgroup (directory) 28 | // 29 | struct cstat { 30 | // GENERAL INFO 31 | struct cggen { 32 | int structlen; // struct length including rounded name 33 | int sequence; // sequence number in chain/array 34 | int parentseq; // parent sequence number in chain/array 35 | int depth; // cgroup tree depth starting from 0 36 | int nprocs; // number of processes in cgroup 37 | int procsbelow; // number of processes in cgroups below 38 | int namelen; // cgroup name length (at end of struct) 39 | int fullnamelen; // cgroup path length 40 | int ifuture[4]; 41 | 42 | long namehash; // cgroup name hash of 43 | // full path name excluding slashes 44 | long lfuture[4]; 45 | } gen; 46 | 47 | // CONFIGURATION INFO 48 | struct cgconf { 49 | int cpuweight; // -1=max, -2=undefined 50 | int cpumax; // -1=max, -2=undefined (perc) 51 | 52 | count_t memmax; // -1=max, -2=undefined (pages) 53 | count_t swpmax; // -1=max, -2=undefined (pages) 54 | 55 | int dskweight; // -1=max, -2=undefined 56 | 57 | int ifuture[5]; 58 | count_t cfuture[5]; 59 | } conf; 60 | 61 | // CPU STATISTICS 62 | struct cgcpu { 63 | count_t utime; // time user text (usec) -1=undefined 64 | count_t stime; // time system text (usec) -1=undefined 65 | 66 | count_t somepres; // some pressure (microsec) 67 | count_t fullpres; // full pressure (microsec) 68 | 69 | count_t cfuture[5]; 70 | } cpu; 71 | 72 | // MEMORY STATISTICS 73 | struct cgmem { 74 | count_t current; // current memory (pages) -1=undefined 75 | count_t anon; // anonymous memory (pages) -1=undefined 76 | count_t file; // file memory (pages) -1=undefined 77 | count_t kernel; // kernel memory (pages) -1=undefined 78 | count_t shmem; // shared memory (pages) -1=undefined 79 | 80 | count_t somepres; // some pressure (microsec) 81 | count_t fullpres; // full pressure (microsec) 82 | 83 | count_t cfuture[5]; 84 | } mem; 85 | 86 | // DISK I/O STATISTICS 87 | struct cgdsk { 88 | count_t rbytes; // total bytes read on all physical disks 89 | count_t wbytes; // total bytes written on all physical disks 90 | count_t rios; // total read I/Os on all physical disks 91 | count_t wios; // total write I/Os on all physical disks 92 | 93 | count_t somepres; // some pressure (microsec) 94 | count_t fullpres; // full pressure (microsec) 95 | 96 | count_t cfuture[5]; 97 | } dsk; 98 | 99 | // cgroup name with variable length 100 | char cgname[]; 101 | }; 102 | 103 | // structure to be used for chaining the cstat struct and pid list 104 | // that are maintained per cgroup 105 | // 106 | struct cgchainer { 107 | struct cgchainer *next; 108 | struct cgchainer *hashnext; 109 | 110 | struct cstat *cstat; // cgroup info and stats 111 | pid_t *proclist; // PID list of cgroup 112 | 113 | unsigned long vlinemask; // bit list for tree drawing: 114 | // bit '1' for continuous line 115 | char stub; // boolean for tree drawing: 116 | // true means corner 117 | }; 118 | 119 | #define CGRMAXDEPTH (sizeof(unsigned long)*8) // #bits in vlinemask 120 | 121 | // structure to be used for printing a merged list 122 | // of cgroups and processes 123 | // 124 | struct tstat; 125 | 126 | struct cglinesel { 127 | struct cgchainer *cgp; // always filled with reference to cgroup 128 | struct tstat *tsp; // filled for process info, otherwise NULL 129 | }; 130 | 131 | int mergecgrouplist(struct cglinesel **, int, 132 | struct cgchainer **, int, 133 | struct tstat **, int, char); 134 | 135 | int cgroupv2support(void); 136 | void photocgroup(void); 137 | int deviatcgroup(struct cgchainer **, int *); 138 | struct cgchainer **cgsort(struct cgchainer *, int, char); 139 | char *cggetpath(struct cgchainer *, struct cgchainer *, int); 140 | void cgwipecur(void); 141 | void cgbuildarray(struct cgchainer **, char *, char *, int); 142 | void cgfillref(struct devtstat *, struct cgchainer *, int, int); 143 | 144 | 145 | #endif 146 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [atop](http://www.atoptool.nl) 2 | ============================== 3 | 4 | Created/maintained by Gerlof Langeveld 5 | 6 | ## Introduction 7 | 8 | 9 | 10 | Atop is an ASCII full-screen performance monitor for Linux that is capable 11 | of reporting the activity of all processes (even if processes have finished 12 | during the interval), daily logging of system and process activity for 13 | long-term analysis, highlighting overloaded system resources by using colors, 14 | etcetera. At regular intervals, it shows system-level activity related to the 15 | CPU, memory, swap, disks (including LVM) and network layers, and for every 16 | process (and thread) it shows e.g. the CPU utilization, memory growth, 17 | disk utilization, priority, username, state, and exit code. 18 | In combination with the optional kernel module *netatop*, 19 | it even shows network activity per process/thread. 20 | In combination with the optional daemon *atopgpud*, 21 | it also shows GPU activity on system level and process level. 22 | Furthermore cgroup-level resource consumption can be shown, optionally 23 | with the processes contained by these cgroups. 24 | 25 | ## Highlights 26 | 27 | The command atop has some major advantages compared to other performance monitoring tools: 28 | 29 | * __Text mode for details and bar graph mode for global overview.__ 30 | In *text mode* details are shown about the utilization of system resources and the resource consumption by processes. 31 | In *bar graph mode* a (character-based) graphical overview is given about the utilization of the processors, disks, 32 | network interfaces and memory on system level. 33 | 34 | * __Cgroups overview.__ 35 | In *text mode* the cgroups hierarchy can be shown with the utilization of CPU, memory and disk resources 36 | and the processes contained by these cgroups. 37 | 38 | * __Resource consumption by *all* processes.__ 39 | It shows the resource consumption by all processes that were active during the interval, so also the resource consumption by those processes that have finished during the interval. 40 | 41 | * __Utilization of *all* relevant resources.__ 42 | Obviously it shows system-level counters concerning utilization of cpu and memory/swap, however it also shows disk I/O and network utilization counters on system level. 43 | 44 | * __Permanent logging of resource utilization.__ 45 | It is able to store raw counters in a file for long-term analysis on system level and process level. These raw counters are compressed at the moment of writing to minimize disk space usage. By default, the daily logfiles are preserved for 28 days. 46 | System activity reports can be generated from a logfile by using the atopsar command. 47 | 48 | * __Highlight critical resources.__ 49 | It highlights resources that have (almost) reached a critical load by using colors for the system statistics. 50 | 51 | * __Scalable window width.__ 52 | It is able to add or remove columns dynamically at the moment that you enlarge or shrink the width of your window. 53 | 54 | * __Resource consumption by individual *threads*.__ 55 | It is able to show the resource consumption for each thread within a process. 56 | 57 | * __Watch activity only.__ 58 | By default, it only shows system resources and processes that were really active during the last interval, so output related to resources or processes that were completely passive during the interval is by default suppressed. 59 | 60 | * __Watch deviations only.__ 61 | For the active system resources and processes, only the load during the last interval is shown (not the accumulated utilization since system boot or process startup). 62 | 63 | * __Accumulated process activity per user.__ 64 | For each interval, it is able to accumulate the resource consumption for all processes per user. 65 | 66 | * __Accumulated process activity per program.__ 67 | For each interval, it is able to accumulate the resource consumption for all processes with the same name. 68 | 69 | * __Accumulated process activity per container.__ 70 | For each interval, it is able to accumulate the resource consumption for all processes within the same container. 71 | 72 | * __Network activity per process.__ 73 | In combination with the optional kernel module [netatop](https://www.atoptool.nl/downloadnetatop.php) or the BPF module [netatop-bpf](https://github.com/bytedance/netatop-bpf), it shows process-level counters concerning the number of TCP and UDP packets transferred, and the consumed network bandwidth per process. 74 | 75 | * __GPU activity on system level and per process.__ 76 | In combination with the optional daemon atopgpud, it shows system-level and process-level counters concerning the load and memory utilization per GPU. 77 | 78 | ## Links 79 | 80 | * A [Cheatsheet](https://www.atoptool.nl/download/ATOP-cheatsheet-keys.pdf) for key usage within atop 81 | * A [BPF implementation](https://github.com/bytedance/netatop-bpf) to gather network statistics per process/thread (alternative for the 'netatop' kernel module) 82 | * A [Web interface](https://github.com/pizhenwei/atophttpd) for atop 83 | * [Graphical representation of system resource utilization]( https://codeberg.org/mgellner/atopsar-plot) 84 | -------------------------------------------------------------------------------- /rawlog.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** ========================================================================== 7 | ** Author: Gerlof Langeveld 8 | ** E-mail: gerlof.langeveld@atoptool.nl 9 | ** Date: September 2002 10 | ** -------------------------------------------------------------------------- 11 | ** Copyright (C) 2000-2010 Gerlof Langeveld 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | ** 23 | ** You should have received a copy of the GNU General Public License 24 | ** along with this program; if not, write to the Free Software 25 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | ** -------------------------------------------------------------------------- 27 | */ 28 | 29 | #ifndef __RAWLOG__ 30 | #define __RAWLOG__ 31 | 32 | /* 33 | ** structure describing the raw file contents 34 | ** 35 | ** layout raw file: rawheader 36 | ** 37 | ** rawrecord \ 38 | ** compressed system-level statistics | 39 | ** compressed process-level statistics | sample 1 40 | ** compressed cgroupv2-level statistics (optional) | 41 | ** compressed cgroupv2 pidlist (optional) / 42 | ** 43 | ** rawrecord \ 44 | ** compressed system-level statistics | 45 | ** compressed process-level statistics | sample 2 46 | ** compressed cgroupv2-level statistics (optional) | 47 | ** compressed cgroupv2 pidlist (optional) / 48 | ** 49 | ** etcetera ..... 50 | */ 51 | #define MYMAGIC (unsigned int) 0xfeedbeef 52 | #define READAHEADOFF 22 53 | #define READAHEADSIZE (1 << READAHEADOFF) 54 | 55 | struct rawheader { 56 | unsigned int magic; 57 | 58 | unsigned short aversion; /* creator atop version with MSB */ 59 | unsigned short future1; /* can be reused */ 60 | unsigned short future2; /* can be reused */ 61 | unsigned short rawheadlen; /* length of struct rawheader */ 62 | unsigned short rawreclen; /* length of struct rawrecord */ 63 | unsigned short hertz; /* clock interrupts per second */ 64 | unsigned short pidwidth; /* number of digits for PID/TID */ 65 | unsigned short sfuture[5]; /* future use */ 66 | unsigned int sstatlen; /* length of struct sstat */ 67 | unsigned int tstatlen; /* length of struct tstat */ 68 | struct utsname utsname; /* info about this system */ 69 | char cfuture[8]; /* future use */ 70 | 71 | unsigned int pagesize; /* size of memory page (bytes) */ 72 | int supportflags; /* used features */ 73 | int osrel; /* OS release number */ 74 | int osvers; /* OS version number */ 75 | int ossub; /* OS version subnumber */ 76 | int cstatlen; /* length of struct cstat */ 77 | int ifuture[5]; /* future use */ 78 | }; 79 | 80 | struct rawrecord { 81 | time_t curtime; /* current time (epoch) */ 82 | 83 | unsigned short flags; /* various flags */ 84 | unsigned short ncgroups; /* number of cgroups */ 85 | unsigned short sfuture[2]; /* future use */ 86 | 87 | unsigned int scomplen; /* length of compressed sstat */ 88 | unsigned int pcomplen; /* length of compressed tstat's */ 89 | unsigned int interval; /* interval (number of seconds) */ 90 | unsigned int ndeviat; /* number of tasks in list */ 91 | unsigned int nactproc; /* number of processes in list */ 92 | unsigned int ntask; /* total number of tasks */ 93 | unsigned int totproc; /* total number of processes */ 94 | unsigned int totrun; /* number of running threads */ 95 | unsigned int totslpi; /* number of sleeping threads(S)*/ 96 | unsigned int totslpu; /* number of sleeping threads(D)*/ 97 | unsigned int totzomb; /* number of zombie processes */ 98 | unsigned int nexit; /* number of exited processes */ 99 | unsigned int noverflow; /* number of overflow processes */ 100 | unsigned int totidle; /* number of idle threads(I)*/ 101 | unsigned int ccomplen; /* length of compressed cstats */ 102 | unsigned int coriglen; /* length of original cstats */ 103 | unsigned int ncgpids; /* number of cgroups pidlist */ 104 | unsigned int icomplen; /* length of compressed pidlist */ 105 | unsigned int ifuture; /* future use */ 106 | }; 107 | #endif 108 | -------------------------------------------------------------------------------- /netstats.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** ========================================================================== 7 | ** Author: Gerlof Langeveld 8 | ** E-mail: gerlof.langeveld@atoptool.nl 9 | ** Date: September 2002 10 | ** -------------------------------------------------------------------------- 11 | ** Copyright (C) 2000-2010 Gerlof Langeveld 12 | ** 13 | ** This program is free software; you can redistribute it and/or modify it 14 | ** under the terms of the GNU General Public License as published by the 15 | ** Free Software Foundation; either version 2, or (at your option) any 16 | ** later version. 17 | ** 18 | ** This program is distributed in the hope that it will be useful, but 19 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ** See the GNU General Public License for more details. 22 | ** 23 | ** You should have received a copy of the GNU General Public License 24 | ** along with this program; if not, write to the Free Software 25 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | ** -------------------------------------------------------------------------- 27 | */ 28 | 29 | #ifndef __NETSTATS__ 30 | #define __NETSTATS__ 31 | 32 | /* 33 | ** structures defined from the output of /proc/net/snmp and /proc/net/snmp6 34 | */ 35 | struct ipv4_stats { 36 | count_t Forwarding; 37 | count_t DefaultTTL; 38 | count_t InReceives; 39 | count_t InHdrErrors; 40 | count_t InAddrErrors; 41 | count_t ForwDatagrams; 42 | count_t InUnknownProtos; 43 | count_t InDiscards; 44 | count_t InDelivers; 45 | count_t OutRequests; 46 | count_t OutDiscards; 47 | count_t OutNoRoutes; 48 | count_t ReasmTimeout; 49 | count_t ReasmReqds; 50 | count_t ReasmOKs; 51 | count_t ReasmFails; 52 | count_t FragOKs; 53 | count_t FragFails; 54 | count_t FragCreates; 55 | }; 56 | 57 | struct icmpv4_stats { 58 | count_t InMsgs; 59 | count_t InErrors; 60 | count_t InCsumErrors; 61 | count_t InDestUnreachs; 62 | count_t InTimeExcds; 63 | count_t InParmProbs; 64 | count_t InSrcQuenchs; 65 | count_t InRedirects; 66 | count_t InEchos; 67 | count_t InEchoReps; 68 | count_t InTimestamps; 69 | count_t InTimestampReps; 70 | count_t InAddrMasks; 71 | count_t InAddrMaskReps; 72 | count_t OutMsgs; 73 | count_t OutErrors; 74 | count_t OutDestUnreachs; 75 | count_t OutTimeExcds; 76 | count_t OutParmProbs; 77 | count_t OutSrcQuenchs; 78 | count_t OutRedirects; 79 | count_t OutEchos; 80 | count_t OutEchoReps; 81 | count_t OutTimestamps; 82 | count_t OutTimestampReps; 83 | count_t OutAddrMasks; 84 | count_t OutAddrMaskReps; 85 | }; 86 | 87 | struct udpv4_stats { 88 | count_t InDatagrams; 89 | count_t NoPorts; 90 | count_t InErrors; 91 | count_t OutDatagrams; 92 | }; 93 | 94 | struct tcp_stats { 95 | count_t RtoAlgorithm; 96 | count_t RtoMin; 97 | count_t RtoMax; 98 | count_t MaxConn; 99 | count_t ActiveOpens; 100 | count_t PassiveOpens; 101 | count_t AttemptFails; 102 | count_t EstabResets; 103 | count_t CurrEstab; 104 | count_t InSegs; 105 | count_t OutSegs; 106 | count_t RetransSegs; 107 | count_t InErrs; 108 | count_t OutRsts; 109 | count_t InCsumErrors; 110 | }; 111 | 112 | struct ipv6_stats { 113 | count_t Ip6InReceives; 114 | count_t Ip6InHdrErrors; 115 | count_t Ip6InTooBigErrors; 116 | count_t Ip6InNoRoutes; 117 | count_t Ip6InAddrErrors; 118 | count_t Ip6InUnknownProtos; 119 | count_t Ip6InTruncatedPkts; 120 | count_t Ip6InDiscards; 121 | count_t Ip6InDelivers; 122 | count_t Ip6OutForwDatagrams; 123 | count_t Ip6OutRequests; 124 | count_t Ip6OutDiscards; 125 | count_t Ip6OutNoRoutes; 126 | count_t Ip6ReasmTimeout; 127 | count_t Ip6ReasmReqds; 128 | count_t Ip6ReasmOKs; 129 | count_t Ip6ReasmFails; 130 | count_t Ip6FragOKs; 131 | count_t Ip6FragFails; 132 | count_t Ip6FragCreates; 133 | count_t Ip6InMcastPkts; 134 | count_t Ip6OutMcastPkts; 135 | }; 136 | 137 | struct icmpv6_stats { 138 | count_t Icmp6InMsgs; 139 | count_t Icmp6InErrors; 140 | count_t Icmp6InDestUnreachs; 141 | count_t Icmp6InPktTooBigs; 142 | count_t Icmp6InTimeExcds; 143 | count_t Icmp6InParmProblems; 144 | count_t Icmp6InEchos; 145 | count_t Icmp6InEchoReplies; 146 | count_t Icmp6InGroupMembQueries; 147 | count_t Icmp6InGroupMembResponses; 148 | count_t Icmp6InGroupMembReductions; 149 | count_t Icmp6InRouterSolicits; 150 | count_t Icmp6InRouterAdvertisements; 151 | count_t Icmp6InNeighborSolicits; 152 | count_t Icmp6InNeighborAdvertisements; 153 | count_t Icmp6InRedirects; 154 | count_t Icmp6OutMsgs; 155 | count_t Icmp6OutDestUnreachs; 156 | count_t Icmp6OutPktTooBigs; 157 | count_t Icmp6OutTimeExcds; 158 | count_t Icmp6OutParmProblems; 159 | count_t Icmp6OutEchoReplies; 160 | count_t Icmp6OutRouterSolicits; 161 | count_t Icmp6OutNeighborSolicits; 162 | count_t Icmp6OutNeighborAdvertisements; 163 | count_t Icmp6OutRedirects; 164 | count_t Icmp6OutGroupMembResponses; 165 | count_t Icmp6OutGroupMembReductions; 166 | }; 167 | 168 | struct udpv6_stats { 169 | count_t Udp6InDatagrams; 170 | count_t Udp6NoPorts; 171 | count_t Udp6InErrors; 172 | count_t Udp6OutDatagrams; 173 | }; 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /prev/photoproc_211.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_211 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_211 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | int nthridle; /* # threads in state 'I' */ 31 | 32 | int ctid; /* OpenVZ container ID */ 33 | int vpid; /* OpenVZ virtual PID */ 34 | 35 | int wasinactive; /* boolean: task inactive */ 36 | 37 | char utsname[UTSLEN+1];/* UTS name container or pod */ 38 | 39 | int cgroupix; /* index in devchain -1=invalid */ 40 | /* lazy filling (parsable/json) */ 41 | int ifuture[4]; /* reserved for future use */ 42 | } gen; 43 | 44 | /* CPU STATISTICS */ 45 | struct cpu_211 { 46 | count_t utime; /* time user text (ticks) */ 47 | count_t stime; /* time system text (ticks) */ 48 | int nice; /* nice value */ 49 | int prio; /* priority */ 50 | int rtprio; /* realtime priority */ 51 | int policy; /* scheduling policy */ 52 | int curcpu; /* current processor */ 53 | int sleepavg; /* sleep average percentage */ 54 | int ifuture[6]; /* reserved for future use */ 55 | char wchan[16]; /* wait channel string */ 56 | count_t rundelay; /* schedstat rundelay (nanosec) */ 57 | count_t blkdelay; /* blkio delay (ticks) */ 58 | count_t nvcsw; /* voluntary cxt switch counts */ 59 | count_t nivcsw; /* involuntary csw counts */ 60 | count_t cfuture[3]; /* reserved for future use */ 61 | } cpu; 62 | 63 | /* DISK STATISTICS */ 64 | struct dsk_211 { 65 | count_t rio; /* number of read requests */ 66 | count_t rsz; /* cumulative # sectors read */ 67 | count_t wio; /* number of write requests */ 68 | count_t wsz; /* cumulative # sectors written */ 69 | count_t cwsz; /* cumulative # written sectors */ 70 | /* being cancelled */ 71 | count_t cfuture[4]; /* reserved for future use */ 72 | } dsk; 73 | 74 | /* MEMORY STATISTICS */ 75 | struct mem_211 { 76 | count_t minflt; /* number of page-reclaims */ 77 | count_t majflt; /* number of page-faults */ 78 | count_t vexec; /* virtmem execfile (Kb) */ 79 | count_t vmem; /* virtual memory (Kb) */ 80 | count_t rmem; /* resident memory (Kb) */ 81 | count_t pmem; /* resident memory (Kb) */ 82 | count_t vgrow; /* virtual growth (Kb) */ 83 | count_t rgrow; /* resident growth (Kb) */ 84 | count_t vdata; /* virtmem data (Kb) */ 85 | count_t vstack; /* virtmem stack (Kb) */ 86 | count_t vlibs; /* virtmem libexec (Kb) */ 87 | count_t vswap; /* swap space used (Kb) */ 88 | count_t vlock; /* virtual locked (Kb) */ 89 | count_t cfuture[7]; /* reserved for future use */ 90 | } mem; 91 | 92 | /* NETWORK STATISTICS */ 93 | struct net_211 { 94 | count_t tcpsnd; /* number of TCP-packets sent */ 95 | count_t tcpssz; /* cumulative size packets sent */ 96 | count_t tcprcv; /* number of TCP-packets recved */ 97 | count_t tcprsz; /* cumulative size packets rcvd */ 98 | count_t udpsnd; /* number of UDP-packets sent */ 99 | count_t udpssz; /* cumulative size packets sent */ 100 | count_t udprcv; /* number of UDP-packets recved */ 101 | count_t udprsz; /* cumulative size packets sent */ 102 | count_t avail1; /* */ 103 | count_t avail2; /* */ 104 | count_t cfuture[4]; /* reserved for future use */ 105 | } net; 106 | 107 | struct gpu_211 { 108 | char state; // A - active, E - Exit, '\0' - no use 109 | char bfuture[3]; // 110 | short nrgpus; // number of GPUs for this process 111 | int32_t gpulist; // bitlist with GPU numbers 112 | 113 | int gpubusy; // gpu busy perc process lifetime -1 = n/a 114 | int membusy; // memory busy perc process lifetime -1 = n/a 115 | count_t timems; // milliseconds accounting -1 = n/a 116 | // value 0 for active process, 117 | // value > 0 after termination 118 | 119 | count_t memnow; // current memory consumption in KiB 120 | count_t memcum; // cumulative memory consumption in KiB 121 | count_t sample; // number of samples 122 | count_t cfuture[3]; // 123 | } gpu; 124 | }; 125 | -------------------------------------------------------------------------------- /prev/photoproc_212.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_212 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_212 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | int nthridle; /* # threads in state 'I' */ 31 | 32 | int ctid; /* OpenVZ container ID */ 33 | int vpid; /* OpenVZ virtual PID */ 34 | 35 | int wasinactive; /* boolean: task inactive */ 36 | 37 | char utsname[UTSLEN+1];/* UTS name container or pod */ 38 | 39 | int cgroupix; /* index in devchain -1=invalid */ 40 | /* lazy filling (parsable/json) */ 41 | int ifuture[4]; /* reserved for future use */ 42 | } gen; 43 | 44 | /* CPU STATISTICS */ 45 | struct cpu_212 { 46 | count_t utime; /* time user text (ticks) */ 47 | count_t stime; /* time system text (ticks) */ 48 | int nice; /* nice value */ 49 | int prio; /* priority */ 50 | int rtprio; /* realtime priority */ 51 | int policy; /* scheduling policy */ 52 | int curcpu; /* current processor */ 53 | int sleepavg; /* sleep average percentage */ 54 | int ifuture[6]; /* reserved for future use */ 55 | char wchan[16]; /* wait channel string */ 56 | count_t rundelay; /* schedstat rundelay (nanosec) */ 57 | count_t blkdelay; /* blkio delay (ticks) */ 58 | count_t nvcsw; /* voluntary cxt switch counts */ 59 | count_t nivcsw; /* involuntary csw counts */ 60 | count_t cfuture[3]; /* reserved for future use */ 61 | } cpu; 62 | 63 | /* DISK STATISTICS */ 64 | struct dsk_212 { 65 | count_t rio; /* number of read requests */ 66 | count_t rsz; /* cumulative # sectors read */ 67 | count_t wio; /* number of write requests */ 68 | count_t wsz; /* cumulative # sectors written */ 69 | count_t cwsz; /* cumulative # written sectors */ 70 | /* being cancelled */ 71 | count_t cfuture[4]; /* reserved for future use */ 72 | } dsk; 73 | 74 | /* MEMORY STATISTICS */ 75 | struct mem_212 { 76 | count_t minflt; /* number of page-reclaims */ 77 | count_t majflt; /* number of page-faults */ 78 | count_t vexec; /* virtmem execfile (Kb) */ 79 | count_t vmem; /* virtual memory (Kb) */ 80 | count_t rmem; /* resident memory (Kb) */ 81 | count_t pmem; /* resident memory (Kb) */ 82 | count_t vgrow; /* virtual growth (Kb) */ 83 | count_t rgrow; /* resident growth (Kb) */ 84 | count_t vdata; /* virtmem data (Kb) */ 85 | count_t vstack; /* virtmem stack (Kb) */ 86 | count_t vlibs; /* virtmem libexec (Kb) */ 87 | count_t vswap; /* swap space used (Kb) */ 88 | count_t vlock; /* virtual locked (Kb) */ 89 | count_t cfuture[7]; /* reserved for future use */ 90 | } mem; 91 | 92 | /* NETWORK STATISTICS */ 93 | struct net_212 { 94 | count_t tcpsnd; /* number of TCP-packets sent */ 95 | count_t tcpssz; /* cumulative size packets sent */ 96 | count_t tcprcv; /* number of TCP-packets recved */ 97 | count_t tcprsz; /* cumulative size packets rcvd */ 98 | count_t udpsnd; /* number of UDP-packets sent */ 99 | count_t udpssz; /* cumulative size packets sent */ 100 | count_t udprcv; /* number of UDP-packets recved */ 101 | count_t udprsz; /* cumulative size packets sent */ 102 | count_t avail1; /* */ 103 | count_t avail2; /* */ 104 | count_t cfuture[4]; /* reserved for future use */ 105 | } net; 106 | 107 | struct gpu_212 { 108 | char state; // A - active, E - Exit, '\0' - no use 109 | char bfuture[3]; // 110 | short nrgpus; // number of GPUs for this process 111 | int32_t gpulist; // bitlist with GPU numbers 112 | 113 | int gpubusy; // gpu busy perc process lifetime -1 = n/a 114 | int membusy; // memory busy perc process lifetime -1 = n/a 115 | count_t timems; // milliseconds accounting -1 = n/a 116 | // value 0 for active process, 117 | // value > 0 after termination 118 | 119 | count_t memnow; // current memory consumption in KiB 120 | count_t memcum; // cumulative memory consumption in KiB 121 | count_t sample; // number of samples 122 | count_t cfuture[3]; // 123 | } gpu; 124 | }; 125 | -------------------------------------------------------------------------------- /prev/photoproc_208.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_28 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_28 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | 31 | int ctid; /* OpenVZ container ID */ 32 | int vpid; /* OpenVZ virtual PID */ 33 | 34 | int wasinactive; /* boolean: task inactive */ 35 | 36 | char container[16]; /* Docker container id (12 pos) */ 37 | char cgpath[CGRLEN]; /* cgroup v2 path name */ 38 | } gen; 39 | 40 | /* CPU STATISTICS */ 41 | struct cpu_28 { 42 | count_t utime; /* time user text (ticks) */ 43 | count_t stime; /* time system text (ticks) */ 44 | int nice; /* nice value */ 45 | int prio; /* priority */ 46 | int rtprio; /* realtime priority */ 47 | int policy; /* scheduling policy */ 48 | int curcpu; /* current processor */ 49 | int sleepavg; /* sleep average percentage */ 50 | int cgcpuweight; /* cgroup cpu.weight */ 51 | int cgcpumax; /* cgroup cpu.max percentage */ 52 | int cgcpumaxr; /* restrictive percentage */ 53 | int ifuture[3]; /* reserved for future use */ 54 | char wchan[16]; /* wait channel string */ 55 | count_t rundelay; /* schedstat rundelay (nanosec) */ 56 | count_t blkdelay; /* blkio delay (ticks) */ 57 | count_t cfuture[3]; /* reserved for future use */ 58 | } cpu; 59 | 60 | /* DISK STATISTICS */ 61 | struct dsk_28 { 62 | count_t rio; /* number of read requests */ 63 | count_t rsz; /* cumulative # sectors read */ 64 | count_t wio; /* number of write requests */ 65 | count_t wsz; /* cumulative # sectors written */ 66 | count_t cwsz; /* cumulative # written sectors */ 67 | /* being cancelled */ 68 | count_t cfuture[4]; /* reserved for future use */ 69 | } dsk; 70 | 71 | /* MEMORY STATISTICS */ 72 | struct mem_28 { 73 | count_t minflt; /* number of page-reclaims */ 74 | count_t majflt; /* number of page-faults */ 75 | count_t vexec; /* virtmem execfile (Kb) */ 76 | count_t vmem; /* virtual memory (Kb) */ 77 | count_t rmem; /* resident memory (Kb) */ 78 | count_t pmem; /* resident memory (Kb) */ 79 | count_t vgrow; /* virtual growth (Kb) */ 80 | count_t rgrow; /* resident growth (Kb) */ 81 | count_t vdata; /* virtmem data (Kb) */ 82 | count_t vstack; /* virtmem stack (Kb) */ 83 | count_t vlibs; /* virtmem libexec (Kb) */ 84 | count_t vswap; /* swap space used (Kb) */ 85 | count_t vlock; /* virtual locked (Kb) */ 86 | count_t cgmemmax; /* cgroup memory.max (Kb) */ 87 | count_t cgmemmaxr; /* restrictive memory.max (Kb) */ 88 | count_t cgswpmax; /* cgroup memory.swap.max (Kb) */ 89 | count_t cgswpmaxr; /* restrictive swap.max (Kb) */ 90 | count_t cfuture[3]; /* reserved for future use */ 91 | } mem; 92 | 93 | /* NETWORK STATISTICS */ 94 | struct net_28 { 95 | count_t tcpsnd; /* number of TCP-packets sent */ 96 | count_t tcpssz; /* cumulative size packets sent */ 97 | count_t tcprcv; /* number of TCP-packets recved */ 98 | count_t tcprsz; /* cumulative size packets rcvd */ 99 | count_t udpsnd; /* number of UDP-packets sent */ 100 | count_t udpssz; /* cumulative size packets sent */ 101 | count_t udprcv; /* number of UDP-packets recved */ 102 | count_t udprsz; /* cumulative size packets sent */ 103 | count_t avail1; /* */ 104 | count_t avail2; /* */ 105 | count_t cfuture[4]; /* reserved for future use */ 106 | } net; 107 | 108 | struct gpu_28 { 109 | char state; // A - active, E - Exit, '\0' - no use 110 | char cfuture[3]; // 111 | short nrgpus; // number of GPUs for this process 112 | int32_t gpulist; // bitlist with GPU numbers 113 | 114 | int gpubusy; // gpu busy perc process lifetime -1 = n/a 115 | int membusy; // memory busy perc process lifetime -1 = n/a 116 | count_t timems; // milliseconds accounting -1 = n/a 117 | // value 0 for active process, 118 | // value > 0 after termination 119 | 120 | count_t memnow; // current memory consumption in KiB 121 | count_t memcum; // cumulative memory consumption in KiB 122 | count_t sample; // number of samples 123 | } gpu; 124 | }; 125 | -------------------------------------------------------------------------------- /prev/photoproc_209.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_29 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_29 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | 31 | int ctid; /* OpenVZ container ID */ 32 | int vpid; /* OpenVZ virtual PID */ 33 | 34 | int wasinactive; /* boolean: task inactive */ 35 | 36 | char container[16]; /* Docker container id (12 pos) */ 37 | char cgpath[CGRLEN]; /* cgroup v2 path name */ 38 | } gen; 39 | 40 | /* CPU STATISTICS */ 41 | struct cpu_29 { 42 | count_t utime; /* time user text (ticks) */ 43 | count_t stime; /* time system text (ticks) */ 44 | int nice; /* nice value */ 45 | int prio; /* priority */ 46 | int rtprio; /* realtime priority */ 47 | int policy; /* scheduling policy */ 48 | int curcpu; /* current processor */ 49 | int sleepavg; /* sleep average percentage */ 50 | int cgcpuweight; /* cgroup cpu.weight */ 51 | int cgcpumax; /* cgroup cpu.max percentage */ 52 | int cgcpumaxr; /* restrictive percentage */ 53 | int ifuture[3]; /* reserved for future use */ 54 | char wchan[16]; /* wait channel string */ 55 | count_t rundelay; /* schedstat rundelay (nanosec) */ 56 | count_t blkdelay; /* blkio delay (ticks) */ 57 | count_t cfuture[3]; /* reserved for future use */ 58 | } cpu; 59 | 60 | /* DISK STATISTICS */ 61 | struct dsk_29 { 62 | count_t rio; /* number of read requests */ 63 | count_t rsz; /* cumulative # sectors read */ 64 | count_t wio; /* number of write requests */ 65 | count_t wsz; /* cumulative # sectors written */ 66 | count_t cwsz; /* cumulative # written sectors */ 67 | /* being cancelled */ 68 | count_t cfuture[4]; /* reserved for future use */ 69 | } dsk; 70 | 71 | /* MEMORY STATISTICS */ 72 | struct mem_29 { 73 | count_t minflt; /* number of page-reclaims */ 74 | count_t majflt; /* number of page-faults */ 75 | count_t vexec; /* virtmem execfile (Kb) */ 76 | count_t vmem; /* virtual memory (Kb) */ 77 | count_t rmem; /* resident memory (Kb) */ 78 | count_t pmem; /* resident memory (Kb) */ 79 | count_t vgrow; /* virtual growth (Kb) */ 80 | count_t rgrow; /* resident growth (Kb) */ 81 | count_t vdata; /* virtmem data (Kb) */ 82 | count_t vstack; /* virtmem stack (Kb) */ 83 | count_t vlibs; /* virtmem libexec (Kb) */ 84 | count_t vswap; /* swap space used (Kb) */ 85 | count_t vlock; /* virtual locked (Kb) */ 86 | count_t cgmemmax; /* cgroup memory.max (Kb) */ 87 | count_t cgmemmaxr; /* restrictive memory.max (Kb) */ 88 | count_t cgswpmax; /* cgroup memory.swap.max (Kb) */ 89 | count_t cgswpmaxr; /* restrictive swap.max (Kb) */ 90 | count_t cfuture[3]; /* reserved for future use */ 91 | } mem; 92 | 93 | /* NETWORK STATISTICS */ 94 | struct net_29 { 95 | count_t tcpsnd; /* number of TCP-packets sent */ 96 | count_t tcpssz; /* cumulative size packets sent */ 97 | count_t tcprcv; /* number of TCP-packets recved */ 98 | count_t tcprsz; /* cumulative size packets rcvd */ 99 | count_t udpsnd; /* number of UDP-packets sent */ 100 | count_t udpssz; /* cumulative size packets sent */ 101 | count_t udprcv; /* number of UDP-packets recved */ 102 | count_t udprsz; /* cumulative size packets sent */ 103 | count_t avail1; /* */ 104 | count_t avail2; /* */ 105 | count_t cfuture[4]; /* reserved for future use */ 106 | } net; 107 | 108 | struct gpu_29 { 109 | char state; // A - active, E - Exit, '\0' - no use 110 | char cfuture[3]; // 111 | short nrgpus; // number of GPUs for this process 112 | int32_t gpulist; // bitlist with GPU numbers 113 | 114 | int gpubusy; // gpu busy perc process lifetime -1 = n/a 115 | int membusy; // memory busy perc process lifetime -1 = n/a 116 | count_t timems; // milliseconds accounting -1 = n/a 117 | // value 0 for active process, 118 | // value > 0 after termination 119 | 120 | count_t memnow; // current memory consumption in KiB 121 | count_t memcum; // cumulative memory consumption in KiB 122 | count_t sample; // number of samples 123 | } gpu; 124 | }; 125 | -------------------------------------------------------------------------------- /netatopbpfif.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** 7 | ** This source-file contains functions to interface with the netatop-bpf 8 | ** in the kernel. This keeps track of network activity per process 9 | ** and thread, and exited process. 10 | ** ================================================================ 11 | ** Author: Ting Liu 12 | ** E-mail: liuting.0xffff@bytedance.com 13 | ** Date: 2023 14 | ** 15 | ** This program is free software; you can redistribute it and/or modify it 16 | ** under the terms of the GNU General Public License as published by the 17 | ** Free Software Foundation; either version 2, or (at your option) any 18 | ** later version. 19 | ** 20 | ** This program is distributed in the hope that it will be useful, but 21 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 22 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 | ** See the GNU General Public License for more details. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include "atop.h" 47 | #include "photoproc.h" 48 | #include "netatop.h" 49 | 50 | static int netsock = -1; 51 | 52 | static void fill_networkcnt(struct tstat *, struct tstat *, 53 | struct taskcount *); 54 | void my_handler(int); 55 | 56 | int len; 57 | struct sockaddr_un un; 58 | /* 59 | ** create a UNIX domain stream socket and 60 | ** connect the netatop-bpf userspace program 61 | */ 62 | void 63 | netatop_bpf_ipopen(void) 64 | { 65 | char *name = NETATOPBPF_SOCKET; 66 | 67 | /* create a UNIX domain stream socket */ 68 | if((netsock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) 69 | return; 70 | 71 | /* fill socket address structure with server's address */ 72 | memset(&un, 0, sizeof(un)); 73 | un.sun_family = AF_UNIX; 74 | strcpy(un.sun_path, name); 75 | len = offsetof(struct sockaddr_un, sun_path) + strlen(name); 76 | 77 | if(connect(netsock, (struct sockaddr *)&un, len) < 0) 78 | { 79 | close(netsock); 80 | return; 81 | } 82 | supportflags |= NETATOPBPF; 83 | return; 84 | } 85 | /* 86 | ** check if at this moment the netatop-bpf is loaded 87 | */ 88 | void 89 | netatop_bpf_probe(void) 90 | { 91 | /* 92 | ** check if netsock is not connect. 93 | ** if not, try to connect again. 94 | */ 95 | if (!(supportflags & NETATOPBPF)) { 96 | char *name = NETATOPBPF_SOCKET; 97 | if (!access(name,F_OK)) { 98 | netatop_bpf_ipopen(); 99 | } 100 | } 101 | } 102 | 103 | void my_handler (int param) 104 | { 105 | supportflags &= ~NETATOPBPF; 106 | close(netsock); 107 | netsock = -1; 108 | } 109 | 110 | /* the NET hash function */ 111 | GHashTable *ghash_net; 112 | 113 | void 114 | netatop_bpf_gettask() 115 | { 116 | int ret; 117 | struct netpertask npt; 118 | 119 | ghash_net = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free); 120 | 121 | /* 122 | ** get statistics of this process/thread 123 | */ 124 | signal(SIGPIPE, my_handler); 125 | if (send(netsock, &npt, sizeof(npt), 0) < 0) { 126 | supportflags &= ~NETATOPBPF; 127 | close(netsock); 128 | netsock = -1; 129 | return; 130 | } 131 | while ((ret = recv(netsock, &npt, sizeof(npt), 0)) > 0) { 132 | if (npt.id == 0) { 133 | break; 134 | } 135 | gint *key = g_new(gint, 1); 136 | *key = npt.id; 137 | struct taskcount *value = g_new(struct taskcount, 1); 138 | *value = npt.tc; 139 | g_hash_table_insert(ghash_net, key, value); 140 | } 141 | if (ret <= 0) { 142 | supportflags &= ~NETATOPBPF; 143 | close(netsock); 144 | netsock = -1; 145 | return ; 146 | } 147 | } 148 | 149 | /* 150 | ** search for relevant exited network task and 151 | ** update counters in tstat struct 152 | */ 153 | void 154 | netatop_bpf_exitfind(unsigned long key, struct tstat *dev, struct tstat *pre) 155 | { 156 | struct taskcount *tc = g_hash_table_lookup(ghash_net, &key); 157 | /* 158 | ** correct PID found 159 | */ 160 | if (tc) { 161 | if (tc->tcpsndpacks < pre->net.tcpsnd || 162 | tc->tcpsndbytes < pre->net.tcpssz || 163 | tc->tcprcvpacks < pre->net.tcprcv || 164 | tc->tcprcvbytes < pre->net.tcprsz || 165 | tc->udpsndpacks < pre->net.udpsnd || 166 | tc->udpsndbytes < pre->net.udpssz || 167 | tc->udprcvpacks < pre->net.udprcv || 168 | tc->udprcvbytes < pre->net.udprsz ) 169 | return; 170 | fill_networkcnt(dev, pre, tc); 171 | } 172 | } 173 | 174 | static void 175 | fill_networkcnt(struct tstat *dev, struct tstat *pre, struct taskcount *tc) 176 | { 177 | dev->net.tcpsnd = tc->tcpsndpacks - pre->net.tcpsnd; 178 | dev->net.tcpssz = tc->tcpsndbytes - pre->net.tcpssz; 179 | dev->net.tcprcv = tc->tcprcvpacks - pre->net.tcprcv; 180 | dev->net.tcprsz = tc->tcprcvbytes - pre->net.tcprsz; 181 | dev->net.udpsnd = tc->udpsndpacks - pre->net.udpsnd; 182 | dev->net.udpssz = tc->udpsndbytes - pre->net.udpssz; 183 | dev->net.udprcv = tc->udprcvpacks - pre->net.udprcv; 184 | dev->net.udprsz = tc->udprcvbytes - pre->net.udprsz; 185 | } 186 | -------------------------------------------------------------------------------- /prev/photoproc_210.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** structure containing only relevant process-info extracted 3 | ** from kernel's process-administration 4 | */ 5 | struct tstat_210 { 6 | /* GENERAL TASK INFO */ 7 | struct gen_210 { 8 | int tgid; /* threadgroup identification */ 9 | int pid; /* process identification */ 10 | int ppid; /* parent process identification*/ 11 | int ruid; /* real user identification */ 12 | int euid; /* eff. user identification */ 13 | int suid; /* saved user identification */ 14 | int fsuid; /* fs user identification */ 15 | int rgid; /* real group identification */ 16 | int egid; /* eff. group identification */ 17 | int sgid; /* saved group identification */ 18 | int fsgid; /* fs group identification */ 19 | int nthr; /* number of threads in tgroup */ 20 | char name[PNAMLEN+1];/* process name string */ 21 | char isproc; /* boolean: process level? */ 22 | char state; /* process state ('E' = exited) */ 23 | int excode; /* process exit status */ 24 | time_t btime; /* process start time (epoch) */ 25 | time_t elaps; /* process elaps time (hertz) */ 26 | char cmdline[CMDLEN+1];/* command-line string */ 27 | int nthrslpi; /* # threads in state 'S' */ 28 | int nthrslpu; /* # threads in state 'D' */ 29 | int nthrrun; /* # threads in state 'R' */ 30 | int nthridle; /* # threads in state 'I' */ 31 | 32 | int ctid; /* OpenVZ container ID */ 33 | int vpid; /* OpenVZ virtual PID */ 34 | 35 | int wasinactive; /* boolean: task inactive */ 36 | 37 | char utsname[UTSLEN+1];/* UTS name container or pod */ 38 | char cgpath[CGRLEN]; /* cgroup v2 path name */ 39 | } gen; 40 | 41 | /* CPU STATISTICS */ 42 | struct cpu_210 { 43 | count_t utime; /* time user text (ticks) */ 44 | count_t stime; /* time system text (ticks) */ 45 | int nice; /* nice value */ 46 | int prio; /* priority */ 47 | int rtprio; /* realtime priority */ 48 | int policy; /* scheduling policy */ 49 | int curcpu; /* current processor */ 50 | int sleepavg; /* sleep average percentage */ 51 | int cgcpuweight; /* cgroup cpu.weight */ 52 | int cgcpumax; /* cgroup cpu.max percentage */ 53 | int cgcpumaxr; /* restrictive percentage */ 54 | int ifuture[3]; /* reserved for future use */ 55 | char wchan[16]; /* wait channel string */ 56 | count_t rundelay; /* schedstat rundelay (nanosec) */ 57 | count_t blkdelay; /* blkio delay (ticks) */ 58 | count_t nvcsw; /* voluntary cxt switch counts */ 59 | count_t nivcsw; /* involuntary csw counts */ 60 | count_t cfuture[3]; /* reserved for future use */ 61 | } cpu; 62 | 63 | /* DISK STATISTICS */ 64 | struct dsk_210 { 65 | count_t rio; /* number of read requests */ 66 | count_t rsz; /* cumulative # sectors read */ 67 | count_t wio; /* number of write requests */ 68 | count_t wsz; /* cumulative # sectors written */ 69 | count_t cwsz; /* cumulative # written sectors */ 70 | /* being cancelled */ 71 | count_t cfuture[4]; /* reserved for future use */ 72 | } dsk; 73 | 74 | /* MEMORY STATISTICS */ 75 | struct mem_210 { 76 | count_t minflt; /* number of page-reclaims */ 77 | count_t majflt; /* number of page-faults */ 78 | count_t vexec; /* virtmem execfile (Kb) */ 79 | count_t vmem; /* virtual memory (Kb) */ 80 | count_t rmem; /* resident memory (Kb) */ 81 | count_t pmem; /* resident memory (Kb) */ 82 | count_t vgrow; /* virtual growth (Kb) */ 83 | count_t rgrow; /* resident growth (Kb) */ 84 | count_t vdata; /* virtmem data (Kb) */ 85 | count_t vstack; /* virtmem stack (Kb) */ 86 | count_t vlibs; /* virtmem libexec (Kb) */ 87 | count_t vswap; /* swap space used (Kb) */ 88 | count_t vlock; /* virtual locked (Kb) */ 89 | count_t cgmemmax; /* cgroup memory.max (Kb) */ 90 | count_t cgmemmaxr; /* restrictive memory.max (Kb) */ 91 | count_t cgswpmax; /* cgroup memory.swap.max (Kb) */ 92 | count_t cgswpmaxr; /* restrictive swap.max (Kb) */ 93 | count_t cfuture[3]; /* reserved for future use */ 94 | } mem; 95 | 96 | /* NETWORK STATISTICS */ 97 | struct net_210 { 98 | count_t tcpsnd; /* number of TCP-packets sent */ 99 | count_t tcpssz; /* cumulative size packets sent */ 100 | count_t tcprcv; /* number of TCP-packets recved */ 101 | count_t tcprsz; /* cumulative size packets rcvd */ 102 | count_t udpsnd; /* number of UDP-packets sent */ 103 | count_t udpssz; /* cumulative size packets sent */ 104 | count_t udprcv; /* number of UDP-packets recved */ 105 | count_t udprsz; /* cumulative size packets sent */ 106 | count_t avail1; /* */ 107 | count_t avail2; /* */ 108 | count_t cfuture[4]; /* reserved for future use */ 109 | } net; 110 | 111 | struct gpu_210 { 112 | char state; // A - active, E - Exit, '\0' - no use 113 | char cfuture[3]; // 114 | short nrgpus; // number of GPUs for this process 115 | int32_t gpulist; // bitlist with GPU numbers 116 | 117 | int gpubusy; // gpu busy perc process lifetime -1 = n/a 118 | int membusy; // memory busy perc process lifetime -1 = n/a 119 | count_t timems; // milliseconds accounting -1 = n/a 120 | // value 0 for active process, 121 | // value > 0 after termination 122 | 123 | count_t memnow; // current memory consumption in KiB 124 | count_t memcum; // cumulative memory consumption in KiB 125 | count_t sample; // number of samples 126 | } gpu; 127 | }; 128 | -------------------------------------------------------------------------------- /acctproc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** 7 | ** Include-file for process-accounting functions. 8 | ** ================================================================ 9 | ** Author: Gerlof Langeveld 10 | ** E-mail: gerlof.langeveld@atoptool.nl 11 | ** Date: November 1996 12 | ** LINUX-port: June 2000 13 | ** 14 | ** This program is free software; you can redistribute it and/or modify it 15 | ** under the terms of the GNU General Public License as published by the 16 | ** Free Software Foundation; either version 2, or (at your option) any 17 | ** later version. 18 | ** 19 | ** This program is distributed in the hope that it will be useful, but 20 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 | ** See the GNU General Public License for more details. 23 | */ 24 | 25 | #ifndef __ACCTPROC__ 26 | #define __ACCTPROC__ 27 | 28 | int acctswon(void); 29 | void acctswoff(void); 30 | unsigned long acctprocnt(void); 31 | unsigned long acctphotoproc(struct tstat *, int); 32 | void acctrepos(unsigned int); 33 | 34 | /* 35 | ** maximum number of records to be read from process accounting file 36 | ** for one sample, to avoid that atop explodes and introduces OOM killing .... 37 | ** 38 | ** the maximum is based on a limit of 50 MiB extra memory (approx. 70000 procs) 39 | */ 40 | #define MAXACCTPROCS (50*1024*1024/sizeof(struct tstat)) 41 | 42 | /* 43 | ** preferred maximum size of process accounting file (200 MiB) 44 | */ 45 | #define ACCTMAXFILESZ (200*1024*1024) 46 | 47 | /* 48 | ** alternative layout of accounting record if kernel-patch 49 | ** has been installed 50 | */ 51 | #include 52 | typedef __u16 comp_t; 53 | typedef __u32 comp2_t; 54 | #define ACCT_COMM 16 55 | 56 | struct acct_atop 57 | { 58 | char ac_flag; /* Flags */ 59 | char ac_version; /* Always set to ACCT_VERSION */ 60 | __u32 ac_pid; /* Process ID */ 61 | __u32 ac_ppid; /* Parent Process ID */ 62 | __u16 ac_uid16; /* LSB of Real User ID */ 63 | __u16 ac_gid16; /* LSB of Real Group ID */ 64 | __u16 ac_tty; /* Control Terminal */ 65 | __u32 ac_btime; /* Process Creation Time */ 66 | comp_t ac_utime; /* User Time */ 67 | comp_t ac_stime; /* System Time */ 68 | comp_t ac_etime; /* Elapsed Time */ 69 | comp_t ac_mem; /* Virtual Memory */ 70 | comp_t ac_rss; /* Resident Memory */ 71 | comp_t ac_io; /* Chars Transferred */ 72 | comp_t ac_rw; /* Blocks Read or Written */ 73 | comp_t ac_bread; /* Blocks Read */ 74 | comp_t ac_bwrite; /* Blocks Written */ 75 | comp2_t ac_dskrsz; /* Cum. blocks read */ 76 | comp2_t ac_dskwsz; /* Cum. blocks written */ 77 | comp_t ac_tcpsnd; /* TCP send requests */ 78 | comp_t ac_tcprcv; /* TCP recv requests */ 79 | comp2_t ac_tcpssz; /* TCP cum. length */ 80 | comp2_t ac_tcprsz; /* TCP cum. length */ 81 | comp_t ac_udpsnd; /* UDP send requests */ 82 | comp_t ac_udprcv; /* UDP recv requests */ 83 | comp2_t ac_udpssz; /* UDP cum. length */ 84 | comp2_t ac_udprsz; /* UDP cum. length */ 85 | comp_t ac_rawsnd; /* RAW send requests */ 86 | comp_t ac_rawrcv; /* RAW recv requests */ 87 | comp_t ac_minflt; /* Minor Pagefaults */ 88 | comp_t ac_majflt; /* Major Pagefaults */ 89 | comp_t ac_swaps; /* Number of Swaps */ 90 | /* m68k had no padding here. */ 91 | #if !defined(CONFIG_M68K) || !defined(__KERNEL__) 92 | __u16 ac_ahz; /* AHZ */ 93 | #endif 94 | __u32 ac_exitcode; /* Exitcode */ 95 | char ac_comm[ACCT_COMM + 1]; /* Command Name */ 96 | __u8 ac_etime_hi; /* Elapsed Time MSB */ 97 | __u16 ac_etime_lo; /* Elapsed Time LSB */ 98 | __u32 ac_uid; /* Real User ID */ 99 | __u32 ac_gid; /* Real Group ID */ 100 | }; 101 | 102 | /* 103 | ** default layout of accounting record 104 | ** (copied from /usr/src/linux/include/linux/acct.h) 105 | */ 106 | 107 | struct acct 108 | { 109 | char ac_flag; /* Flags */ 110 | char ac_version; /* Always set to ACCT_VERSION */ 111 | /* for binary compatibility back until 2.0 */ 112 | __u16 ac_uid16; /* LSB of Real User ID */ 113 | __u16 ac_gid16; /* LSB of Real Group ID */ 114 | __u16 ac_tty; /* Control Terminal */ 115 | __u32 ac_btime; /* Process Creation Time */ 116 | comp_t ac_utime; /* User Time */ 117 | comp_t ac_stime; /* System Time */ 118 | comp_t ac_etime; /* Elapsed Time */ 119 | comp_t ac_mem; /* Average Memory Usage */ 120 | comp_t ac_io; /* Chars Transferred */ 121 | comp_t ac_rw; /* Blocks Read or Written */ 122 | comp_t ac_minflt; /* Minor Pagefaults */ 123 | comp_t ac_majflt; /* Major Pagefaults */ 124 | comp_t ac_swaps; /* Number of Swaps */ 125 | /* m68k had no padding here. */ 126 | #if !defined(CONFIG_M68K) || !defined(__KERNEL__) 127 | __u16 ac_ahz; /* AHZ */ 128 | #endif 129 | __u32 ac_exitcode; /* Exitcode */ 130 | char ac_comm[ACCT_COMM + 1]; /* Command Name */ 131 | __u8 ac_etime_hi; /* Elapsed Time MSB */ 132 | __u16 ac_etime_lo; /* Elapsed Time LSB */ 133 | __u32 ac_uid; /* Real User ID */ 134 | __u32 ac_gid; /* Real Group ID */ 135 | }; 136 | 137 | struct acct_v3 138 | { 139 | char ac_flag; /* Flags */ 140 | char ac_version; /* Always set to ACCT_VERSION */ 141 | __u16 ac_tty; /* Control Terminal */ 142 | __u32 ac_exitcode; /* Exitcode */ 143 | __u32 ac_uid; /* Real User ID */ 144 | __u32 ac_gid; /* Real Group ID */ 145 | __u32 ac_pid; /* Process ID */ 146 | __u32 ac_ppid; /* Parent Process ID */ 147 | __u32 ac_btime; /* Process Creation Time */ 148 | #ifdef __KERNEL__ 149 | __u32 ac_etime; /* Elapsed Time */ 150 | #else 151 | float ac_etime; /* Elapsed Time */ 152 | #endif 153 | comp_t ac_utime; /* User Time */ 154 | comp_t ac_stime; /* System Time */ 155 | comp_t ac_mem; /* Average Memory Usage */ 156 | comp_t ac_io; /* Chars Transferred */ 157 | comp_t ac_rw; /* Blocks Read or Written */ 158 | comp_t ac_minflt; /* Minor Pagefaults */ 159 | comp_t ac_majflt; /* Major Pagefaults */ 160 | comp_t ac_swaps; /* Number of Swaps */ 161 | char ac_comm[ACCT_COMM]; /* Command Name */ 162 | }; 163 | 164 | #endif 165 | -------------------------------------------------------------------------------- /utsnames.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** 7 | ** This source-file contains functions to retrieve the hostname of a 8 | ** containerized process by associating to its UTS namespace. 9 | ** ========================================================================== 10 | ** Author: Gerlof Langeveld 11 | ** E-mail: gerlof.langeveld@atoptool.nl 12 | ** Date: August 2023 (initial) 13 | ** -------------------------------------------------------------------------- 14 | ** Copyright (C) 2023 Gerlof Langeveld 15 | ** 16 | ** This program is free software; you can redistribute it and/or modify it 17 | ** under the terms of the GNU General Public License as published by the 18 | ** Free Software Foundation; either version 2, or (at your option) any 19 | ** later version. 20 | ** 21 | ** This program is distributed in the hope that it will be useful, but 22 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | ** See the GNU General Public License for more details. 25 | ** 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program; if not, write to the Free Software 28 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29 | ** -------------------------------------------------------------------------- 30 | */ 31 | 32 | #define _GNU_SOURCE 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | #include 42 | #include 43 | 44 | #define BASEPATH "/proc/1/ns/uts" 45 | #define UTSPATH "/proc/%d/ns/uts" 46 | 47 | static int mypidfd, foreignuts; 48 | 49 | // Function that fills the host name (container/pod name) of 50 | // a specific process. 51 | // When the process has a different UTS namespace then systemd, 52 | // the process' UTS namespace will be temporarily associated with atop 53 | // itself to retrieve the host name (i.e. container/pod name) of that process. 54 | // To avoid too many namespace switches, atop only reassociates with its own 55 | // UTS namespace when the resetutsname() function is called. 56 | // 57 | // Return value: 58 | // 0 - no container/pod detected 59 | // 1 - container/pod detected 60 | // 61 | int 62 | getutsname(struct tstat *curtask) 63 | { 64 | static char firstcall = 1, basepath[64], basehost[32]; 65 | 66 | int pidfd, offset; 67 | ssize_t destlen; 68 | char srcpath[64], destpath[64], tmphost[70]; 69 | 70 | // regain root privs in case of setuid root executable 71 | // 72 | regainrootprivs(); 73 | 74 | // function initialization 75 | // 76 | if (firstcall) 77 | { 78 | firstcall = 0; 79 | 80 | // determine the UTS namespace of systemd and the hostname 81 | // related to systemd 82 | // 83 | if ( (destlen = readlink(BASEPATH, basepath, sizeof basepath)) == -1) 84 | goto drop_and_return; 85 | 86 | basepath[destlen] = '\0'; // guarantee delimeter 87 | 88 | if ( (pidfd = open(BASEPATH, O_RDONLY)) == -1) 89 | goto drop_and_return; 90 | 91 | if (setns(pidfd, CLONE_NEWUTS) == -1) 92 | { 93 | close(pidfd); 94 | goto drop_and_return; 95 | } 96 | 97 | foreignuts = 1; 98 | close(pidfd); 99 | 100 | gethostname(basehost, sizeof basehost); 101 | 102 | // determine the UTS namespace of atop itself 103 | // and open that namespace for reassociation via 104 | // function resetutsname() 105 | // 106 | snprintf(srcpath, sizeof srcpath, UTSPATH, getpid()); 107 | 108 | if ( (mypidfd = open(srcpath, O_RDONLY)) == -1) 109 | basepath[0] = '\0'; 110 | 111 | resetutsname(); 112 | } 113 | 114 | // no root privileges? 115 | // 116 | if (!basepath[0]) 117 | goto drop_and_return; 118 | 119 | // check if this pid is related to myself (atop) 120 | // 121 | if (curtask->gen.pid == getpid()) 122 | goto drop_and_return; 123 | 124 | // base path is known 125 | // verify if this process is native, i.e. does it share the 126 | // UTS namespace of systemd 127 | // 128 | snprintf(srcpath, sizeof srcpath, UTSPATH, curtask->gen.pid); 129 | 130 | destlen = readlink(srcpath, destpath, sizeof destpath); 131 | destpath[destlen] = '\0'; 132 | 133 | if (strcmp(basepath, destpath) == 0) // equal? 134 | goto drop_and_return; 135 | 136 | // UTS namespace deviates from base UTS namespace 137 | // 138 | // get hostname related to this UTS namespace by associating 139 | // atop to that namespace 140 | // 141 | if ( (pidfd = open(srcpath, O_RDONLY)) == -1) 142 | goto drop_and_return; 143 | 144 | if (setns(pidfd, CLONE_NEWUTS) == -1) 145 | { 146 | close(pidfd); 147 | goto drop_and_return; 148 | } 149 | 150 | foreignuts = 1; // set boolean 151 | close(pidfd); 152 | 153 | gethostname(tmphost, sizeof tmphost); 154 | 155 | // check if the hostname is the same as the hostname of 156 | // systemd (PID 1), because some systemd-related processes have 157 | // their own UTS namespace with the same hostname 158 | // also the hostname 'localhost' might be used by various daemons 159 | // and will be skipped as well 160 | // 161 | if ( strcmp(tmphost, basehost) == 0 || strcmp(tmphost, "localhost") == 0) 162 | goto drop_and_return; 163 | 164 | // this process really seems to be container/pod related 165 | // 166 | if ( (offset = strlen(tmphost) - UTSLEN) < 0) 167 | offset = 0; 168 | 169 | strcpy(curtask->gen.utsname, tmphost+offset); // copy last part when overflow 170 | 171 | if (! droprootprivs()) 172 | mcleanstop(42, "failed to drop root privs\n"); 173 | 174 | return 1; 175 | 176 | drop_and_return: 177 | if (! droprootprivs()) 178 | mcleanstop(42, "failed to drop root privs\n"); 179 | 180 | return 0; 181 | } 182 | 183 | // Reassociate atop with its own UTS namespace 184 | // 185 | void 186 | resetutsname(void) 187 | { 188 | // switch back to my own original UTS namespace 189 | // 190 | if (foreignuts) 191 | { 192 | foreignuts = 0; 193 | 194 | regainrootprivs(); 195 | 196 | if (setns(mypidfd, CLONE_NEWUTS) == -1) 197 | ; 198 | 199 | if (! droprootprivs()) 200 | mcleanstop(42, "failed to drop root privs\n"); 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /prev/photosyst_200.h: -------------------------------------------------------------------------------- 1 | #define MAXCPU_20 2048 2 | #define MAXDSK_20 512 3 | #define MAXLVM_20 1024 4 | #define MAXMDD_20 256 5 | #define MAXINTF_20 128 6 | 7 | /************************************************************************/ 8 | 9 | struct memstat_20 { 10 | count_t physmem; // number of physical pages 11 | count_t freemem; // number of free pages 12 | count_t buffermem; // number of buffer pages 13 | count_t slabmem; // number of slab pages 14 | count_t cachemem; // number of cache pages 15 | count_t cachedrt; // number of cache pages (dirty) 16 | 17 | count_t totswap; // number of pages in swap 18 | count_t freeswap; // number of free swap pages 19 | 20 | count_t pgscans; // number of page scans 21 | count_t pgsteal; // number of page steals 22 | count_t allocstall; // try to free pages forced 23 | count_t swouts; // number of pages swapped out 24 | count_t swins; // number of pages swapped in 25 | 26 | count_t commitlim; // commit limit in pages 27 | count_t committed; // number of reserved pages 28 | 29 | count_t shmem; // tot shmem incl. tmpfs (pages) 30 | count_t shmrss; // resident shared memory (pages) 31 | count_t shmswp; // swapped shared memory (pages) 32 | 33 | count_t slabreclaim; // reclaimable slab (pages) 34 | }; 35 | 36 | /************************************************************************/ 37 | 38 | struct netstat_20 { 39 | struct ipv4_stats ipv4; 40 | struct icmpv4_stats_without_InCsumErrors icmpv4; 41 | struct udpv4_stats udpv4; 42 | 43 | struct ipv6_stats ipv6; 44 | struct icmpv6_stats icmpv6; 45 | struct udpv6_stats udpv6; 46 | 47 | struct tcp_stats_without_InCsumErrors tcp; 48 | }; 49 | 50 | /************************************************************************/ 51 | 52 | struct freqcnt_20 { 53 | count_t maxfreq;/* frequency in MHz */ 54 | count_t cnt; /* number of clock ticks times state */ 55 | count_t ticks; /* number of total clock ticks */ 56 | /* if zero, cnt is actul freq */ 57 | }; 58 | 59 | struct percpu_20 { 60 | int cpunr; 61 | count_t stime; /* system time in clock ticks */ 62 | count_t utime; /* user time in clock ticks */ 63 | count_t ntime; /* nice time in clock ticks */ 64 | count_t itime; /* idle time in clock ticks */ 65 | count_t wtime; /* iowait time in clock ticks */ 66 | count_t Itime; /* irq time in clock ticks */ 67 | count_t Stime; /* softirq time in clock ticks */ 68 | count_t steal; /* steal time in clock ticks */ 69 | count_t guest; /* guest time in clock ticks */ 70 | struct freqcnt_20 freqcnt;/* frequency scaling info */ 71 | count_t cfuture[1]; /* reserved for future use */ 72 | }; 73 | 74 | struct cpustat_20 { 75 | count_t nrcpu; /* number of cpu's */ 76 | count_t devint; /* number of device interrupts */ 77 | count_t csw; /* number of context switches */ 78 | count_t nprocs; /* number of processes started */ 79 | float lavg1; /* load average last minute */ 80 | float lavg5; /* load average last 5 minutes */ 81 | float lavg15; /* load average last 15 minutes */ 82 | count_t cfuture[4]; /* reserved for future use */ 83 | 84 | struct percpu_20 all; 85 | struct percpu_20 cpu[MAXCPU_20]; 86 | }; 87 | 88 | /************************************************************************/ 89 | 90 | struct perdsk_20 { 91 | char name[MAXDKNAM]; /* empty string for last */ 92 | count_t nread; /* number of read transfers */ 93 | count_t nrsect; /* number of sectors read */ 94 | count_t nwrite; /* number of write transfers */ 95 | count_t nwsect; /* number of sectors written */ 96 | count_t io_ms; /* number of millisecs spent for I/O */ 97 | count_t avque; /* average queue length */ 98 | count_t cfuture[4]; /* reserved for future use */ 99 | }; 100 | 101 | struct dskstat_20 { 102 | int ndsk; /* number of physical disks */ 103 | int nmdd; /* number of md volumes */ 104 | int nlvm; /* number of logical volumes */ 105 | struct perdsk_20 dsk[MAXDSK_20]; 106 | struct perdsk_20 mdd[MAXMDD_20]; 107 | struct perdsk_20 lvm[MAXLVM_20]; 108 | }; 109 | 110 | /************************************************************************/ 111 | 112 | struct perintf_20 { 113 | char name[16]; /* empty string for last */ 114 | 115 | count_t rbyte; /* number of read bytes */ 116 | count_t rpack; /* number of read packets */ 117 | count_t rerrs; /* receive errors */ 118 | count_t rdrop; /* receive drops */ 119 | count_t rfifo; /* receive fifo */ 120 | count_t rframe; /* receive framing errors */ 121 | count_t rcompr; /* receive compressed */ 122 | count_t rmultic;/* receive multicast */ 123 | count_t rfuture[4]; /* reserved for future use */ 124 | 125 | count_t sbyte; /* number of written bytes */ 126 | count_t spack; /* number of written packets */ 127 | count_t serrs; /* transmit errors */ 128 | count_t sdrop; /* transmit drops */ 129 | count_t sfifo; /* transmit fifo */ 130 | count_t scollis;/* collisions */ 131 | count_t scarrier;/* transmit carrier */ 132 | count_t scompr; /* transmit compressed */ 133 | count_t sfuture[4]; /* reserved for future use */ 134 | 135 | long speed; /* interface speed in megabits/second */ 136 | char duplex; /* full duplex (boolean) */ 137 | count_t cfuture[4]; /* reserved for future use */ 138 | }; 139 | 140 | struct intfstat_20 { 141 | int nrintf; 142 | struct perintf_20 intf[MAXINTF_20]; 143 | }; 144 | 145 | /************************************************************************/ 146 | /* 147 | ** experimental stuff for access to local HTTP daemons 148 | */ 149 | struct wwwstat_20 { 150 | count_t accesses; /* total number of HTTP-requests */ 151 | count_t totkbytes; /* total kbytes transfer for HTTP-req */ 152 | count_t uptime; /* number of seconds since startup */ 153 | int bworkers; /* number of busy httpd-daemons */ 154 | int iworkers; /* number of idle httpd-daemons */ 155 | }; 156 | 157 | /************************************************************************/ 158 | 159 | struct sstat_20 { 160 | struct cpustat_20 cpu; 161 | struct memstat_20 mem; 162 | struct netstat_20 net; 163 | struct intfstat_20 intf; 164 | struct dskstat_20 dsk; 165 | 166 | struct wwwstat_20 www; 167 | }; 168 | -------------------------------------------------------------------------------- /prev/photosyst_201.h: -------------------------------------------------------------------------------- 1 | #define MAXCPU_21 2048 2 | #define MAXDSK_21 1024 3 | #define MAXLVM_21 2048 4 | #define MAXMDD_21 256 5 | #define MAXINTF_21 128 6 | 7 | #define MAXDKNAM 32 8 | 9 | /************************************************************************/ 10 | 11 | struct memstat_21 { 12 | count_t physmem; // number of physical pages 13 | count_t freemem; // number of free pages 14 | count_t buffermem; // number of buffer pages 15 | count_t slabmem; // number of slab pages 16 | count_t cachemem; // number of cache pages 17 | count_t cachedrt; // number of cache pages (dirty) 18 | 19 | count_t totswap; // number of pages in swap 20 | count_t freeswap; // number of free swap pages 21 | 22 | count_t pgscans; // number of page scans 23 | count_t pgsteal; // number of page steals 24 | count_t allocstall; // try to free pages forced 25 | count_t swouts; // number of pages swapped out 26 | count_t swins; // number of pages swapped in 27 | 28 | count_t commitlim; // commit limit in pages 29 | count_t committed; // number of reserved pages 30 | 31 | count_t shmem; // tot shmem incl. tmpfs (pages) 32 | count_t shmrss; // resident shared memory (pages) 33 | count_t shmswp; // swapped shared memory (pages) 34 | 35 | count_t slabreclaim; // reclaimable slab (pages) 36 | 37 | count_t tothugepage; // total huge pages (huge pages) 38 | count_t freehugepage; // free huge pages (huge pages) 39 | count_t hugepagesz; // huge page size (bytes) 40 | 41 | count_t vmwballoon; // vmware claimed balloon pages 42 | 43 | count_t cfuture[8]; // reserved for future use 44 | }; 45 | 46 | /************************************************************************/ 47 | 48 | struct netstat_21 { 49 | struct ipv4_stats ipv4; 50 | struct icmpv4_stats_without_InCsumErrors icmpv4; 51 | struct udpv4_stats udpv4; 52 | 53 | struct ipv6_stats ipv6; 54 | struct icmpv6_stats icmpv6; 55 | struct udpv6_stats udpv6; 56 | 57 | struct tcp_stats_without_InCsumErrors tcp; 58 | }; 59 | 60 | /************************************************************************/ 61 | 62 | struct freqcnt_21 { 63 | count_t maxfreq;/* frequency in MHz */ 64 | count_t cnt; /* number of clock ticks times state */ 65 | count_t ticks; /* number of total clock ticks */ 66 | /* if zero, cnt is actul freq */ 67 | }; 68 | 69 | struct percpu_21 { 70 | int cpunr; 71 | count_t stime; /* system time in clock ticks */ 72 | count_t utime; /* user time in clock ticks */ 73 | count_t ntime; /* nice time in clock ticks */ 74 | count_t itime; /* idle time in clock ticks */ 75 | count_t wtime; /* iowait time in clock ticks */ 76 | count_t Itime; /* irq time in clock ticks */ 77 | count_t Stime; /* softirq time in clock ticks */ 78 | count_t steal; /* steal time in clock ticks */ 79 | count_t guest; /* guest time in clock ticks */ 80 | struct freqcnt_21 freqcnt;/* frequency scaling info */ 81 | count_t cfuture[4]; /* reserved for future use */ 82 | }; 83 | 84 | struct cpustat_21 { 85 | count_t nrcpu; /* number of cpu's */ 86 | count_t devint; /* number of device interrupts */ 87 | count_t csw; /* number of context switches */ 88 | count_t nprocs; /* number of processes started */ 89 | float lavg1; /* load average last minute */ 90 | float lavg5; /* load average last 5 minutes */ 91 | float lavg15; /* load average last 15 minutes */ 92 | count_t cfuture[4]; /* reserved for future use */ 93 | 94 | struct percpu_21 all; 95 | struct percpu_21 cpu[MAXCPU_21]; 96 | }; 97 | 98 | /************************************************************************/ 99 | 100 | struct perdsk_21 { 101 | char name[MAXDKNAM]; /* empty string for last */ 102 | count_t nread; /* number of read transfers */ 103 | count_t nrsect; /* number of sectors read */ 104 | count_t nwrite; /* number of write transfers */ 105 | count_t nwsect; /* number of sectors written */ 106 | count_t io_ms; /* number of millisecs spent for I/O */ 107 | count_t avque; /* average queue length */ 108 | count_t cfuture[4]; /* reserved for future use */ 109 | }; 110 | 111 | struct dskstat_21 { 112 | int ndsk; /* number of physical disks */ 113 | int nmdd; /* number of md volumes */ 114 | int nlvm; /* number of logical volumes */ 115 | struct perdsk_21 dsk[MAXDSK_21]; 116 | struct perdsk_21 mdd[MAXMDD_21]; 117 | struct perdsk_21 lvm[MAXLVM_21]; 118 | }; 119 | 120 | /************************************************************************/ 121 | 122 | struct perintf_21 { 123 | char name[16]; /* empty string for last */ 124 | 125 | count_t rbyte; /* number of read bytes */ 126 | count_t rpack; /* number of read packets */ 127 | count_t rerrs; /* receive errors */ 128 | count_t rdrop; /* receive drops */ 129 | count_t rfifo; /* receive fifo */ 130 | count_t rframe; /* receive framing errors */ 131 | count_t rcompr; /* receive compressed */ 132 | count_t rmultic;/* receive multicast */ 133 | count_t rfuture[4]; /* reserved for future use */ 134 | 135 | count_t sbyte; /* number of written bytes */ 136 | count_t spack; /* number of written packets */ 137 | count_t serrs; /* transmit errors */ 138 | count_t sdrop; /* transmit drops */ 139 | count_t sfifo; /* transmit fifo */ 140 | count_t scollis;/* collisions */ 141 | count_t scarrier;/* transmit carrier */ 142 | count_t scompr; /* transmit compressed */ 143 | count_t sfuture[4]; /* reserved for future use */ 144 | 145 | long speed; /* interface speed in megabits/second */ 146 | char duplex; /* full duplex (boolean) */ 147 | count_t cfuture[4]; /* reserved for future use */ 148 | }; 149 | 150 | struct intfstat_21 { 151 | int nrintf; 152 | struct perintf_21 intf[MAXINTF_21]; 153 | }; 154 | 155 | /************************************************************************/ 156 | /* 157 | ** experimental stuff for access to local HTTP daemons 158 | */ 159 | struct wwwstat_21 { 160 | count_t accesses; /* total number of HTTP-requests */ 161 | count_t totkbytes; /* total kbytes transfer for HTTP-req */ 162 | count_t uptime; /* number of seconds since startup */ 163 | int bworkers; /* number of busy httpd-daemons */ 164 | int iworkers; /* number of idle httpd-daemons */ 165 | }; 166 | /************************************************************************/ 167 | 168 | struct sstat_21 { 169 | struct cpustat_21 cpu; 170 | struct memstat_21 mem; 171 | struct netstat_21 net; 172 | struct intfstat_21 intf; 173 | struct dskstat_21 dsk; 174 | 175 | struct wwwstat_21 www; 176 | }; 177 | -------------------------------------------------------------------------------- /netlink.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2014 Gerlof Langeveld 3 | ** 4 | ** This program is free software; you can redistribute it and/or modify it 5 | ** under the terms of the GNU General Public License as published by the 6 | ** Free Software Foundation; either version 2, or (at your option) any 7 | ** later version. 8 | ** 9 | ** This program is distributed in the hope that it will be useful, but 10 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | ** See the GNU General Public License for more details. 13 | ** 14 | ** You should have received a copy of the GNU General Public License 15 | ** along with this program; if not, write to the Free Software 16 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | ** -------------------------------------------------------------------------- 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #include "atop.h" 35 | 36 | /* 37 | ** generic macro's 38 | */ 39 | #define GENLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + GENL_HDRLEN)) 40 | #define GENLMSG_PAYLOAD(glh) (NLMSG_PAYLOAD(glh, 0) - GENL_HDRLEN) 41 | #define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN)) 42 | #define NLA_PAYLOAD(len) (len - NLA_HDRLEN) 43 | 44 | /* 45 | ** function prototypes 46 | */ 47 | static int nlsock_open(void); 48 | static int nlsock_sendcmd(int, __u16, __u32, __u8, __u16, void *, int); 49 | static int nlsock_getfam(int); 50 | static int getnumcpu(void); 51 | 52 | /* 53 | ** message format to communicate with NETLINK 54 | */ 55 | struct msgtemplate { 56 | struct nlmsghdr n; 57 | struct genlmsghdr g; 58 | char buf[2048]; 59 | }; 60 | 61 | int 62 | netlink_open(void) 63 | { 64 | int nlsock, famid; 65 | char cpudef[64]; 66 | 67 | /* 68 | ** open the netlink socket 69 | */ 70 | nlsock = nlsock_open(); 71 | 72 | /* 73 | ** get the family id for the TASKSTATS family 74 | */ 75 | famid = nlsock_getfam(nlsock); 76 | 77 | /* 78 | ** determine maximum number of CPU's for this system 79 | ** and specify mask to register all cpu's 80 | */ 81 | snprintf(cpudef, sizeof cpudef, "0-%d", getnumcpu() -1); 82 | 83 | /* 84 | ** indicate to listen for processes from all CPU's 85 | */ 86 | if (nlsock_sendcmd(nlsock, famid, getpid(), TASKSTATS_CMD_GET, 87 | TASKSTATS_CMD_ATTR_REGISTER_CPUMASK, 88 | &cpudef, strlen(cpudef)+1) == -1) 89 | { 90 | fprintf(stderr, "register cpumask failed\n"); 91 | return -1; 92 | } 93 | 94 | return nlsock; 95 | } 96 | 97 | 98 | int 99 | netlink_recv(int nlsock, int flags) 100 | { 101 | int len; 102 | struct msgtemplate msg; 103 | 104 | if ( (len = recv(nlsock, &msg, sizeof msg, flags)) == -1) 105 | return -errno; // negative: errno 106 | 107 | if (msg.n.nlmsg_type == NLMSG_ERROR || !NLMSG_OK(&msg.n, len)) 108 | { 109 | struct nlmsgerr *err = NLMSG_DATA(&msg); 110 | 111 | return err->error; // negative: errno 112 | } 113 | 114 | return len; // 0 or positive value 115 | } 116 | 117 | static int 118 | nlsock_getfam(int nlsock) 119 | { 120 | int len; 121 | struct nlattr *nlattr; 122 | struct msgtemplate msg; 123 | 124 | nlsock_sendcmd(nlsock, GENL_ID_CTRL, getpid(), 125 | CTRL_CMD_GETFAMILY, 126 | CTRL_ATTR_FAMILY_NAME, 127 | TASKSTATS_GENL_NAME, sizeof TASKSTATS_GENL_NAME); 128 | 129 | if ( (len = recv(nlsock, &msg, sizeof msg, 0)) == -1) 130 | { 131 | perror("receive NETLINK family"); 132 | exit(1); 133 | } 134 | 135 | if (msg.n.nlmsg_type == NLMSG_ERROR || !NLMSG_OK(&msg.n, len)) 136 | { 137 | struct nlmsgerr *err = NLMSG_DATA(&msg); 138 | 139 | fprintf(stderr, "receive NETLINK family, errno %d\n", 140 | err->error); 141 | 142 | exit(1); 143 | } 144 | 145 | nlattr = (struct nlattr *) GENLMSG_DATA(&msg); 146 | nlattr = (struct nlattr *) ((char *) nlattr + 147 | NLA_ALIGN(nlattr->nla_len)); 148 | 149 | if (nlattr->nla_type != CTRL_ATTR_FAMILY_ID) 150 | { 151 | fprintf(stderr, "unexpected family id\n"); 152 | exit(1); 153 | } 154 | 155 | return *(__u16 *) NLA_DATA(nlattr); 156 | } 157 | 158 | 159 | static int 160 | nlsock_open(void) 161 | { 162 | int nlsock, rcvsz = 256*1024; 163 | struct sockaddr_nl nlsockaddr; 164 | 165 | if ( (nlsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC) ) == -1) 166 | { 167 | perror("open NETLINK socket"); 168 | exit(1); 169 | } 170 | 171 | if (setsockopt(nlsock, SOL_SOCKET, SO_RCVBUF, &rcvsz, sizeof rcvsz) 172 | == -1) 173 | { 174 | perror("set length receive buffer"); 175 | exit(1); 176 | } 177 | 178 | memset(&nlsockaddr, 0, sizeof nlsockaddr); 179 | nlsockaddr.nl_family = AF_NETLINK; 180 | 181 | if (bind(nlsock, (struct sockaddr *) &nlsockaddr, sizeof nlsockaddr) 182 | == -1) 183 | { 184 | perror("bind NETLINK socket"); 185 | close(nlsock); 186 | exit(1); 187 | } 188 | 189 | return nlsock; 190 | } 191 | 192 | static int 193 | nlsock_sendcmd(int nlsock, __u16 nlmsg_type, 194 | __u32 nlmsg_pid, __u8 genl_cmd, 195 | __u16 nla_type, void *nla_data, int nla_len) 196 | { 197 | struct nlattr *na; 198 | struct sockaddr_nl nlsockaddr; 199 | int rv, buflen; 200 | char *buf; 201 | struct msgtemplate msg; 202 | 203 | msg.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); 204 | msg.n.nlmsg_type = nlmsg_type; 205 | msg.n.nlmsg_flags = NLM_F_REQUEST; 206 | msg.n.nlmsg_seq = 0; 207 | msg.n.nlmsg_pid = nlmsg_pid; 208 | msg.g.cmd = genl_cmd; 209 | msg.g.version = 0x1; 210 | na = (struct nlattr *) GENLMSG_DATA(&msg); 211 | na->nla_type = nla_type; 212 | na->nla_len = nla_len + 1 + NLA_HDRLEN; 213 | 214 | memcpy(NLA_DATA(na), nla_data, nla_len); 215 | msg.n.nlmsg_len += NLMSG_ALIGN(na->nla_len); 216 | 217 | buf = (char *) &msg; 218 | buflen = msg.n.nlmsg_len ; 219 | 220 | memset(&nlsockaddr, 0, sizeof(nlsockaddr)); 221 | nlsockaddr.nl_family = AF_NETLINK; 222 | 223 | while ((rv = sendto(nlsock, buf, buflen, 0, 224 | (struct sockaddr *) &nlsockaddr, sizeof(nlsockaddr))) < buflen) 225 | { 226 | if (rv == -1) 227 | { 228 | if (errno != EAGAIN) 229 | { 230 | perror("sendto NETLINK"); 231 | return -1; 232 | } 233 | } 234 | else 235 | { 236 | buf += rv; 237 | buflen -= rv; 238 | } 239 | } 240 | 241 | return 0; 242 | } 243 | 244 | static int 245 | getnumcpu(void) 246 | { 247 | FILE *fp; 248 | char linebuf[4096], label[256]; 249 | int cpunum, maxcpu = 0; 250 | 251 | if ( (fp = fopen("/proc/stat", "r")) != NULL) 252 | { 253 | while ( fgets(linebuf, sizeof(linebuf), fp) != NULL) 254 | { 255 | sscanf(linebuf, "%255s", label); 256 | 257 | if ( strncmp("cpu", label, 3) == 0 && strlen(label) >3) 258 | { 259 | cpunum = atoi(&label[3]); 260 | 261 | if (maxcpu < cpunum) 262 | maxcpu = cpunum; 263 | } 264 | 265 | if ( strncmp("int", label, 3) == 0) 266 | break; 267 | } 268 | 269 | fclose(fp); 270 | } 271 | 272 | return maxcpu+1; 273 | } 274 | -------------------------------------------------------------------------------- /atop.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** 7 | ** Include-file describing miscellaneous constants and function-prototypes. 8 | ** ================================================================ 9 | ** Author: Gerlof Langeveld 10 | ** E-mail: gerlof.langeveld@atoptool.nl 11 | ** Date: November 1996 12 | ** LINUX-port: June 2000 13 | ** 14 | ** This program is free software; you can redistribute it and/or modify it 15 | ** under the terms of the GNU General Public License as published by the 16 | ** Free Software Foundation; either version 2, or (at your option) any 17 | ** later version. 18 | ** 19 | ** This program is distributed in the hope that it will be useful, but 20 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 | ** See the GNU General Public License for more details. 23 | */ 24 | #ifndef __ATOP__ 25 | #define __ATOP__ 26 | 27 | #include 28 | 29 | #define EQ 0 30 | #define SECONDSINDAY 86400 31 | #define RAWNAMESZ 256 32 | 33 | /* 34 | ** memory-size formatting possibilities 35 | */ 36 | #define BFORMAT 0 37 | #define KBFORMAT 1 38 | #define KBFORMAT_INT 2 39 | #define MBFORMAT 3 40 | #define MBFORMAT_INT 4 41 | #define GBFORMAT 5 42 | #define GBFORMAT_INT 6 43 | #define TBFORMAT 7 44 | #define TBFORMAT_INT 8 45 | #define PBFORMAT 9 46 | #define PBFORMAT_INT 10 47 | #define EBFORMAT 11 48 | #define EBFORMAT_INT 12 49 | #define OVFORMAT 13 50 | 51 | typedef long long count_t; 52 | 53 | struct tstat; 54 | struct devtstat; 55 | struct sstat; 56 | struct cgchainer; 57 | struct netpertask; 58 | 59 | /* 60 | ** miscellaneous flags 61 | */ 62 | #define RRBOOT 0x0001 63 | #define RRLAST 0x0002 64 | #define RRNETATOP 0x0004 65 | #define RRNETATOPD 0x0008 66 | #define RRACCTACTIVE 0x0010 67 | #define RRIOSTAT 0x0020 68 | #define RRCONTAINERSTAT 0x0040 69 | #define RRGPUSTAT 0x0080 70 | #define RRCGRSTAT 0x0100 71 | 72 | #define MAXHANDLERS 10 73 | 74 | struct handler { 75 | char (*handle_sample) (time_t, int, 76 | struct devtstat *, struct sstat *, 77 | struct cgchainer *, int, int, int, 78 | unsigned int, char); 79 | }; 80 | 81 | /* 82 | ** external values 83 | */ 84 | extern struct utsname utsname; 85 | extern int utsnodenamelen; 86 | extern time_t pretime; 87 | extern time_t curtime; 88 | extern unsigned long interval; 89 | extern unsigned long sampcnt; 90 | extern char screen; 91 | extern int fdinotify; 92 | extern pid_t twinpid; 93 | extern int linelen; 94 | extern char acctreason; 95 | extern char deviatonly; 96 | extern char usecolors; 97 | extern char threadview; 98 | extern char calcpss; 99 | extern char getwchan; 100 | extern char irawname[]; 101 | extern char orawname[]; 102 | extern char twindir[]; 103 | extern char rawreadflag; 104 | extern char connectnetatop; 105 | extern char idnamesuppress; 106 | extern char rmspaces; 107 | extern time_t begintime, endtime, cursortime; // epoch or time in day 108 | extern char flaglist[]; 109 | extern struct handler handlers[]; 110 | 111 | extern char displaymode; 112 | extern char barmono; 113 | 114 | extern int osrel; 115 | extern int osvers; 116 | extern int ossub; 117 | 118 | extern unsigned short hertz; 119 | extern unsigned int pagesize; 120 | extern unsigned int pidwidth; 121 | extern unsigned int nrgpus; 122 | 123 | extern int supportflags; 124 | 125 | extern int cpubadness; 126 | extern int membadness; 127 | extern int swpbadness; 128 | extern int dskbadness; 129 | extern int netbadness; 130 | extern int pagbadness; 131 | extern int almostcrit; 132 | 133 | /* 134 | ** bit-values for supportflags 135 | */ 136 | #define ACCTACTIVE 0x00000001 137 | #define IOSTAT 0x00000004 138 | #define NETATOP 0x00000010 139 | #define NETATOPD 0x00000020 140 | #define CONTAINERSTAT 0x00000040 141 | #define GPUSTAT 0x00000080 142 | #define CGROUPV2 0x00000100 143 | #define NETATOPBPF 0x00001000 144 | #define REALNUMA 0x00002000 145 | #define ZSWAP 0x00004000 146 | 147 | 148 | /* 149 | ** in rawlog file, the four least significant bits 150 | ** are moved to the per-sample flags and therefor dummy 151 | ** in the support flags of the general header 152 | */ 153 | #define RAWLOGNG (ACCTACTIVE|IOSTAT|NETATOP|NETATOPD) 154 | 155 | /* 156 | ** structure containing the start addresses of functions for visualization 157 | */ 158 | char generic_samp (time_t, int, 159 | struct devtstat *, struct sstat *, 160 | struct cgchainer *, int, int, 161 | int, unsigned int, char); 162 | void generic_error(const char *, ...); 163 | void generic_end (void); 164 | void generic_usage(void); 165 | 166 | /* 167 | ** miscellaneous prototypes 168 | */ 169 | int atopsar(int, char *[]); 170 | char *convtime(time_t, char *); 171 | char *convdate(time_t, char *); 172 | int getbranchtime(char *, time_t *); 173 | time_t normalize_epoch(time_t, long); 174 | 175 | 176 | char *val2valstr(count_t, char *, int, int, int); 177 | char *val2memstr(count_t, char *, int, int, int); 178 | char *val2cpustr(count_t, char *); 179 | char *val2Hzstr(count_t, char *); 180 | int val2elapstr(int, char *); 181 | 182 | char *uid2name(uid_t); 183 | char *gid2name(gid_t); 184 | 185 | void safe_strcpy(char *, const char *, size_t); 186 | 187 | int compcpu(const void *, const void *, void *); 188 | int compdsk(const void *, const void *, void *); 189 | int compmem(const void *, const void *, void *); 190 | int compnet(const void *, const void *, void *); 191 | int compgpu(const void *, const void *, void *); 192 | 193 | int compusr(const void *, const void *); 194 | int compnam(const void *, const void *); 195 | int compcon(const void *, const void *); 196 | 197 | int cpucompar (const void *, const void *); 198 | int gpucompar (const void *, const void *); 199 | int diskcompar(const void *, const void *); 200 | int intfcompar(const void *, const void *); 201 | int ifbcompar(const void *, const void *); 202 | int nfsmcompar(const void *, const void *); 203 | int contcompar(const void *, const void *); 204 | int memnumacompar(const void *, const void *); 205 | int cpunumacompar(const void *, const void *); 206 | int llccompar(const void *, const void *); 207 | 208 | int rawread(void); 209 | char rawwrite (time_t, int, 210 | struct devtstat *, struct sstat *, 211 | struct cgchainer *, int, int, 212 | int, unsigned int, char); 213 | 214 | int numeric(char *); 215 | void getalarm(int); 216 | unsigned long long getboot(void); 217 | char *getstrvers(void); 218 | unsigned short getnumvers(void); 219 | void ptrverify(const void *, const char *, ...); 220 | void mcleanstop(int, const char *, ...); 221 | void cleanstop(int); 222 | int getpidwidth(void); 223 | void prusage(char *); 224 | 225 | int rootprivs(void); 226 | int droprootprivs(void); 227 | void regainrootprivs(void); 228 | FILE *fopen_tryroot(const char *, const char *); 229 | 230 | void netatop_ipopen(void); 231 | void netatop_probe(void); 232 | void netatop_signoff(void); 233 | void netatop_gettask(pid_t, char, struct tstat *); 234 | unsigned int netatop_exitstore(void); 235 | void netatop_exiterase(void); 236 | void netatop_exithash(char); 237 | void netatop_exitfind(unsigned long, struct tstat *, struct tstat *); 238 | 239 | void netatop_bpf_ipopen(void); 240 | void netatop_bpf_probe(void); 241 | void netatop_bpf_gettask(void); 242 | void netatop_bpf_exitfind(unsigned long, struct tstat *, struct tstat *); 243 | 244 | void set_oom_score_adj(void); 245 | int run_in_guest(void); 246 | 247 | void getusr1(int), getusr2(int); 248 | void do_pacctdir(char *, char *); 249 | void do_atopsarflags(char *, char *); 250 | 251 | int netlink_open(void); 252 | int netlink_recv(int, int); 253 | 254 | int getutsname(struct tstat *); 255 | void resetutsname(void); 256 | 257 | #endif 258 | -------------------------------------------------------------------------------- /photoproc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** 7 | ** Include-file describing process-level counters maintained and functions 8 | ** to access the process-database. 9 | ** ================================================================ 10 | ** Author: Gerlof Langeveld 11 | ** E-mail: gerlof.langeveld@atoptool.nl 12 | ** Date: November 1996 13 | ** LINUX-port: June 2000 14 | ** 15 | ** This program is free software; you can redistribute it and/or modify it 16 | ** under the terms of the GNU General Public License as published by the 17 | ** Free Software Foundation; either version 2, or (at your option) any 18 | ** later version. 19 | ** 20 | ** This program is distributed in the hope that it will be useful, but 21 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 22 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 | ** See the GNU General Public License for more details. 24 | */ 25 | 26 | #ifndef __PHOTOPROC__ 27 | #define __PHOTOPROC__ 28 | 29 | #define PNAMLEN 15 30 | #define CMDLEN 255 31 | #define CGRLEN 64 32 | #define UTSLEN 15 33 | 34 | /* 35 | ** structure containing only relevant process-info extracted 36 | ** from kernel's process-administration 37 | */ 38 | struct tstat { 39 | /* GENERAL TASK INFO */ 40 | struct gen { 41 | int tgid; /* threadgroup identification */ 42 | int pid; /* process identification */ 43 | int ppid; /* parent process identification*/ 44 | int ruid; /* real user identification */ 45 | int euid; /* eff. user identification */ 46 | int suid; /* saved user identification */ 47 | int fsuid; /* fs user identification */ 48 | int rgid; /* real group identification */ 49 | int egid; /* eff. group identification */ 50 | int sgid; /* saved group identification */ 51 | int fsgid; /* fs group identification */ 52 | int nthr; /* number of threads in tgroup */ 53 | char name[PNAMLEN+1];/* process name string */ 54 | char isproc; /* boolean: process level? */ 55 | char state; /* process state ('E' = exited) */ 56 | int excode; /* process exit status */ 57 | time_t btime; /* process start time (epoch) */ 58 | time_t elaps; /* process elaps time (hertz) */ 59 | char cmdline[CMDLEN+1];/* command-line string */ 60 | int nthrslpi; /* # threads in state 'S' */ 61 | int nthrslpu; /* # threads in state 'D' */ 62 | int nthrrun; /* # threads in state 'R' */ 63 | int nthridle; /* # threads in state 'I' */ 64 | 65 | int ctid; /* OpenVZ container ID */ 66 | int vpid; /* OpenVZ virtual PID */ 67 | 68 | int wasinactive; /* boolean: task inactive */ 69 | 70 | char utsname[UTSLEN+1];/* UTS name container or pod */ 71 | 72 | int cgroupix; /* index in devchain -1=invalid */ 73 | /* lazy filling (parsable/json) */ 74 | int ifuture[4]; /* reserved for future use */ 75 | } gen; 76 | 77 | /* CPU STATISTICS */ 78 | struct cpu { 79 | count_t utime; /* time user text (ticks) */ 80 | count_t stime; /* time system text (ticks) */ 81 | int nice; /* nice value */ 82 | int prio; /* priority */ 83 | int rtprio; /* realtime priority */ 84 | int policy; /* scheduling policy */ 85 | int curcpu; /* current processor */ 86 | int sleepavg; /* sleep average percentage */ 87 | int ifuture[6]; /* reserved for future use */ 88 | char wchan[16]; /* wait channel string */ 89 | count_t rundelay; /* schedstat rundelay (nanosec) */ 90 | count_t blkdelay; /* blkio delay (ticks) */ 91 | count_t nvcsw; /* voluntary cxt switch counts */ 92 | count_t nivcsw; /* involuntary csw counts */ 93 | count_t cfuture[3]; /* reserved for future use */ 94 | } cpu; 95 | 96 | /* DISK STATISTICS */ 97 | struct dsk { 98 | count_t rio; /* number of read requests */ 99 | count_t rsz; /* cumulative # sectors read */ 100 | count_t wio; /* number of write requests */ 101 | count_t wsz; /* cumulative # sectors written */ 102 | count_t cwsz; /* cumulative # written sectors */ 103 | /* being cancelled */ 104 | count_t cfuture[4]; /* reserved for future use */ 105 | } dsk; 106 | 107 | /* MEMORY STATISTICS */ 108 | struct mem { 109 | count_t minflt; /* number of page-reclaims */ 110 | count_t majflt; /* number of page-faults */ 111 | count_t vexec; /* virtmem execfile (Kb) */ 112 | count_t vmem; /* virtual memory (Kb) */ 113 | count_t rmem; /* resident memory (Kb) */ 114 | count_t pmem; /* resident memory (Kb) */ 115 | count_t vgrow; /* virtual growth (Kb) */ 116 | count_t rgrow; /* resident growth (Kb) */ 117 | count_t vdata; /* virtmem data (Kb) */ 118 | count_t vstack; /* virtmem stack (Kb) */ 119 | count_t vlibs; /* virtmem libexec (Kb) */ 120 | count_t vswap; /* swap space used (Kb) */ 121 | count_t vlock; /* virtual locked (Kb) */ 122 | count_t cfuture[7]; /* reserved for future use */ 123 | } mem; 124 | 125 | /* NETWORK STATISTICS */ 126 | struct net { 127 | count_t tcpsnd; /* number of TCP-packets sent */ 128 | count_t tcpssz; /* cumulative size packets sent */ 129 | count_t tcprcv; /* number of TCP-packets recved */ 130 | count_t tcprsz; /* cumulative size packets rcvd */ 131 | count_t udpsnd; /* number of UDP-packets sent */ 132 | count_t udpssz; /* cumulative size packets sent */ 133 | count_t udprcv; /* number of UDP-packets recved */ 134 | count_t udprsz; /* cumulative size packets sent */ 135 | count_t avail1; /* */ 136 | count_t avail2; /* */ 137 | count_t cfuture[4]; /* reserved for future use */ 138 | } net; 139 | 140 | struct gpu { 141 | char state; // A - active, E - Exit, '\0' - no use 142 | char type; // C - compute, G - graphic, U - unknown 143 | char bfuture[2]; // 144 | short nrgpus; // number of GPUs for this process 145 | int32_t gpulist; // bitlist with GPU numbers 146 | 147 | count_t gpubusycum; // cumulative gpu busy perc -1 = n/a 148 | count_t membusycum; // cumulative memory busy perc -1 = n/a 149 | 150 | count_t memnow; // current memory consumption in KiB 151 | count_t memcum; // cumulative memory consumption in KiB 152 | count_t samples; // number of samples that this process 153 | // was really active 154 | count_t cfuture[3]; // 155 | } gpu; 156 | }; 157 | 158 | 159 | struct pinfo { 160 | struct pinfo *phnext; /* next process in hash chain */ 161 | struct pinfo *prnext; /* next process in residue chain */ 162 | struct pinfo *prprev; /* prev process in residue chain */ 163 | 164 | struct tstat tstat; /* per-process statistics */ 165 | }; 166 | 167 | /* 168 | ** structure to maintains all deviation info related to one sample 169 | */ 170 | struct devtstat { 171 | struct tstat *taskall; // all processes (also exited) and threads 172 | struct tstat **procall; // all processes (also exited) 173 | struct tstat **procactive; // all processes (also exited) being active 174 | 175 | unsigned long ntaskall; 176 | unsigned long ntaskactive; 177 | unsigned long nprocall; 178 | unsigned long nprocactive; 179 | 180 | unsigned long totrun, totslpi, totslpu, totidle, totzombie; 181 | }; 182 | 183 | /* 184 | ** prototypes of process-database functions 185 | */ 186 | int pdb_gettask(int, char, time_t, struct pinfo **); 187 | void pdb_addtask(int, struct pinfo *); 188 | int pdb_deltask(int, char); 189 | int pdb_makeresidue(void); 190 | int pdb_cleanresidue(void); 191 | int pdb_srchresidue(struct tstat *, struct pinfo **); 192 | 193 | /* 194 | ** prototypes for raw process-statistics functions 195 | */ 196 | struct netpertask; 197 | 198 | void deviattask(struct tstat *, unsigned long, 199 | struct tstat *, unsigned long, 200 | struct devtstat *, struct sstat *); 201 | 202 | unsigned long photoproc(struct tstat *, int); 203 | unsigned long counttasks(void); 204 | 205 | #endif 206 | -------------------------------------------------------------------------------- /showgeneric.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** 7 | ** Include-file describing prototypes and structures for visualization 8 | ** of counters. 9 | ** ================================================================ 10 | ** Author: Gerlof Langeveld 11 | ** E-mail: gerlof.langeveld@atoptool.nl 12 | ** Date: July 2002 13 | ** 14 | ** This program is free software; you can redistribute it and/or modify it 15 | ** under the terms of the GNU General Public License as published by the 16 | ** Free Software Foundation; either version 2, or (at your option) any 17 | ** later version. 18 | ** 19 | ** This program is distributed in the hope that it will be useful, but 20 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 | ** See the GNU General Public License for more details. 23 | */ 24 | #ifndef __SHOWGENERIC__ 25 | #define __SHOWGENERIC__ 26 | 27 | #define USERSTUB 9999999 28 | #define MAXUSERSEL 64 29 | #define MAXPID 32 30 | 31 | // minimum screen dimensions 32 | // 33 | #define MINLINES 24 34 | #define MINCOLUMNS 60 35 | 36 | struct procview { 37 | unsigned char showtype; // type of process details 38 | unsigned char showresource; // current resource percentage 39 | unsigned char sortcolumn; // column index in alldetaildefs[] 40 | // 0 = resource percentage 41 | signed char ascdesc; // 1 (ascending) or -1 (descending) 42 | }; 43 | 44 | 45 | struct syscap { 46 | int nrcpu; 47 | count_t availcpu; 48 | count_t availmem; 49 | count_t availdsk; 50 | count_t availnet; 51 | int nrgpu; 52 | count_t availgpumem; // GPU memory in Kb! 53 | int nrmemnuma; 54 | int nrcpunuma; 55 | }; 56 | 57 | struct pselection { 58 | char username[256]; 59 | uid_t userid[MAXUSERSEL]; 60 | 61 | pid_t pid[MAXPID]; 62 | 63 | char progname[64]; 64 | int prognamesz; 65 | regex_t progregex; 66 | 67 | char argname[64]; 68 | int argnamesz; 69 | regex_t argregex; 70 | 71 | char utsname[UTSLEN+1]; 72 | 73 | char states[16]; 74 | }; 75 | 76 | struct sselection { 77 | char lvmname[64]; // logical volume selection 78 | int lvmnamesz; 79 | regex_t lvmregex; 80 | 81 | char dskname[64]; // disk selection 82 | int dsknamesz; 83 | regex_t dskregex; 84 | 85 | char itfname[64]; // network interface selection 86 | int itfnamesz; 87 | regex_t itfregex; 88 | }; 89 | 90 | /* 91 | ** color definitions 92 | */ 93 | #define COLOR_MYORANGE 20 94 | #define COLOR_MYGREEN 21 95 | #define COLOR_MYGREY 22 96 | #define COLOR_MYLGREY 23 97 | 98 | #define COLOR_MYBROWN1 24 99 | #define COLOR_MYBROWN2 25 100 | 101 | #define COLOR_MYBLUE0 26 102 | #define COLOR_MYBLUE1 27 103 | #define COLOR_MYBLUE2 28 104 | #define COLOR_MYBLUE3 29 105 | #define COLOR_MYBLUE4 30 106 | #define COLOR_MYBLUE5 31 107 | 108 | #define COLOR_MYGREEN0 35 109 | #define COLOR_MYGREEN1 36 110 | #define COLOR_MYGREEN2 37 111 | 112 | /* 113 | ** color pair definitions 114 | */ 115 | #define FGCOLORBORDER 1 116 | #define FGCOLORINFO 2 117 | #define FGCOLORALMOST 3 118 | #define FGCOLORCRIT 4 119 | #define FGCOLORTHR 5 120 | #define FGCOLORGREY 6 121 | 122 | #define WHITE_GREEN 10 123 | #define WHITE_ORANGE 11 124 | #define WHITE_RED 12 125 | #define WHITE_GREY 13 126 | #define WHITE_BLUE 14 127 | #define WHITE_MAGENTA 15 128 | 129 | #define WHITE_BROWN1 18 130 | #define WHITE_BROWN2 19 131 | 132 | #define WHITE_BLUE0 20 133 | #define WHITE_BLUE1 21 134 | #define WHITE_BLUE2 22 135 | #define WHITE_BLUE3 23 136 | #define WHITE_BLUE4 24 137 | #define WHITE_BLUE5 25 138 | 139 | #define WHITE_GREEN0 30 140 | #define WHITE_GREEN1 31 141 | #define WHITE_GREEN2 32 142 | 143 | /* 144 | ** text and bar color selections 145 | */ 146 | #define COLOROKAY WHITE_GREEN 147 | #define COLORWARN WHITE_ORANGE 148 | #define COLORBAD WHITE_RED 149 | 150 | #define COLORCPUSYS WHITE_BLUE1 151 | #define COLORCPUUSR WHITE_BLUE2 152 | #define COLORCPUINTR WHITE_BLUE3 153 | #define COLORCPUSTEAL WHITE_BLUE4 154 | #define COLORCPUGUEST WHITE_BLUE5 155 | 156 | #define COLORMEMFREE WHITE_GREEN 157 | #define COLORMEMCACH WHITE_ORANGE 158 | #define COLORMEMHUGE WHITE_BLUE5 159 | #define COLORMEMUSED WHITE_GREY 160 | #define COLORMEMSHM WHITE_BROWN1 161 | #define COLORMEMTMP WHITE_BLUE 162 | #define COLORMEMSLAB WHITE_MAGENTA 163 | #define COLORMEMBAR WHITE_BLUE3 164 | 165 | #define COLORDSKREAD WHITE_GREEN1 166 | #define COLORDSKWRITE WHITE_GREEN2 167 | 168 | #define COLORNETRECV WHITE_BROWN1 169 | #define COLORNETSEND WHITE_BROWN2 170 | 171 | /* 172 | ** list with keystrokes/flags 173 | */ 174 | #define MPROCGEN 'g' 175 | #define MPROCMEM 'm' 176 | #define MPROCDSK 'd' 177 | #define MPROCNET 'n' 178 | #define MPROCGPU 'e' 179 | #define MPROCSCH 's' 180 | #define MPROCVAR 'v' 181 | #define MPROCARG 'c' 182 | #define MCGROUPS 'G' 183 | #define MPROCOWN 'o' 184 | 185 | #define MCUMUSER 'u' 186 | #define MCUMPROC 'p' 187 | #define MCUMCONT 'j' 188 | 189 | #define MPERCCPU 'C' 190 | #define MPERCDSK 'D' 191 | #define MPERCMEM 'M' 192 | #define MPERCNET 'N' 193 | #define MPERCGPU 'E' 194 | 195 | #define MTHREAD 'y' 196 | #define MTHRSORT 'Y' 197 | #define MCALCPSS 'R' 198 | #define MGETWCHAN 'W' 199 | #define MSUPEXITS 'X' 200 | #define MCOLORS 'x' 201 | #define MSYSFIXED 'f' 202 | #define MSYSNOSORT 'F' 203 | #define MSYSLIMIT 'l' 204 | #define MRMSPACES 'Z' 205 | 206 | #define MSELUSER 'U' 207 | #define MSELPROC 'P' 208 | #define MSELCONT 'J' 209 | #define MSELPID 'I' 210 | #define MSELARG '/' 211 | #define MSELSTATE 'Q' 212 | #define MSELSYS 'S' 213 | 214 | #define MALLACTIVE 'a' 215 | 216 | #define MORDERPROC 'O' 217 | #define MKILLPROC 'k' 218 | #define MLISTFW 0x06 219 | #define MLISTBW 0x02 220 | #define MREDRAW 0x0c 221 | #define MINTERVAL 'i' 222 | #define MPAUSE 'z' 223 | #define MQUIT 'q' 224 | #define MRESET 'r' 225 | #define MEND 'Z' 226 | #define MSAMPNEXT 't' 227 | #define MSAMPPREV 'T' 228 | #define MSAMPBRANCH 'b' 229 | #define MVERSION 'V' 230 | #define MAVGVAL '1' 231 | #define MHELP1 '?' 232 | #define MHELP2 'h' 233 | 234 | #define MBARGRAPH 'B' 235 | #define MBARLOWER 'L' 236 | #define MBARMONO 'H' 237 | 238 | /* 239 | ** extern values for globals 240 | */ 241 | extern int paused; 242 | extern int cgroupdepth; 243 | 244 | /* 245 | ** general function prototypes 246 | */ 247 | void totalcap (struct syscap *, struct sstat *, struct tstat **, int); 248 | void pricumproc (struct sstat *, struct devtstat *, 249 | int, unsigned int, int, int); 250 | 251 | void showgenproc(struct tstat *, double, int, int); 252 | void showmemproc(struct tstat *, double, int, int); 253 | void showdskproc(struct tstat *, double, int, int); 254 | void shownetproc(struct tstat *, double, int, int); 255 | void showvarproc(struct tstat *, double, int, int); 256 | void showschproc(struct tstat *, double, int, int); 257 | void showtotproc(struct tstat *, double, int, int); 258 | void showcmdproc(struct tstat *, double, int, int); 259 | 260 | void printg(const char *, ...); 261 | int prisyst(struct sstat *, int, int, int, int, struct sselection *, 262 | int, int, int, int, int, int, int, int, int, int, int); 263 | void prihead(int, int, struct procview *, count_t); 264 | 265 | struct cglinesel; 266 | 267 | int pricgroup(struct cglinesel *, int, int, int, int, int, 268 | struct syscap *, int, int); 269 | 270 | int priproc(struct tstat **, int, int, int, int, int, struct procview *, 271 | struct syscap *, int, int); 272 | 273 | char draw_samp(time_t, int, struct sstat *, char, char); 274 | 275 | void do_username(char *, char *); 276 | void do_procname(char *, char *); 277 | void do_maxcpu(char *, char *); 278 | void do_maxgpu(char *, char *); 279 | void do_maxdisk(char *, char *); 280 | void do_maxmdd(char *, char *); 281 | void do_maxlvm(char *, char *); 282 | void do_maxintf(char *, char *); 283 | void do_maxifb(char *, char *); 284 | void do_maxnfsm(char *, char *); 285 | void do_maxcont(char *, char *); 286 | void do_maxnuma(char *, char *); 287 | void do_maxllc(char *, char *); 288 | void do_colinfo(char *, char *); 289 | void do_colalmost(char *, char *); 290 | void do_colcrit(char *, char *); 291 | void do_colthread(char *, char *); 292 | void do_twindir(char *, char *); 293 | void do_flags(char *, char *); 294 | 295 | #endif 296 | -------------------------------------------------------------------------------- /procdbase.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** ATOP - System & Process Monitor 3 | ** 4 | ** The program 'atop' offers the possibility to view the activity of 5 | ** the system on system-level as well as process-level. 6 | ** 7 | ** This source-file contains all functions required to manipulate the 8 | ** process-database. This database is implemented as a linked list of 9 | ** all running processes, needed to remember the process-counters from 10 | ** the previous sample. 11 | ** ========================================================================== 12 | ** Author: Gerlof Langeveld 13 | ** E-mail: gerlof.langeveld@atoptool.nl 14 | ** Date: November 1996 15 | ** LINUX-port: June 2000 16 | ** -------------------------------------------------------------------------- 17 | ** Copyright (C) 2000-2012 Gerlof Langeveld 18 | ** 19 | ** This program is free software; you can redistribute it and/or modify it 20 | ** under the terms of the GNU General Public License as published by the 21 | ** Free Software Foundation; either version 2, or (at your option) any 22 | ** later version. 23 | ** 24 | ** This program is distributed in the hope that it will be useful, but 25 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 26 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 27 | ** See the GNU General Public License for more details. 28 | ** 29 | ** You should have received a copy of the GNU General Public License 30 | ** along with this program; if not, write to the Free Software 31 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 32 | ** -------------------------------------------------------------------------- 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "atop.h" 45 | #include "photoproc.h" 46 | 47 | /*****************************************************************************/ 48 | #define NPHASH 256 /* number of hash queues for process dbase */ 49 | /* MUST be a power of 2 !!! */ 50 | 51 | /* hash buckets for getting process-info */ 52 | /* for a given PID */ 53 | static struct pinfo *phash[NPHASH]; 54 | 55 | /* cyclic list of all processes, to detect */ 56 | /* which processes were not referred */ 57 | static struct pinfo presidue; 58 | /*****************************************************************************/ 59 | 60 | 61 | /* 62 | ** search process database for the given PID 63 | */ 64 | int 65 | pdb_gettask(int pid, char isproc, time_t btime, struct pinfo **pinfopp) 66 | { 67 | register struct pinfo *pp; 68 | 69 | pp = phash[pid&(NPHASH-1)]; /* get proper hash bucket */ 70 | 71 | /* 72 | ** scan all entries in hash Q 73 | */ 74 | while (pp) 75 | { 76 | /* 77 | ** if this is required PID, unchain it from the RESIDUE-list 78 | ** and return info 79 | */ 80 | if (pp->tstat.gen.pid == pid && 81 | pp->tstat.gen.isproc == isproc ) 82 | { 83 | int diff = pp->tstat.gen.btime - btime; 84 | 85 | /* 86 | ** with longer intervals, the same PID might be 87 | ** found more than once, so also check the start 88 | ** time of the task 89 | */ 90 | if (diff > 1 || diff < -1) 91 | { 92 | pp = pp->phnext; 93 | continue; 94 | } 95 | 96 | if (pp->prnext) /* if part of RESIDUE-list */ 97 | { 98 | (pp->prnext)->prprev = pp->prprev; /* unchain */ 99 | (pp->prprev)->prnext = pp->prnext; 100 | } 101 | 102 | pp->prnext = NULL; 103 | pp->prprev = NULL; 104 | 105 | *pinfopp = pp; 106 | 107 | return 1; 108 | } 109 | 110 | pp = pp->phnext; 111 | } 112 | 113 | /* 114 | ** end of list; PID not found 115 | */ 116 | return 0; 117 | } 118 | 119 | /* 120 | ** add new process-info structure to the process database 121 | */ 122 | void 123 | pdb_addtask(int pid, struct pinfo *pinfop) 124 | { 125 | register int i = pid&(NPHASH-1); 126 | 127 | pinfop->phnext = phash[i]; 128 | phash[i] = pinfop; 129 | } 130 | 131 | /* 132 | ** delete a process from the process database 133 | */ 134 | int 135 | pdb_deltask(int pid, char isproc) 136 | { 137 | register struct pinfo *pp, *ppp; 138 | 139 | pp = phash[pid&(NPHASH-1)]; /* get proper hash bucket */ 140 | 141 | /* 142 | ** check first entry in hash Q 143 | */ 144 | if (pp->tstat.gen.pid == pid && pp->tstat.gen.isproc == isproc) 145 | { 146 | phash[pid&(NPHASH-1)] = pp->phnext; 147 | 148 | if ( pp->prnext ) /* still part of RESIDUE-list ? */ 149 | { 150 | (pp->prprev)->prnext = pp->prnext; 151 | (pp->prnext)->prprev = pp->prprev; /* unchain */ 152 | } 153 | 154 | /* 155 | ** remove process-info from process-database 156 | */ 157 | free(pp); 158 | 159 | return 1; 160 | } 161 | 162 | /* 163 | ** scan other entries of hash-list 164 | */ 165 | ppp = pp; 166 | pp = pp->phnext; 167 | 168 | while (pp) 169 | { 170 | /* 171 | ** if this is wanted PID, unchain it from the RESIDUE-list 172 | ** and return info 173 | */ 174 | if (pp->tstat.gen.pid == pid && pp->tstat.gen.isproc == isproc) 175 | { 176 | ppp->phnext = pp->phnext; 177 | 178 | if ( pp->prnext ) /* part of RESIDUE-list ? */ 179 | { 180 | (pp->prnext)->prprev = pp->prprev; 181 | (pp->prprev)->prnext = pp->prnext; 182 | } 183 | 184 | /* 185 | ** remove process-info from process-database 186 | */ 187 | free(pp); 188 | 189 | return 1; 190 | } 191 | 192 | ppp = pp; 193 | pp = pp->phnext; 194 | } 195 | 196 | return 0; /* PID not found */ 197 | } 198 | 199 | /* 200 | ** Chain all process-info structures into the RESIDUE-list; 201 | ** every process-info struct which is referenced later on by pdb_gettask(), 202 | ** will be removed from this list again. After that, the remaining 203 | ** (unreferred) process-info structs can be easily discovered and 204 | ** eventually removed. 205 | */ 206 | int 207 | pdb_makeresidue(void) 208 | { 209 | register struct pinfo *pp, *pr; 210 | register int i; 211 | 212 | /* 213 | ** prepare RESIDUE-list anchor 214 | */ 215 | pr = &presidue; 216 | 217 | pr->prnext = pr; 218 | pr->prprev = pr; 219 | 220 | /* 221 | ** check all entries in hash list 222 | */ 223 | for (i=0; i < NPHASH; i++) 224 | { 225 | if (!phash[i]) 226 | continue; /* empty hash bucket */ 227 | 228 | pp = phash[i]; /* get start of list */ 229 | 230 | while (pp) /* all entries in hash list */ 231 | { 232 | pp->prnext = pr->prnext; 233 | pr->prnext = pp; 234 | 235 | pp->prprev = (pp->prnext)->prprev; 236 | (pp->prnext)->prprev = pp; 237 | 238 | pp = pp->phnext; /* get next of hash list */ 239 | } 240 | } 241 | 242 | /* 243 | ** all entries chained in doubly-linked RESIDUE-list 244 | */ 245 | return 1; 246 | } 247 | 248 | /* 249 | ** remove all remaining entries in RESIDUE-list 250 | */ 251 | int 252 | pdb_cleanresidue(void) 253 | { 254 | register struct pinfo *pr; 255 | register int pid; 256 | char isproc; 257 | 258 | /* 259 | ** start at RESIDUE-list anchor and delete all entries 260 | */ 261 | pr = presidue.prnext; 262 | 263 | while (pr != &presidue) 264 | { 265 | pid = pr->tstat.gen.pid; 266 | isproc = pr->tstat.gen.isproc; 267 | 268 | pr = pr->prnext; /* MUST be done before deletion */ 269 | 270 | pdb_deltask(pid, isproc); 271 | } 272 | 273 | return 1; 274 | } 275 | 276 | /* 277 | ** search in the RESIDUE-list for process-info which may fit to the 278 | ** given process-info, for which the PID is not known 279 | */ 280 | int 281 | pdb_srchresidue(struct tstat *tstatp, struct pinfo **pinfopp) 282 | { 283 | register struct pinfo *pr, *prmin=NULL; 284 | register long btimediff; 285 | 286 | /* 287 | ** start at RESIDUE-list anchor and search through 288 | ** all remaining entries 289 | */ 290 | pr = presidue.prnext; 291 | 292 | while (pr != &presidue) /* still entries left ? */ 293 | { 294 | /* 295 | ** check if this entry matches searched info 296 | */ 297 | if ( pr->tstat.gen.ruid == tstatp->gen.ruid && 298 | pr->tstat.gen.rgid == tstatp->gen.rgid && 299 | strcmp(pr->tstat.gen.name, tstatp->gen.name) == EQ ) 300 | { 301 | /* 302 | ** check if the start-time of the process is exactly 303 | ** the same ----> then we have a match; 304 | ** however sometimes the start-time may deviate a 305 | ** second although it IS the process we are looking 306 | ** for (depending on the rounding of the boot-time), 307 | ** so if we don't find the exact match, we will check 308 | ** later on if we found an almost-exact match 309 | */ 310 | btimediff = pr->tstat.gen.btime - tstatp->gen.btime; 311 | 312 | if (btimediff == 0) /* gotcha !! */ 313 | { 314 | *pinfopp = pr; 315 | return 1; 316 | } 317 | 318 | if ((btimediff== -1 || btimediff== 1) && prmin== NULL) 319 | prmin = pr; /* remember this process */ 320 | } 321 | 322 | pr = pr->prnext; 323 | } 324 | 325 | /* 326 | ** nothing found that matched exactly; 327 | ** do we remember a process that matched almost exactly? 328 | */ 329 | if (prmin) 330 | { 331 | *pinfopp = prmin; 332 | return 1; 333 | } 334 | 335 | return 0; /* even not almost */ 336 | } 337 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for System & Process Monitor ATOP (Linux version) 2 | # 3 | # Gerlof Langeveld - gerlof.langeveld@atoptool.nl 4 | # 5 | DESTDIR = 6 | 7 | BINPATH = /usr/bin 8 | SBINPATH = /usr/sbin 9 | SCRPATH = /usr/share/atop 10 | LOGPATH = /var/log/atop 11 | MAN1PATH = /usr/share/man/man1 12 | MAN5PATH = /usr/share/man/man5 13 | MAN8PATH = /usr/share/man/man8 14 | INIPATH = /etc/init.d 15 | DEFPATH = /etc/default 16 | SYSDPATH = /lib/systemd/system 17 | CRNPATH = /etc/cron.d 18 | ROTPATH = /etc/logrotate.d 19 | PMPATH1 = /usr/lib/pm-utils/sleep.d 20 | PMPATH2 = /usr/lib64/pm-utils/sleep.d 21 | PMPATHD = /usr/lib/systemd/system-sleep 22 | 23 | PKG_CONFIG ?= pkg-config 24 | 25 | override CFLAGS := -O2 -I. -Wall $(shell $(PKG_CONFIG) --cflags glib-2.0) -Wmissing-prototypes -Wmissing-declarations -Wformat-security $(CFLAGS) # -DNOPERFEVENT # -DHTTPSTATS 26 | 27 | CC_CHECK := $(shell echo | $(CC) -dM -E - | grep -q __clang__ && echo clang || echo gcc) 28 | ifeq ($(CC_CHECK),gcc) 29 | override CFLAGS += -Wno-stringop-truncation 30 | endif 31 | 32 | override LDFLAGS := $(shell $(PKG_CONFIG) --libs glib-2.0) $(LDFLAGS) 33 | 34 | OBJMOD0 = version.o 35 | OBJMOD1 = various.o deviate.o procdbase.o 36 | OBJMOD2 = acctproc.o photoproc.o photosyst.o cgroups.o rawlog.o ifprop.o parseable.o 37 | OBJMOD3 = showgeneric.o drawbar.o showlinux.o showsys.o showprocs.o 38 | OBJMOD4 = atopsar.o netatopif.o netatopbpfif.o gpucom.o json.o utsnames.o 39 | ALLMODS = $(OBJMOD0) $(OBJMOD1) $(OBJMOD2) $(OBJMOD3) $(OBJMOD4) 40 | 41 | VERS = $(shell ./atop -V 2>/dev/null| sed -e 's/^[^ ]* //' -e 's/ .*//') 42 | 43 | all: atop atopsar atopacctd atopconvert atopcat atophide 44 | 45 | atop: atop.o $(ALLMODS) Makefile 46 | $(CC) atop.o $(ALLMODS) -o atop -lncursesw -lz -lm -lrt $(LDFLAGS) 47 | 48 | atopsar: atop 49 | ln -sf atop atopsar 50 | 51 | atopacctd: atopacctd.o netlink.o 52 | $(CC) atopacctd.o netlink.o -o atopacctd $(LDFLAGS) 53 | 54 | atopconvert: atopconvert.o 55 | $(CC) atopconvert.o -o atopconvert -lz $(LDFLAGS) 56 | 57 | atopcat: atopcat.o 58 | $(CC) atopcat.o -o atopcat $(LDFLAGS) 59 | 60 | atophide: atophide.o 61 | $(CC) atophide.o -o atophide -lz $(LDFLAGS) 62 | 63 | clean: 64 | rm -f *.o atop atopsar atopacctd atopconvert atopcat atophide versdate.h 65 | 66 | distr: 67 | rm -f *.o atop 68 | tar czvf /tmp/atop.tar.gz * 69 | 70 | # default install is based on systemd 71 | # 72 | install: genericinstall 73 | if [ ! -d $(DESTDIR)$(SYSDPATH) ]; \ 74 | then mkdir -p $(DESTDIR)$(SYSDPATH); fi 75 | if [ ! -d $(DESTDIR)$(PMPATHD) ]; \ 76 | then mkdir -p $(DESTDIR)$(PMPATHD); fi 77 | # 78 | cp atop.service $(DESTDIR)$(SYSDPATH) 79 | chmod 0644 $(DESTDIR)$(SYSDPATH)/atop.service 80 | cp atopgpu.service $(DESTDIR)$(SYSDPATH) 81 | chmod 0644 $(DESTDIR)$(SYSDPATH)/atopgpu.service 82 | cp atop-rotate.service $(DESTDIR)$(SYSDPATH) 83 | chmod 0644 $(DESTDIR)$(SYSDPATH)/atop-rotate.service 84 | cp atop-rotate.timer $(DESTDIR)$(SYSDPATH) 85 | chmod 0644 $(DESTDIR)$(SYSDPATH)/atop-rotate.timer 86 | cp atopacct.service $(DESTDIR)$(SYSDPATH) 87 | chmod 0644 $(DESTDIR)$(SYSDPATH)/atopacct.service 88 | cp atop-pm.sh $(DESTDIR)$(PMPATHD) 89 | chmod 0711 $(DESTDIR)$(PMPATHD)/atop-pm.sh 90 | # 91 | # only when making on target system: 92 | # 93 | if [ -z "$(DESTDIR)" -a -f /bin/systemctl ]; \ 94 | then /bin/systemctl disable --now atop 2> /dev/null; \ 95 | /bin/systemctl disable --now atopacct 2> /dev/null; \ 96 | /bin/systemctl daemon-reload; \ 97 | /bin/systemctl enable --now atopacct; \ 98 | /bin/systemctl enable --now atop; \ 99 | /bin/systemctl enable --now atop-rotate.timer; \ 100 | fi 101 | 102 | 103 | # explicitly use sysvinstall for System V init based systems 104 | # 105 | sysvinstall: genericinstall 106 | if [ ! -d $(DESTDIR)$(INIPATH) ]; \ 107 | then mkdir -p $(DESTDIR)$(INIPATH); fi 108 | if [ ! -d $(DESTDIR)$(SCRPATH) ]; \ 109 | then mkdir -p $(DESTDIR)$(SCRPATH); fi 110 | if [ ! -d $(DESTDIR)$(CRNPATH) ]; \ 111 | then mkdir -p $(DESTDIR)$(CRNPATH); fi 112 | if [ ! -d $(DESTDIR)$(ROTPATH) ]; \ 113 | then mkdir -p $(DESTDIR)$(ROTPATH); fi 114 | # 115 | cp atop.init $(DESTDIR)$(INIPATH)/atop 116 | cp atopacct.init $(DESTDIR)$(INIPATH)/atopacct 117 | cp atop.cronsysv $(DESTDIR)$(CRNPATH)/atop 118 | cp atop.daily $(DESTDIR)$(SCRPATH) 119 | chmod 0711 $(DESTDIR)$(SCRPATH)/atop.daily 120 | touch $(DESTDIR)$(LOGPATH)/dummy_before 121 | touch $(DESTDIR)$(LOGPATH)/dummy_after 122 | # 123 | if [ -d $(DESTDIR)$(PMPATH1) ]; \ 124 | then cp 45atoppm $(DESTDIR)$(PMPATH1); \ 125 | chmod 0711 $(DESTDIR)$(PMPATH1)/45atoppm; \ 126 | fi 127 | if [ -d $(DESTDIR)$(PMPATH2) ]; \ 128 | then cp 45atoppm $(DESTDIR)$(PMPATH2); \ 129 | chmod 0711 $(DESTDIR)$(PMPATH2)/45atoppm; \ 130 | fi 131 | # 132 | # 133 | # only when making on target system: 134 | # 135 | if [ -z "$(DESTDIR)" -a -f /sbin/chkconfig ]; \ 136 | then /sbin/chkconfig --del atop 2> /dev/null; \ 137 | /sbin/chkconfig --add atop; \ 138 | /sbin/chkconfig --del atopacct 2> /dev/null; \ 139 | /sbin/chkconfig --add atopacct; \ 140 | fi 141 | if [ -z "$(DESTDIR)" -a -f /usr/sbin/update-rc.d ]; \ 142 | then update-rc.d atop defaults; \ 143 | update-rc.d atopacct defaults; \ 144 | fi 145 | if [ -z "$(DESTDIR)" -a -f /sbin/service ]; \ 146 | then /sbin/service atopacct start; \ 147 | sleep 2; \ 148 | /sbin/service atop start; \ 149 | fi 150 | 151 | 152 | genericinstall: atop atopacctd atopconvert atopcat atophide 153 | if [ ! -d $(DESTDIR)$(LOGPATH) ]; \ 154 | then mkdir -p $(DESTDIR)$(LOGPATH); fi 155 | if [ ! -d $(DESTDIR)$(DEFPATH) ]; \ 156 | then mkdir -p $(DESTDIR)$(DEFPATH); fi 157 | if [ ! -d $(DESTDIR)$(BINPATH) ]; \ 158 | then mkdir -p $(DESTDIR)$(BINPATH); fi 159 | if [ ! -d $(DESTDIR)$(SBINPATH) ]; \ 160 | then mkdir -p $(DESTDIR)$(SBINPATH); fi 161 | if [ ! -d $(DESTDIR)$(MAN1PATH) ]; \ 162 | then mkdir -p $(DESTDIR)$(MAN1PATH); fi 163 | if [ ! -d $(DESTDIR)$(MAN5PATH) ]; \ 164 | then mkdir -p $(DESTDIR)$(MAN5PATH); fi 165 | if [ ! -d $(DESTDIR)$(MAN8PATH) ]; \ 166 | then mkdir -p $(DESTDIR)$(MAN8PATH); fi 167 | # 168 | touch $(DESTDIR)$(DEFPATH)/atop 169 | chmod 644 $(DESTDIR)$(DEFPATH)/atop 170 | # 171 | cp atop $(DESTDIR)$(BINPATH)/atop 172 | chmod 0711 $(DESTDIR)$(BINPATH)/atop 173 | ln -sf atop $(DESTDIR)$(BINPATH)/atopsar 174 | cp atopacctd $(DESTDIR)$(SBINPATH)/atopacctd 175 | chmod 0700 $(DESTDIR)$(SBINPATH)/atopacctd 176 | cp atopgpud $(DESTDIR)$(SBINPATH)/atopgpud 177 | chmod 0700 $(DESTDIR)$(SBINPATH)/atopgpud 178 | cp atop $(DESTDIR)$(BINPATH)/atop-$(VERS) 179 | ln -sf atop-$(VERS) $(DESTDIR)$(BINPATH)/atopsar-$(VERS) 180 | cp atopconvert $(DESTDIR)$(BINPATH)/atopconvert 181 | chmod 0711 $(DESTDIR)$(BINPATH)/atopconvert 182 | cp atopcat $(DESTDIR)$(BINPATH)/atopcat 183 | chmod 0711 $(DESTDIR)$(BINPATH)/atopcat 184 | cp atophide $(DESTDIR)$(BINPATH)/atophide 185 | chmod 0711 $(DESTDIR)$(BINPATH)/atophide 186 | cp man/atop.1 $(DESTDIR)$(MAN1PATH) 187 | cp man/atopsar.1 $(DESTDIR)$(MAN1PATH) 188 | cp man/atopconvert.1 $(DESTDIR)$(MAN1PATH) 189 | cp man/atopcat.1 $(DESTDIR)$(MAN1PATH) 190 | cp man/atophide.1 $(DESTDIR)$(MAN1PATH) 191 | cp man/atoprc.5 $(DESTDIR)$(MAN5PATH) 192 | cp man/atopacctd.8 $(DESTDIR)$(MAN8PATH) 193 | cp man/atopgpud.8 $(DESTDIR)$(MAN8PATH) 194 | 195 | ########################################################################## 196 | 197 | versdate.h: 198 | ./mkdate 199 | 200 | atop.o: atop.h photoproc.h photosyst.h acctproc.h showgeneric.h 201 | atopsar.o: atop.h photoproc.h photosyst.h 202 | rawlog.o: atop.h photoproc.h photosyst.h rawlog.h showgeneric.h 203 | various.o: atop.h acctproc.h 204 | ifprop.o: atop.h photosyst.h ifprop.h 205 | parseable.o: atop.h photoproc.h photosyst.h cgroups.h parseable.h 206 | deviate.o: atop.h photoproc.h photosyst.h 207 | procdbase.o: atop.h photoproc.h 208 | acctproc.o: atop.h photoproc.h atopacctd.h acctproc.h netatop.h 209 | netatopif.o: atop.h photoproc.h netatopd.h netatop.h 210 | netatopbpfif.o: atop.h photoproc.h netatop.h 211 | photoproc.o: atop.h photoproc.h 212 | photosyst.o: atop.h photosyst.h 213 | cgroups.o: atop.h cgroups.h 214 | showgeneric.o: atop.h photoproc.h photosyst.h cgroups.h showgeneric.h showlinux.h 215 | showlinux.o: atop.h photoproc.h photosyst.h cgroups.h showgeneric.h showlinux.h 216 | showsys.o: atop.h photoproc.h photosyst.h showgeneric.h 217 | showprocs.o: atop.h photoproc.h photosyst.h cgroups.h showgeneric.h showlinux.h 218 | drawbar.o: atop.h photosyst.h showgeneric.h 219 | version.o: version.c version.h versdate.h 220 | gpucom.o: atop.h photoproc.h photosyst.h 221 | 222 | atopacctd.o: atop.h photoproc.h acctproc.h atopacctd.h version.h versdate.h 223 | 224 | atopconvert.o: atop.h photoproc.h photosyst.h rawlog.h 225 | atopcat.o: atop.h rawlog.h 226 | atophide.o: atop.h photoproc.h photosyst.h rawlog.h 227 | --------------------------------------------------------------------------------