Skip to contentSkip to conversation

kerneltop ver. 0.7

announce/OT Randy.Dunlap 4 participants 9 messages May 24, 2004 – May 27, 2004

lore
Share & tools
lore
#0 lore raw

just a little note about kerneltop...

'kerneltop' is similar to 'top', but shows only kernel function usage (modules not included).

I have updated it a bit (now version 0.7) and made sure that it works OK on Linux 2.6.x.

It's available here:
http://www.xenotime.net/linux/kerneltop/

--
~Randy

changelog:
version 0.6 (never released/announced):
* . add interactive keyboard inputs for l(ines), s(econds), t(icks),
* u(nsort), h(elp) or ?(help), q(uit)

version 0.7:
* . make a difference in profile_lines and console_lines; they were
* the same, which caused some heading lines to scroll off the
* top of the console and make general garbage of the headings;
* . reduce the fixed heading info by 2 lines (no version, no dash line);

#1 lore raw
Quoted 7 lines · Randy.Dunlap

just a little note about kerneltop...
'kerneltop' is similar to 'top', but shows only kernel function usage (modules not included).
I have updated it a bit (now version 0.7) and made sure that it works OK on Linux 2.6.x.
It's available here:
http://www.xenotime.net/linux/kerneltop/

GRRR.. this tries to reset /proc/profile. Multiple megabytes of in- kernel memset() at a frequency of 1Hz are extremely unfriendly.

kerneltop.c renamed from kerneltop.c.orig +5 -32
@@ -491,32 +491,6 @@ int do_key(char c)
 } // end do_key
 
 
-/* reset the profile buffer after each read of it */
-static void profile_reset (void)
-{
-	int multiplier, fd, to_write;
-
-	/*
-	 * When writing the multiplier, if the length of the write is
-	 * not sizeof(int), the multiplier is not changed.
-	 */
-	multiplier = 0;
-	to_write = 1;	/* smth different from sizeof(int) */
-	/* try to become root, just in case */
-	setuid (0);
-	fd = open (defaultpro, O_WRONLY);
-	if (fd < 0) {
-		perror (defaultpro);
-		exit (1);
-	}
-	if (write (fd, &multiplier, to_write) != to_write) {
-		fprintf (stderr, "kerneltop: error writing %s: %s\n",
-			defaultpro, strerror (errno));
-		exit (1);
-	}
-	close (fd);
-} // end profile_reset
-
 /*
  * allocates <buf> for the profile data;
  * returns buffer length;
@@ -753,7 +727,7 @@ main (int argc, char **argv) {
 	char *mapFile, *proFile;
 	unsigned long len = 0;
 	unsigned int step;
-	unsigned int *buf;
+	unsigned int *lastbuf, *buf = NULL;
 	int opt;
 	int optReverse = 0, optProfile = 0;
 	time_t timer;
@@ -824,10 +798,8 @@ main (int argc, char **argv) {
 	heading ();
 
     while (1) {		// get profile data, put it into symbol buckets, print
-
+	lastbuf = buf;
 	len = profile_read (proFile, &buf); // allocates buf & returns its len
-	if (!optProfile)		// don't reset if using non-default file
-		profile_reset ();
 	step = buf[0];
 	vid_curpos (ROW_SAMPLING_RANGE, 1);
 	printf (_("Sampling_step: %i | Address range: 0x%lx - 0x%lx\n"),
@@ -863,7 +835,7 @@ main (int argc, char **argv) {
 	// collect frequency histogram of profile buf.
 	for (ix = 0, lookup_last = 0; ix < mx; ix++) {
 		adr = adr0 + step * ix;
-		ticks = buf [ix + 1];
+		ticks = buf [ix + 1] - (lastbuf ? lastbuf [ix + 1] : 0);
 		total_ticks += ticks;
 		fnx = lookup (adr);
 		if (fnx >= 0)
@@ -897,7 +869,7 @@ main (int argc, char **argv) {
 	total_ticks = 0;
 	// clear freqs for next pass
 	memset (freqs, 0, sizeof(int) * (text_lines + 1));
-	free (buf);	// before next profile_read call
+	free (lastbuf);	// before next profile_read call
 
 	// check for stdin (keyboard) input 1x per second
 	// while sleeping for <sleep_seconds>
@@ -910,6 +882,7 @@ main (int argc, char **argv) {
 	}
 
     } // end while 1
+    free (buf);
 
 fini:
 	printf("\n");
#2 lore raw
Quoted 11 lines · William Lee Irwin III
Quoted 7 lines · Randy.Dunlap

just a little note about kerneltop...
'kerneltop' is similar to 'top', but shows only kernel function usage (modules not included).
I have updated it a bit (now version 0.7) and made sure that it works OK on Linux 2.6.x.
It's available here:
http://www.xenotime.net/linux/kerneltop/

GRRR.. this tries to reset /proc/profile. Multiple megabytes of in- kernel memset() at a frequency of 1Hz are extremely unfriendly.

Following patch primes the buffer first time round (avoids huge total_ticks on first pass) and moves total_ticks to the end of the field header bar, saving an output line for useful data.

PS: If this keeps going, we should probably take this off-list or move to somewhere appropriate.

kerneltop.c renamed from kerneltop.c-old +6 -2
@@ -266,7 +266,7 @@
  * heading looks like (3 lines):
 <uname -a>
 Sampling step: n | Address range: s_text_addr - e_text_addr
-address  function ..... date/time ...... ticks
+address  function ..... date/time ...... ticks (total_ticks)
  */
 static void heading (void)
 {
@@ -797,6 +797,11 @@
 
 	heading ();
 
+	printf ("... profiling ...\n"); // keep the user in suspense
+	len = profile_read (proFile, &buf); // allocates buf & returns its len
+	memset (freqs, 0, sizeof(int) * (text_lines + 1));
+	sleep (1);
+
     while (1) {		// get profile data, put it into symbol buckets, print
 	lastbuf = buf;
 	len = profile_read (proFile, &buf); // allocates buf & returns its len
@@ -809,7 +814,7 @@
 	time (&timer);
 	dttm = localtime (&timer);
 	vid_curpos (ROW_HEADINGS, 1);
-	printf (_("address  function ..... %d-%02d-%02d/%02d:%02d:%02d ...... 

ticks\n"),
+ printf (_("address function ..... %d-%02d-%02d/%02d:%02d:%02d ......
ticks"),
dttm->tm_year + 1900, dttm->tm_mon + 1, dttm->tm_mday, dttm->tm_hour, dttm->tm_min, dttm->tm_sec);

@@ -841,6 +846,9 @@
if (fnx >= 0)
freqs [fnx] += ticks;
}
+ // Print total on end of previous string
+ printf (" (%6i)\n", total_ticks);
+
/*
* Optionally sort the top <prof_lines> entries.
* Print the top entries.
@@ -863,9 +871,6 @@
textsym->textadr, textsym->textname, ticks);
}

- /* trailer */
- printf ("%08x %-40s %6i\n", 0, "total", total_ticks);
-
total_ticks = 0;
// clear freqs for next pass
memset (freqs, 0, sizeof(int) * (text_lines + 1));

Signature · 2 lines
 Stuart Young (aka Cef)
 [email protected] is for LKML and related email only
#3 lore raw

On Mon, 24 May 2004 19:55:42 +1000 Cef (LKML) wrote:

| On Mon, 24 May 2004 15:31, William Lee Irwin III wrote:
| > On Sun, May 23, 2004 at 09:50:27PM -0700, Randy.Dunlap wrote:
| > > just a little note about kerneltop...
| > > 'kerneltop' is similar to 'top', but shows only kernel function usage
| > > (modules not included).
| > > I have updated it a bit (now version 0.7) and made sure that it
| > > works OK on Linux 2.6.x.
| > > It's available here:
| > > 	http://www.xenotime.net/linux/kerneltop/
| >
| > GRRR.. this tries to reset /proc/profile. Multiple megabytes of in-
| > kernel memset() at a frequency of 1Hz are extremely unfriendly.
| 
| Following patch primes the buffer first time round (avoids huge total_ticks on 
| first pass) and moves total_ticks to the end of the field header bar, saving 
| an output line for useful data.
| 
| PS: If this keeps going, we should probably take this off-list or move to 
| somewhere appropriate.

I applied the total_ticks heading change. Still thinking about the first-pass-priming-the-pump change. It's not a big deal either way IMO.

| For clarity, you might want to invert the "address function ....." line to | separate the header from the actual displayed data (like top does).

Done.

Still considering your other suggestions. Thanks.

--
~Randy

#4 lore raw
In reply to William Lee Irwin III

On Sun, 23 May 2004 22:31:53 -0700 William Lee Irwin III wrote:

| On Sun, May 23, 2004 at 09:50:27PM -0700, Randy.Dunlap wrote:
| > just a little note about kerneltop...
| > 'kerneltop' is similar to 'top', but shows only kernel function usage
| > (modules not included).
| > I have updated it a bit (now version 0.7) and made sure that it
| > works OK on Linux 2.6.x.
| > It's available here:
| > 	http://www.xenotime.net/linux/kerneltop/
| 
| GRRR.. this tries to reset /proc/profile. Multiple megabytes of in-
| kernel memset() at a frequency of 1Hz are extremely unfriendly.

Looks nice. Applied.

--
~Randy

#5 lore raw
In reply to Randy.Dunlap
Quoted 4 lines · Randy.Dunlap

just a little note about kerneltop...

'kerneltop' is similar to 'top', but shows only kernel function usage (modules not included).

Looks good! A few suggestions....

Might want to add support for /boot/System.map containing the version number (eg: /boot/System.map-uname -r ), if /boot/System.map doesn't exist, before just dropping out with an error.

For clarity, you might want to invert the "address function ....." line to separate the header from the actual displayed data (like top does).

Having the total up in the header instead of at the end of the data might also be useful (eg: next to ticks perhaps?) as it's really a waste of a display line for 1 number.

Also a little more verbosity in the error messages would be good.

eg:
/proc/profile not found:
You need to enable profiling support in your kernel to use kerneltop /proc/profile Permission Denied:
You need to be root to run kerneltop

Hope these comments are useful.

Signature · 2 lines
 Stuart Young (aka Cef)
 [email protected] is for LKML and related email only
#6 lore raw
Quoted 8 lines · Cef (LKML)

Looks good! A few suggestions....
Might want to add support for /boot/System.map containing the version number (eg: /boot/System.map-uname -r ), if /boot/System.map doesn't exist, before just dropping out with an error.
For clarity, you might want to invert the "address function ....." line to separate the header from the actual displayed data (like top does). Having the total up in the header instead of at the end of the data might also be useful (eg: next to ticks perhaps?) as it's really a waste of a display

Quoted 8 lines

line for 1 number.
Also a little more verbosity in the error messages would be good. eg:
/proc/profile not found:
You need to enable profiling support in your kernel to use kerneltop /proc/profile Permission Denied:
You need to be root to run kerneltop
Hope these comments are useful.

Please try the patch I just posted which eliminates the need to be root.

-- wli

#7 lore raw
Quoted 18 lines · William Lee Irwin III
Quoted 8 lines · Cef (LKML)

Looks good! A few suggestions....
Might want to add support for /boot/System.map containing the version number (eg: /boot/System.map-uname -r ), if /boot/System.map doesn't exist, before just dropping out with an error.
For clarity, you might want to invert the "address function ....." line to separate the header from the actual displayed data (like top does). Having the total up in the header instead of at the end of the data might also be useful (eg: next to ticks perhaps?) as it's really a waste of a

Quoted 8 lines

display line for 1 number.
Also a little more verbosity in the error messages would be good. eg:
/proc/profile not found:
You need to enable profiling support in your kernel to use kerneltop /proc/profile Permission Denied:
You need to be root to run kerneltop
Hope these comments are useful.

Quoted 1 line

Please try the patch I just posted which eliminates the need to be root.

Works well, but there is one notable side effect.

First time you read /proc/profile, you get everything instead of the last difference, so the first display is huge (and total_ticks is just right off the scale). Probably a good idea to read the values once first, just throw them away, and use that as the starting point.

Signature · 2 lines
 Stuart Young (aka Cef)
 [email protected] is for LKML and related email only
#8 lore raw
In reply to William Lee Irwin III

Hi!

Quoted 2 lines

Please try the patch I just posted which eliminates the need to be root.

Non-root is allowed to profile kernel?

That allows it to get some knowledge what other processes are doing. Potential security hole?

Okay, when wchan is publicly visible in /proc this is probably not too big deal.
Pavel

Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms