Timo Kokkonen [Thu, 2 Sep 2010 15:35:55 +0000 (18:35 +0300)]
main: Assume non-option arguments to be pids or process names
If arguments are given without any option arguments, it is tested if
it is a valid pid number, and add it to pidlist. If it is not a pid
number, then it is threated as a process name the system is scanned
for processes with a matching name.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sun, 29 Aug 2010 10:30:33 +0000 (13:30 +0300)]
Analyzer: Print detailed kpageflag statistics
The print_page_statst() function is modified so that it will count how
many pages are found with each of the kpageflag bit set. The collected
stats are then printed so that count for every non-zero kpageflag is
shown. Since there are so many kpageflag flags (22 at the moment),
zero number counts are alwaysy omitted.
Since root priviledges are required to read the /proc/kpageflag
interface, all of the kpageflag counts are zero if user does not have
root priviledges.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Thu, 26 Aug 2010 18:43:32 +0000 (21:43 +0300)]
parser: Remove unaccessible pids from the pidlist
If scan-pagemap is run without root priviledges and --shared-mappings
option is used, pids that are inaccessible to the user need to be
removed from the list of interesting pids. Otherwise
dunp_process_maps() will not print any pages for the given processes,
as it will try to count pages that are shared with all interesting
pids. If any pids from the list are inaccessible to the user, then
none of the pages are shared with these inaccessible pids. Therefore,
the inaccessible pids must be removed from the list altogether.
Since list entries are being removed from the list, all
list_for_each_entry will be need to be replaced with the _safe
variant.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sat, 21 Aug 2010 07:24:07 +0000 (10:24 +0300)]
main.c: Allow scanning multiple processes by name
Now that we have code in place for scanning multiple pid numbers, we
can also convert all process names to pids. That way, it becomes also
possible to add all process names user has given as an argument.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sat, 21 Aug 2010 07:18:24 +0000 (10:18 +0300)]
Analyzer: Drop PRETTY_THRESH value to 98
We have reserved five digits for the byte sizes in the print
output. However, if the size of a process happens to be for example
101272kB, the size is still below the 100 * 1024 = 102400 kB
threshold, which has in fact six digits.
Lowering the threshold to 98 will ensure the pretty output is never
more than five digits.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Wed, 18 Aug 2010 16:34:19 +0000 (19:34 +0300)]
Mark initially scanned pids in analyzer printouts
Since the initial page mappings are are collected from one or more
pids, they deserve to be marked on the analyzer output. That way the
user will know which are the processes that have all of their pages
counted and which have only those pages counted that are shared with
any of the interesting processes.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Wed, 18 Aug 2010 16:31:13 +0000 (19:31 +0300)]
Add macro for testing parse option flags
The parse option structure parse_mask variable is tested for option
bits in quite many places. Add a macro that makes testing easier and
moves the duplicate code in one macro.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Wed, 18 Aug 2010 16:12:24 +0000 (19:12 +0300)]
Analyzer: Show prints in kilobyte resolution
Since all pages are 4kB in size, all mapping and process sizes are
also always divizable by 4kB. Therefore it makes no sense to show
sizes less than 100kB in bytes. Using kilobyte as a smallest possible
size improves readability.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Mon, 16 Aug 2010 18:23:30 +0000 (21:23 +0300)]
Compact pageframe structure
Instead of decoding each entry to individual variables in the
pageframe structure, maintain them as a single raw 64 bit
value. Various helper functions are introduced for decoding the
information on the fly. This reduces the run time memory consumption
without really slowing down the execution.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sun, 15 Aug 2010 19:44:14 +0000 (22:44 +0300)]
print_page_stats: Print unique pages
Now that we don't scan interesting processes multiple times, we can
count the pages which have refcount == 1 as unique pages and show that
number to the user.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sun, 15 Aug 2010 19:37:16 +0000 (22:37 +0300)]
parser: When scannin by name, scan all pids twice
When scanning by a mapping name, we must first scan through all
processes to find out which processes are using the mappings. Then we
need to scan all pids again to find out if there are somewhere
physical pages that are being shared by the given mapping with a
different name.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sun, 15 Aug 2010 17:45:57 +0000 (20:45 +0300)]
Correct the usage of linked lists
There is really no documentation about how the linked lists in the
lists.h should be used. Specifically, it does not mention the fact
that the head entry of the list should never be used at all. Instead,
the head entry, when being empty, just points to itself.
Now that this fact is clear, a lot of difficult assumptions can be
left out and some overly complicated code can be cleared with the list
handling. This is because the head entry does not have to contain a
valid entry at all.
This also fixes a bug with was caused by the incorrect list handling:
printing the process list always had the head entry missing, since the
list_for_all() functions left the head entry unhandled for purpose.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sun, 15 Aug 2010 16:43:08 +0000 (19:43 +0300)]
parser: Do not scan processes twice
Before we would scan some processes twice: First when we find out the
pages of the interesting processes, then again when we scan the rest
of the processes. This patch changes the handling so that the second
time we ignore all interesting pids that we already scanned.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sun, 15 Aug 2010 16:39:10 +0000 (19:39 +0300)]
read_pageframe: Do not add empty entries in process list
If reading of some of the process details fails, the process is most
likely died while we were processing its details. Thus, there is no
good to add the entry to the process list either. The entry is now
freed instead of adding the half-read entry to the list.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sat, 14 Aug 2010 16:56:09 +0000 (19:56 +0300)]
parser: Fix the order of argumets for list_add()
The parameters were in wrong order, thus causing the new pageframe
referencing node to be lost for most of the processes. The results
were thus showing only references for only the first pid that was
found, ignoring everything else. This fix will thus improve the
results dramatically.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Fri, 23 Jul 2010 12:38:59 +0000 (15:38 +0300)]
Break parsing if no processes are found
Scanning through all pids in the system can be a time consuming task,
especially with slower CPUs. Therefore, if the user gives a
nonexistent process argument it can tage significant amount of time
until the user gets the response that there will be no useful results
available.
This patch counts the number of processes that have been encoutered
during the prescan. If the count is zero, then it is no good to
proceed scanning all of the rest processes. As an extra benefit, the
number of prescanned processes can be used for something useful..
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Thu, 22 Jul 2010 11:19:45 +0000 (14:19 +0300)]
parser: get_next_pid: Do not store state internally
Storing the directory state internally may conflict in case there are
multiple users to the get_next_pid function. The directory state is
now taken as an argument and caller will store it.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Thu, 22 Jul 2010 09:12:07 +0000 (12:12 +0300)]
Scan threads only when requested
Usually there is no need to scan every threads for every processes, as
they are very likely to share their address space between each
others. Thus, scanning only one of them is mostly enough.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Fri, 16 Jul 2010 12:00:22 +0000 (15:00 +0300)]
parse_pageframe: Fully ignore all unused pages
The pagemap data read from the file might contain only the page shift
field, nothing else. That kind of pages are really not useful, so they
can be skipped.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Wed, 14 Jul 2010 19:10:28 +0000 (22:10 +0300)]
analyzer: Sort processes based on both swapped and present size
Sorting by only the present size will cause the logic to get in an
infinite loop, since the exit criteria for the print loop is that the
sum of the swapped and present size needs to be zero.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Wed, 14 Jul 2010 13:17:25 +0000 (16:17 +0300)]
parser: Populate the pageframe tree by scanning interesting pids first
The "interesting" pids needs to be scanned always first, since later
on the pages from "noninteresting" pids are compared to the ones
already in the tree. We are optimizing by not storing anything out of
interest in the tree.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Mon, 5 Jul 2010 19:21:46 +0000 (22:21 +0300)]
Handle the process name better
Read the name from cmdline instead of the comm file. It appears that
at least in ubuntu kernel the comm file is not even
exposed. Furthermore, the newline in the end of the cmdline is
replaced with null byte. This also ensures that the string is always
null terminated even though the string is otherwise truncated.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sun, 4 Jul 2010 13:26:56 +0000 (16:26 +0300)]
analyzer: Remodify the pretty prints
Now there is an adjustable limit when prettifying prints takes
effect. When the number goes above the threshold, the number is
divided to look prettier.
After this change, there is still enough accuracy in the numbers to
keep them meaningful even though they are shrunk dramatically.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
Timo Kokkonen [Sun, 4 Jul 2010 12:58:57 +0000 (15:58 +0300)]
Make it possible to scan only interesting pids
When scanning "non-interesting" pids, the pageframes are not populated
in the tree. This makes it possible to reduce memory consumption
significantly by discarding uninterested data.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>