Linux monitor cpu and memory usage11/29/2023 Tasks: 8 total, 1 running, 6 sleeping, 1 stopped, 0 zombie =746= error calling PR_SET_PTRACER, vgdb might block =746= Using Valgrind-3.15.0 and LibVEX rerun with -h for copyright info =746= Copyright (C) 2003-2017, and GNU GPL'd, by Nicholas Nethercote A simple valgrind massif one-liner to depict peak memory usage of the ‘ top‘ process will look like: $ valgrind -tool=massif -pages-as-heap=yes -massif-out-file=massif.out top grep mem_heap_B massif.out | sed -e 's/mem_heap_B=\(.*\)/\1/' | sort -g | tail -n 1 Massif, one of the Valgrind tools, measures the heap memory used by a specific program. This information stored in memory segments represents the average total (data+stack+text) memory use (K), and the maximum resident set size (M) of the process. We can also create an alias or adjust the environment to use GNU time for average and maximum memory information: alias time="$(which time) -f '\t%E real,\t%U user,\t%S sys,\t%K amem,\t%M mmem'"Įxport TIME="$(which time) -f '\t%E real,\t%U user,\t%S sys,\t%K amem,\t%M mmem'" In bash, we need to specify the full path, such as /usr/bin/time, because the bash built-in time keyword doesn’t support the -f option: $ /usr/bin/time -f '%M' top Apart from memory usage, GNU time with the %P option provides unrelated statistics (%CPU), which depends on the scheduler and is therefore quite variable: $ /usr/bin/time -f "%P %M" top In this case, it’s the “Maximum resident set size” that tells us so: $ /usr/bin/time -v top | grep "Maximum resident set size" Suppose we want to know the peak memory usage of the ‘ top‘ process. Let’s understand the GNU time in the given context by going through a few examples. We’ll use atop -w if we need to record the output to a file: $ atop -w filenameĪnd we’ll use atop -r if we need to playback the output from that file: To keep a record, we can schedule a cron job to write the output to a file, so it becomes feasible to play back later. Its advantage is the very useful feature of recording the output in a file.Ĭonsider an issue that happens once and again at a particular time window. It has the command column, which is convenient to recognize the process path.Ītop is again a command like top and htop. Htop is similar to top, but shows more data about a process. Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |