summaryrefslogtreecommitdiffstats
path: root/tapset/proc_mem.stp
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2010-02-15 11:28:38 +0100
committerMark Wielaard <mjw@redhat.com>2010-03-03 12:22:37 +0100
commitb36411e750e154eede9019e97844731927141a9e (patch)
tree03cc970de1a9cd93745628f870efbe7eba1c868f /tapset/proc_mem.stp
parent7020ae0062b9f5dc60da698f896bb91c6d8a6b09 (diff)
downloadsystemtap-steved-b36411e750e154eede9019e97844731927141a9e.tar.gz
systemtap-steved-b36411e750e154eede9019e97844731927141a9e.tar.xz
systemtap-steved-b36411e750e154eede9019e97844731927141a9e.zip
Add proc_mem_*_pid tapset function variants.
* tapset/proc_mem.stp: Add proc_mem_size_pid, proc_mem_rss_pid, proc_mem_shr_pid, proc_mem_txt_pid, proc_mem_data_pid and proc_mem_string_pid functions to tapset.
Diffstat (limited to 'tapset/proc_mem.stp')
-rw-r--r--tapset/proc_mem.stp107
1 files changed, 106 insertions, 1 deletions
diff --git a/tapset/proc_mem.stp b/tapset/proc_mem.stp
index 7641ffe2..3de8cc00 100644
--- a/tapset/proc_mem.stp
+++ b/tapset/proc_mem.stp
@@ -1,5 +1,5 @@
// Process memory query and utility functions.
-// Copyright (C) 2009 Red Hat Inc.
+// Copyright (C) 2009, 2010 Red Hat Inc.
//
// This file is part of systemtap, and is free software. You can
// redistribute it and/or modify it under the terms of the GNU General
@@ -32,6 +32,24 @@
}
%}
+function _stp_get_mm_counter_file_rss:long(mm:long)
+{
+%( CONFIG_NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS %?
+ return @cast(mm, "mm_struct", "kernel<linux/mm_types.h>")->_file_rss->counter;
+%:
+ return @cast(mm, "mm_struct", "kernel<linux/mm_types.h>")->_file_rss;
+%)
+}
+
+function _stp_get_mm_counter_anon_rss(mm:long)
+{
+%( CONFIG_NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS %?
+ return @cast(mm, "mm_struct", "kernel<linux/mm_types.h>")->_anon_rss->counter;
+%:
+ return @cast(mm, "mm_struct", "kernel<linux/mm_types.h>")->_anon_rss;
+%)
+}
+
/**
* sfunction proc_mem_size - Total program virtual memory size in pages.
*
@@ -48,6 +66,18 @@ function proc_mem_size:long ()
THIS->__retvalue = 0;
%}
+function proc_mem_size_pid:long (pid:long)
+{
+ task = pid2task(pid);
+ if (task != 0)
+ {
+ mm = @cast(task, "task_struct", "kernel<linux/sched.h>")->mm;
+ if (mm != 0)
+ return @cast(mm, "mm_struct", "kernel<linux/mm_types.h>")->total_vm;
+ }
+ return 0;
+}
+
/**
* sfunction proc_mem_rss - Program resident set size in pages.
*
@@ -65,6 +95,19 @@ function proc_mem_rss:long ()
THIS->__retvalue = 0;
%}
+function proc_mem_rss_pid:long (pid:long)
+{
+ task = pid2task(pid);
+ if (task)
+ {
+ mm = @cast(task, "task_struct", "kernel<linux/sched.h>")->mm;
+ if (mm != 0)
+ return (_stp_get_mm_counter_file_rss (mm)
+ + _stp_get_mm_counter_anon_rss (mm));
+ }
+ return 0;
+}
+
/**
* sfunction proc_mem_shr - Program shared pages (from shared mappings).
*
@@ -81,6 +124,18 @@ function proc_mem_shr:long ()
THIS->__retvalue = 0;
%}
+function proc_mem_shr_pid:long (pid:long)
+{
+ task = pid2task(pid);
+ if (task)
+ {
+ mm = @cast(task, "task_struct", "kernel<linux/sched.h>")->mm;
+ if (mm != 0)
+ return _stp_get_mm_counter_file_rss (mm);
+ }
+ return 0;
+}
+
/**
* sfunction proc_mem_txt - Program text (code) size in pages.
*
@@ -98,6 +153,30 @@ function proc_mem_txt:long ()
THIS->__retvalue = 0;
%}
+function _stp_mem_txt_adjust:long (start_code:long, end_code:long)
+%{ /* pure */
+ unsigned long start_code = (unsigned long) THIS->start_code;
+ unsigned long end_code = (unsigned long) THIS->end_code;
+ THIS->__retvalue = (PAGE_ALIGN(end_code)
+ - (start_code & PAGE_MASK)) >> PAGE_SHIFT;
+%}
+
+function proc_mem_txt_pid:long (pid:long)
+{
+ task = pid2task(pid);
+ if (task != 0)
+ {
+ mm = @cast(task, "task_struct", "kernel<linux/sched.h>")->mm;
+ if (mm != 0)
+ {
+ s = @cast(mm, "mm_struct", "kernel<linux/mm_types.h>")->start_code;
+ e = @cast(mm, "mm_struct", "kernel<linux/mm_types.h>")->end_code;
+ return _stp_mem_txt_adjust (s, e);
+ }
+ }
+ return 0;
+}
+
/**
* sfunction proc_mem_data - Program data size (data + stack) in pages.
*
@@ -114,6 +193,22 @@ function proc_mem_data:long ()
THIS->__retvalue = 0;
%}
+function proc_mem_data_pid:long (pid:long)
+{
+ task = pid2task(pid);
+ if (task != 0)
+ {
+ mm = @cast(task, "task_struct", "kernel<linux/sched.h>")->mm;
+ if (mm != 0)
+ {
+ t = @cast(mm, "mm_struct", "kernel<linux/mm_types.h>")->total_vm;
+ s = @cast(mm, "mm_struct", "kernel<linux/mm_types.h>")->shared_vm;
+ return t - s;
+ }
+ }
+ return 0;
+}
+
/**
* sfunction mem_page_size - Number of bytes in a page for this architecture.
*/
@@ -194,3 +289,13 @@ function proc_mem_string:string ()
pages_to_string(proc_mem_txt()),
pages_to_string(proc_mem_data()));
}
+
+function proc_mem_string_pid:string (pid:long)
+{
+ return sprintf ("size: %s, rss: %s, shr: %s, txt: %s, data: %s",
+ pages_to_string(proc_mem_size_pid(pid)),
+ pages_to_string(proc_mem_rss_pid(pid)),
+ pages_to_string(proc_mem_shr_pid(pid)),
+ pages_to_string(proc_mem_txt_pid(pid)),
+ pages_to_string(proc_mem_data_pid(pid)));
+} \ No newline at end of file