]> git.itanic.dy.fi Git - scan-pagemap/log
scan-pagemap
3 years agoReverse list printing order master
Timo Kokkonen [Sat, 29 Dec 2018 15:06:11 +0000 (17:06 +0200)]
Reverse list printing order

The process and mapping lists are often very long and rarely fit
entirely on the screen. Usually we are most interested in the largest
entries, the ones that now get printed in the beginning of the
list. This is cumbersome as it therefore requires quite a bit of
scrolling to see what you really want.

Reverse the list printing order so that the tool becomes more friendly
to the end user.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
10 years agoparse_maps: Fix issues with white space in file names
Timo Kokkonen [Thu, 12 Jul 2012 14:41:49 +0000 (17:41 +0300)]
parse_maps: Fix issues with white space in file names

If there is any white space character in the file name field, sscanf
would only copy the file name part until the first white space and
leave out everything else.

The fix is trivial; we will use the %n with sscanf to find out all the
chars before the file name part and then skip that part when using
strncpy to copy the file name.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
10 years agoprint_page_stats: Reserve 7 digits for page count alignment
Timo Kokkonen [Mon, 11 Jun 2012 19:19:55 +0000 (22:19 +0300)]
print_page_stats: Reserve 7 digits for page count alignment

If there are mappings that are larger than 4 gigabytes, 6 digits is
not enough for the output. 7 digits is enough until 40 gigabytes,
which should probably be enough in most of users. If someone has got
more than 40 gigabytes of ram and wants to have nicely aligned page
usage prints, I'm happy to implement some sort of dynamic
alignmenting for it..

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
10 years agopf_insert: Return matching node on insert
Timo Kokkonen [Mon, 11 Jun 2012 15:32:10 +0000 (18:32 +0300)]
pf_insert: Return matching node on insert

When a matching entry is found from the rb_tree, the insert function
should return the found entry from the tree to the caller. This is
also explicitly documented in the code. However, the code incorrectly
returned NULL instead.

Fix the code to return the match as it should do. Without this fix
identical pageframe entries are never located.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
10 years agokpageflags: Add transparent huge pages
Timo Kokkonen [Sun, 10 Jun 2012 18:42:08 +0000 (21:42 +0300)]
kpageflags: Add transparent huge pages

This bit has been available in the kernel since 3.4-rc1.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
10 years agopagemap.h: Do not use hardcoded maximum number of kpageflags
Timo Kokkonen [Sun, 10 Jun 2012 18:37:16 +0000 (21:37 +0300)]
pagemap.h: Do not use hardcoded maximum number of kpageflags

The kpageflag definitions are subject to change. It is better to have
a dynamic maximum defined for this.

Furthermore, the previous maximum was actually wrong. The KSM pages
were never shown even if such pages were present on the system.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
10 years agoRevert "Fix bug when showing process shared mappings"
Timo Kokkonen [Mon, 4 Jun 2012 19:40:28 +0000 (22:40 +0300)]
Revert "Fix bug when showing process shared mappings"

This reverts commit 52cf500b2f5cbe16f991990d50ec990ab9540b97.

The previous commit was causing the allocated pages reported by the
'-s' option to be doubled. That is clearly wrong.

As I can not remember anymore what I was thinking when I wrote the
commit and I can only see how wrong it is, I see no reason to not
revert it.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
10 years agoUpdate my email address
Timo Kokkonen [Mon, 4 Jun 2012 18:40:32 +0000 (21:40 +0300)]
Update my email address

This one should last forever.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
10 years agoMakefile: allow usage of cross_compile
Nishanth Menon [Mon, 4 Jun 2012 17:21:32 +0000 (12:21 -0500)]
Makefile: allow usage of cross_compile

Signed-off-by: Nishanth Menon <nm@ti.com>
10 years agoanalyze.c: Use 1000 as a thousand multiplier for PRETTY_TRESH
Timo Kokkonen [Sat, 17 Mar 2012 21:04:01 +0000 (23:04 +0200)]
analyze.c: Use 1000 as a thousand multiplier for PRETTY_TRESH

This makes it easier to adjust the theshold to the value that is
expected to be seen by the end user.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
10 years agoupdate_kpageflags: Ensure file descriptors are closed correctly on error
Timo Kokkonen [Mon, 7 Nov 2011 16:24:50 +0000 (18:24 +0200)]
update_kpageflags: Ensure file descriptors are closed correctly on error

If only opening only other of the files fails, the successfully opened
file was not closed. This scenario is extremely unlikely, but should
be fixed never the less.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoFix bug when showing process shared mappings
Timo Kokkonen [Thu, 3 Nov 2011 12:54:41 +0000 (14:54 +0200)]
Fix bug when showing process shared mappings

The way page table tree is walked through nowadays requires that the
process map data is incremented every time the page table tree is
processed. Otherwise the last time the tree is processed, the counters
are overwritten with the last values, which is most likely zeros.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoMakefile: Do not fail build if stale dependency files are present
Timo Kokkonen [Fri, 21 Oct 2011 18:38:36 +0000 (21:38 +0300)]
Makefile: Do not fail build if stale dependency files are present

If we happen to remove some old header files, the build should not
fail because the header files are still listed in the dependency
files.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoMakefile: Do not force pretty print
Timo Kokkonen [Fri, 21 Oct 2011 18:35:58 +0000 (21:35 +0300)]
Makefile: Do not force pretty print

Verbose build messages can be enabled by setting variable V=1

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoprint_pid_stats: Revert order of pageframe tree and process list are traversed
Timo Kokkonen [Sun, 16 Oct 2011 18:20:20 +0000 (21:20 +0300)]
print_pid_stats: Revert order of pageframe tree and process list are traversed

The pageframe tree is usually quite big, in order of dozens of
megabytes. The process list on the other hand is usually quite small,
usually in the order of tens of kilobytes. The process list thus can
fit entirely in L2 (or even in L1) cache whereas the pageframe tree
most likely does not fit in any cache at all.

Therefore, when calculating the pid statistics, walking through the
page frame tree as many times as there are processes in the process
list will likely cause very big traffic to the memory bus. Changing
the ordering of the loops will significantly increase cache locality
and reduce the memory bus traffic, decreasing the execution times a
lot.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoanalyze.c: Factor out counting stats for a single pageframe
Timo Kokkonen [Sun, 16 Oct 2011 18:19:08 +0000 (21:19 +0300)]
analyze.c: Factor out counting stats for a single pageframe

This makes it possible to re-use the pageframe stats counting in cases
it is not desirable to count the stats for every pages in the tree.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoparse.c: Do not update per process mapping data
Timo Kokkonen [Sun, 16 Oct 2011 15:16:48 +0000 (18:16 +0300)]
parse.c: Do not update per process mapping data

This data is calculated on demand basis in the analyze.c file. No need
to calculate the redundat data here.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years ago.gitignore: Add some more entries
Timo Kokkonen [Sat, 15 Oct 2011 18:20:29 +0000 (21:20 +0300)]
.gitignore: Add some more entries

Hide emacs temporary files, perf data files and patches.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoRemove old unused bintree code.
Timo Kokkonen [Sat, 15 Oct 2011 18:15:31 +0000 (21:15 +0300)]
Remove old unused bintree code.

This has been replaced with rbtree code.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoReplace bintree with rbtree implementation
Timo Kokkonen [Sat, 15 Oct 2011 18:02:26 +0000 (21:02 +0300)]
Replace bintree with rbtree implementation

The biggest flaw with the bintree is that they can easily become
unbalanced. For example, if X server maps the video card memory into
its address space as 1:1 mapping, running scan-pagemap can be really
slow. This is because reading the 1:1 mapping will generate horribly
skewed binary tree that resembles more closely a single direction
linked list. Replacing the simple binary tree implementation with the
red black tree can make full scan over five times faster.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agorbtree: Compile without the kernel
Timo Kokkonen [Sat, 15 Oct 2011 17:52:58 +0000 (20:52 +0300)]
rbtree: Compile without the kernel

Make minimum amoutn of changes in order to make it compile without the
kernel.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoImport rbtree code from Linux kernel
Timo Kokkonen [Sat, 15 Oct 2011 12:28:11 +0000 (15:28 +0300)]
Import rbtree code from Linux kernel

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
10 years agoalloc_map: Remove redundat memset
Timo Kokkonen [Wed, 12 Oct 2011 16:16:05 +0000 (19:16 +0300)]
alloc_map: Remove redundat memset

The struct is already filled with zeroes by calloc, thus the memset
call is not needed.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
11 years agoPrint verbose output during operation
Timo Kokkonen [Sun, 2 Oct 2011 09:10:38 +0000 (12:10 +0300)]
Print verbose output during operation

Sometimes (especially with slower computers with a lot of memory, or
just computers with *a lot* of memory) it can take quite a while until
all the processing is done. Print brief status notes to the user
stating which pid's data we are now processing. This allows the user
to know how far we are going.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
11 years agoMerge branch 'master' of remote
Timo Kokkonen [Thu, 29 Sep 2011 18:09:22 +0000 (21:09 +0300)]
Merge branch 'master' of remote

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
11 years agomain: Set a reasonable default function if no arguments are given
Timo Kokkonen [Thu, 29 Sep 2011 17:58:09 +0000 (20:58 +0300)]
main: Set a reasonable default function if no arguments are given

A very useful way to use scan-pagemap is to simply print out memory
usage of all processes on the system. Let this be the default behavior
of the program if no other options are given.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
11 years agoReplace malloc + memset with calloc
Timo Kokkonen [Tue, 27 Sep 2011 15:30:08 +0000 (18:30 +0300)]
Replace malloc + memset with calloc

The libc has a function for allocating cleared memory, so use that
instead of manually clearing the memory with memset.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
11 years agoMakefile: Reduce wildcard usage
Timo Kokkonen [Mon, 6 Dec 2010 09:31:54 +0000 (11:31 +0200)]
Makefile: Reduce wildcard usage

Having wildcards in the Makefile is error prone in situations where
there are unrelated files in the source tree that are not related to
the actual project. For example, if some source files have been
renamed and there are leftover .*.o.d files that still contain the old
source files. Then make will incorrectly determine that some old files
would still be needed even though they are not part of the project any
more.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAdd README file
Timo Kokkonen [Sun, 19 Sep 2010 15:36:03 +0000 (18:36 +0300)]
Add README file

This file contains some description on how this tool works and how it
can be used.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAdd a copyright notes on each source file
Timo Kokkonen [Sun, 19 Sep 2010 14:10:43 +0000 (17:10 +0300)]
Add a copyright notes on each source file

This is a GPLv2 licensed software.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Avoid parsing pids completely when not necessary
Timo Kokkonen [Wed, 8 Sep 2010 18:35:00 +0000 (21:35 +0300)]
parser: Avoid parsing pids completely when not necessary

If user has decided to scan only given mapping name for the processes,
it doesn't make sense to scan the entire process list too.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: More strict process scanning decision
Timo Kokkonen [Wed, 8 Sep 2010 18:16:59 +0000 (21:16 +0300)]
parser: More strict process scanning decision

If user has given a list of processes and a mapping name, then only
the given processes should be scanned for the mapping names.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAnalyzer: Readjust PRETTY_THRESH value
Timo Kokkonen [Fri, 3 Sep 2010 18:07:53 +0000 (21:07 +0300)]
Analyzer: Readjust PRETTY_THRESH value

100000 / 1024 = 97.65625

Thus, it needs to be 97 instead of 98

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agomain: Remove stupid debug message
Timo Kokkonen [Fri, 3 Sep 2010 18:04:09 +0000 (21:04 +0300)]
main: Remove stupid debug message

This was left here by an accident.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAnalyzer: Print USS
Timo Kokkonen [Fri, 3 Sep 2010 17:37:49 +0000 (20:37 +0300)]
Analyzer: Print USS

Print the Unique Set Size columnt for each process.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAnalyzer: Rename "in ram" column to "RSS"
Timo Kokkonen [Fri, 3 Sep 2010 17:36:40 +0000 (20:36 +0300)]
Analyzer: Rename "in ram" column to "RSS"

This is now more consistent with tools like top.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agomain: Assume non-option arguments to be pids or process names
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>
12 years agopidlib: Implement pidstr_is_ok()
Timo Kokkonen [Thu, 2 Sep 2010 15:28:41 +0000 (18:28 +0300)]
pidlib: Implement pidstr_is_ok()

This can be used to check whether a numerical pid string represents an
actual pid numer on the system.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAnalyzer: Print also the unit for page stats
Timo Kokkonen [Sun, 29 Aug 2010 11:16:26 +0000 (14:16 +0300)]
Analyzer: Print also the unit for page stats

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAnalyzer: Print detailed kpageflag statistics
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>
12 years agopagemap.h: Implement kpageflag handling code
Timo Kokkonen [Sun, 29 Aug 2010 10:29:30 +0000 (13:29 +0300)]
pagemap.h: Implement kpageflag handling code

This code is needed for convenient kpageflag handling.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAnalyzer: Indent page stats nicely
Timo Kokkonen [Sun, 29 Aug 2010 10:27:32 +0000 (13:27 +0300)]
Analyzer: Indent page stats nicely

We will soon have more detailed page stats, so indent the existing
lines to improve readability.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAnalyzer: Use the kpagecount data for determining unique pages
Timo Kokkonen [Sun, 29 Aug 2010 10:23:57 +0000 (13:23 +0300)]
Analyzer: Use the kpagecount data for determining unique pages

Since we now have the kpagecount interface, use that to determine
whether a page is truly referenced only once or not.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoParser: Read kpageflags and kpagecount
Timo Kokkonen [Sun, 29 Aug 2010 10:21:38 +0000 (13:21 +0300)]
Parser: Read kpageflags and kpagecount

Read the /proc/kpageflags and /proc/kpagecount data for every page
frame.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Free pidlist entries after removed from the list
Timo Kokkonen [Fri, 27 Aug 2010 17:40:23 +0000 (20:40 +0300)]
parser: Free pidlist entries after removed from the list

Since there will be no references to the pidlist entries that are
removed from the list, it should be freed as well.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Use substring comparison in map names
Timo Kokkonen [Thu, 26 Aug 2010 20:17:38 +0000 (23:17 +0300)]
parser: Use substring comparison in map names

This allows searching map names with only part of the string. Thanks
to Tapani Pälli for the idea.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Remove unaccessible pids from the pidlist
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>
12 years agopagemap.h: Fix compiler warning
Timo Kokkonen [Thu, 26 Aug 2010 18:42:18 +0000 (21:42 +0300)]
pagemap.h: Fix compiler warning

As there is now call to malloc(), the stdlib.h needs to be included.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Remove unused variable
Timo Kokkonen [Sun, 22 Aug 2010 13:31:21 +0000 (16:31 +0300)]
parser: Remove unused variable

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAdd support for listing mappings that are shared between processes
Timo Kokkonen [Sat, 21 Aug 2010 10:42:54 +0000 (13:42 +0300)]
Add support for listing mappings that are shared between processes

This counts the amoutn of pages that are being shared among the list
of given processes for each mapping the process has.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoParser: Remove support for parsing processes by name
Timo Kokkonen [Sat, 21 Aug 2010 08:57:10 +0000 (11:57 +0300)]
Parser: Remove support for parsing processes by name

This is no longer needed since process names are converted to pids
already in main.c function.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agomain.c: Allow scanning multiple processes by name
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>
12 years agoAnalyzer: Drop PRETTY_THRESH value to 98
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>
12 years agoMakefile: Apply CFLAGS also when linking the final binary
Timo Kokkonen [Sat, 21 Aug 2010 07:13:05 +0000 (10:13 +0300)]
Makefile: Apply CFLAGS also when linking the final binary

The extra optimization and warnings might be useful during linking. It
certainly doesn't hurt to have these enabled.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoFactor out all pid handling functions in a separate pidlib.c
Timo Kokkonen [Sat, 21 Aug 2010 07:09:58 +0000 (10:09 +0300)]
Factor out all pid handling functions in a separate pidlib.c

There will be need to handle pids from other files as well, so
separating them all out into one file is needed.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoanalyzer: Remove unnecessary list_empty() check
Timo Kokkonen [Thu, 19 Aug 2010 20:24:40 +0000 (23:24 +0300)]
analyzer: Remove unnecessary list_empty() check

This is not needed since list_for_each_entry() will handle empty lists
just fine.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoRemove duplicate pageframe initialization code
Timo Kokkonen [Thu, 19 Aug 2010 20:11:43 +0000 (23:11 +0300)]
Remove duplicate pageframe initialization code

Move the initialization code to an inlined function in pagemap.h,
where it can be used also from main.c.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAdd support for parsing multiple pid numbers
Timo Kokkonen [Thu, 19 Aug 2010 19:49:20 +0000 (22:49 +0300)]
Add support for parsing multiple pid numbers

Pids are now stored in a linked list in the parse_opts structure.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoCompact struct pageframe
Timo Kokkonen [Thu, 19 Aug 2010 14:51:20 +0000 (17:51 +0300)]
Compact struct pageframe

It really makes no sense to have map_list structure embedded in the
pageframe list. All we need is a list_head that contains map_list
entries.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoanalyzer: Remove unnecessary list_empty check
Timo Kokkonen [Wed, 18 Aug 2010 19:39:40 +0000 (22:39 +0300)]
analyzer: Remove unnecessary list_empty check

This check really doesn't serve any useful purposes.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoMark initially scanned pids in analyzer printouts
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>
12 years agoAdd macro for testing parse option flags
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>
12 years agoAnalyzer: Show prints in kilobyte resolution
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>
12 years agomain: Use geteuid instead of getuid
Timo Kokkonen [Mon, 16 Aug 2010 20:02:16 +0000 (23:02 +0300)]
main: Use geteuid instead of getuid

The effective used ID is what matters, since if someone uses setuid
bit to run the binary as root, the euid will be 0 but uid might not.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoCompact pageframe structure
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>
12 years agoprint_page_stats: Print unique pages
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>
12 years agoparser: When scannin by name, scan all pids twice
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>
12 years agoparser: Fix scanning by mapping name
Timo Kokkonen [Sun, 15 Aug 2010 19:36:18 +0000 (22:36 +0300)]
parser: Fix scanning by mapping name

If we scan by a mapping name, we must allow all processes to be
scanned.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoCorrect the usage of linked lists
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>
12 years agoMakefile: Disable optimizations for the debug version
Timo Kokkonen [Sun, 15 Aug 2010 17:45:22 +0000 (20:45 +0300)]
Makefile: Disable optimizations for the debug version

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Do not scan processes twice
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>
12 years agoread_pageframe: Do not add empty entries in process list
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>
12 years agoutils.h: Fix coding conventions
Timo Kokkonen [Sun, 15 Aug 2010 16:36:07 +0000 (19:36 +0300)]
utils.h: Fix coding conventions

These were reported by checkpatch.pl

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Fix the order of argumets for list_add()
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>
12 years agomain: Print warning if root priviledges are not available
Timo Kokkonen [Sat, 14 Aug 2010 16:01:55 +0000 (19:01 +0300)]
main: Print warning if root priviledges are not available

Without root priviledges, reading only the user's own processes is
possible. Thus, the results usually don't contain all of the possible
results.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agomain.c: Get rid of unnecessary white space
Timo Kokkonen [Sat, 14 Aug 2010 15:59:47 +0000 (18:59 +0300)]
main.c: Get rid of unnecessary white space

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agomain.c: Print page stats also after dumping process maps
Timo Kokkonen [Fri, 23 Jul 2010 16:58:22 +0000 (19:58 +0300)]
main.c: Print page stats also after dumping process maps

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoDump process page maps when requested
Timo Kokkonen [Fri, 23 Jul 2010 16:40:30 +0000 (19:40 +0300)]
Dump process page maps when requested

If dumping is requested, only the given processes are being scanned,
not all pids in the system.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoanalyzer: Add support for dumping process page maps
Timo Kokkonen [Fri, 23 Jul 2010 16:37:02 +0000 (19:37 +0300)]
analyzer: Add support for dumping process page maps

This code will dump the process page mappings, sorted by the the
actual (ram + swap) size. The size of the mapping address space is
printed as well.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Avoid too long reads from /proc/pid/pageframe
Timo Kokkonen [Fri, 23 Jul 2010 16:35:20 +0000 (19:35 +0300)]
parser: Avoid too long reads from /proc/pid/pageframe

The correct amount is always one 8 byte entry for each 4096 size
pages.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoanalyzer: print_pid_stats: Add column for total mem usage
Timo Kokkonen [Fri, 23 Jul 2010 14:45:51 +0000 (17:45 +0300)]
analyzer: print_pid_stats: Add column for total mem usage

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoprint_help: Add help string for the -P and --process options
Timo Kokkonen [Fri, 23 Jul 2010 14:38:14 +0000 (17:38 +0300)]
print_help: Add help string for the -P and --process options

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAnalyzer: Do not report unused pages
Timo Kokkonen [Fri, 23 Jul 2010 14:34:56 +0000 (17:34 +0300)]
Analyzer: Do not report unused pages

We are ignoring the unused pages anyway, so there is no good in
reporting them.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoread_args: Remove debug print
Timo Kokkonen [Fri, 23 Jul 2010 14:33:46 +0000 (17:33 +0300)]
read_args: Remove debug print

This line got here by accident again, remove it!

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoanalyzer: Avoid ignoring mappings with only one reference
Timo Kokkonen [Fri, 23 Jul 2010 14:13:00 +0000 (17:13 +0300)]
analyzer: Avoid ignoring mappings with only one reference

The list_for_each_entry macro does not work for lists that have only
one item in it. Thus, we need a special case for lists containing only
one entry.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoBreak parsing if no processes are found
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>
12 years agomain.c: read_args: Add missing break to switch clause
Timo Kokkonen [Fri, 23 Jul 2010 12:37:34 +0000 (15:37 +0300)]
main.c: read_args: Add missing break to switch clause

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Coding convention fixes
Timo Kokkonen [Fri, 23 Jul 2010 11:14:03 +0000 (14:14 +0300)]
parser: Coding convention fixes

These were reported by the checkpatch.pl script

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agomain.c: Clear the options structure before using
Timo Kokkonen [Fri, 23 Jul 2010 11:04:21 +0000 (14:04 +0300)]
main.c: Clear the options structure before using

Obviously it is not guaranteed that the contents of the structure are
zeroed if the content is allocated from the stack..

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: opendir_check: Open the correct directory
Timo Kokkonen [Fri, 23 Jul 2010 10:50:40 +0000 (13:50 +0300)]
parser: opendir_check: Open the correct directory

Remove the incorrect hard coded directory since it is wrong.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agomain.c: Add new command line options for parsing by process name
Timo Kokkonen [Fri, 23 Jul 2010 10:41:44 +0000 (13:41 +0300)]
main.c: Add new command line options for parsing by process name

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Add support for parsing processes by name
Timo Kokkonen [Fri, 23 Jul 2010 10:41:22 +0000 (13:41 +0300)]
parser: Add support for parsing processes by name

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Factor out reading cmdline to separate function
Timo Kokkonen [Fri, 23 Jul 2010 10:39:59 +0000 (13:39 +0300)]
parser: Factor out reading cmdline to separate function

This will be needed from different places in future, so factor it out
in a separate function.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparse_opts: Add new parse options
Timo Kokkonen [Fri, 23 Jul 2010 10:36:56 +0000 (13:36 +0300)]
parse_opts: Add new parse options

Prepare for adding support for parsing by process name.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: Factor out duplicate code into a separate function
Timo Kokkonen [Thu, 22 Jul 2010 11:34:05 +0000 (14:34 +0300)]
parser: Factor out duplicate code into a separate function

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoparser: get_next_pid: Do not store state internally
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>
12 years agoAnalyzer: Print thread-ID only when --with-threads is enabled
Timo Kokkonen [Thu, 22 Jul 2010 09:33:51 +0000 (12:33 +0300)]
Analyzer: Print thread-ID only when --with-threads is enabled

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoScan threads only when requested
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>
12 years agomain.c: Add help text
Timo Kokkonen [Thu, 22 Jul 2010 08:19:41 +0000 (11:19 +0300)]
main.c: Add help text

Print usage when insufficient parameters are given or when user
requests the help text.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAdd support for parsing all threads, not just thead parents
Timo Kokkonen [Mon, 19 Jul 2010 11:51:39 +0000 (14:51 +0300)]
Add support for parsing all threads, not just thead parents

Some threads may have different memory address space than their
parents. Therefore it makes sense to allow scanning all threads
separately.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>