public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [announce/OT] kerneltop ver. 0.7
@ 2004-05-24  4:50 Randy.Dunlap
  2004-05-24  5:31 ` William Lee Irwin III
  2004-05-24  5:53 ` Cef (LKML)
  0 siblings, 2 replies; 10+ messages in thread
From: Randy.Dunlap @ 2004-05-24  4:50 UTC (permalink / raw)
  To: lkml


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);


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [announce/OT] kerneltop ver. 0.7
  2004-05-24  4:50 Randy.Dunlap
@ 2004-05-24  5:31 ` William Lee Irwin III
  2004-05-24  9:55   ` Cef (LKML)
  2004-05-24 21:47   ` Randy.Dunlap
  2004-05-24  5:53 ` Cef (LKML)
  1 sibling, 2 replies; 10+ messages in thread
From: William Lee Irwin III @ 2004-05-24  5:31 UTC (permalink / raw)
  To: Randy.Dunlap; +Cc: lkml

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.


--- kerneltop.c.orig	2004-05-23 22:11:29.000000000 -0700
+++ kerneltop.c	2004-05-23 22:22:08.000000000 -0700
@@ -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");

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [announce/OT] kerneltop ver. 0.7
  2004-05-24  4:50 Randy.Dunlap
  2004-05-24  5:31 ` William Lee Irwin III
@ 2004-05-24  5:53 ` Cef (LKML)
  2004-05-24  6:00   ` William Lee Irwin III
  1 sibling, 1 reply; 10+ messages in thread
From: Cef (LKML) @ 2004-05-24  5:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: Randy.Dunlap

On Mon, 24 May 2004 14:50, Randy.Dunlap wrote:
> 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.

-- 
 Stuart Young (aka Cef)
 cef-lkml@optusnet.com.au is for LKML and related email only

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [announce/OT] kerneltop ver. 0.7
  2004-05-24  5:53 ` Cef (LKML)
@ 2004-05-24  6:00   ` William Lee Irwin III
  2004-05-24  7:18     ` Cef (LKML)
  2004-05-25 19:12     ` Pavel Machek
  0 siblings, 2 replies; 10+ messages in thread
From: William Lee Irwin III @ 2004-05-24  6:00 UTC (permalink / raw)
  To: Cef (LKML); +Cc: linux-kernel, Randy.Dunlap

On Mon, May 24, 2004 at 03:53:42PM +1000, Cef (LKML) wrote:
> 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.

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


-- wli

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [announce/OT] kerneltop ver. 0.7
  2004-05-24  6:00   ` William Lee Irwin III
@ 2004-05-24  7:18     ` Cef (LKML)
  2004-05-25 19:12     ` Pavel Machek
  1 sibling, 0 replies; 10+ messages in thread
From: Cef (LKML) @ 2004-05-24  7:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: William Lee Irwin III, Randy.Dunlap

On Mon, 24 May 2004 16:00, William Lee Irwin III wrote:
> On Mon, May 24, 2004 at 03:53:42PM +1000, Cef (LKML) wrote:
> > 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.
>
> 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.

-- 
 Stuart Young (aka Cef)
 cef-lkml@optusnet.com.au is for LKML and related email only

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [announce/OT] kerneltop ver. 0.7
  2004-05-24  5:31 ` William Lee Irwin III
@ 2004-05-24  9:55   ` Cef (LKML)
  2004-05-24 21:49     ` Randy.Dunlap
  2004-05-24 21:47   ` Randy.Dunlap
  1 sibling, 1 reply; 10+ messages in thread
From: Cef (LKML) @ 2004-05-24  9:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: William Lee Irwin III, Randy.Dunlap

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.

--- kerneltop.c-old	2004-05-24 19:44:35.000000000 +1000
+++ kerneltop.c	2004-05-24 19:48:40.000000000 +1000
@@ -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));

-- 
 Stuart Young (aka Cef)
 cef-lkml@optusnet.com.au is for LKML and related email only

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [announce/OT] kerneltop ver. 0.7
  2004-05-24  5:31 ` William Lee Irwin III
  2004-05-24  9:55   ` Cef (LKML)
@ 2004-05-24 21:47   ` Randy.Dunlap
  1 sibling, 0 replies; 10+ messages in thread
From: Randy.Dunlap @ 2004-05-24 21:47 UTC (permalink / raw)
  To: William Lee Irwin III; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [announce/OT] kerneltop ver. 0.7
  2004-05-24  9:55   ` Cef (LKML)
@ 2004-05-24 21:49     ` Randy.Dunlap
  0 siblings, 0 replies; 10+ messages in thread
From: Randy.Dunlap @ 2004-05-24 21:49 UTC (permalink / raw)
  To: Cef (LKML); +Cc: linux-kernel, wli

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [announce/OT] kerneltop ver. 0.7
@ 2004-05-24 23:20 Albert Cahalan
  0 siblings, 0 replies; 10+ messages in thread
From: Albert Cahalan @ 2004-05-24 23:20 UTC (permalink / raw)
  To: linux-kernel mailing list; +Cc: cef-lkml, rddunlap, wli

Cef writes:

> 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.

Please search for this data in a procps-like order:

$PS_SYSMAP
$PS_SYSTEM_MAP
** see note **
/boot/System.map-`uname -r`
/boot/System.map
/lib/modules/`uname -r`/System.map
/usr/src/linux/System.map
/System.map

Where I mark "see note" would be a good place to
try /proc/kallsyms or similar. Also, you should
give up if the user gave a bad environment variable
rather than using some undesired data source.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [announce/OT] kerneltop ver. 0.7
  2004-05-24  6:00   ` William Lee Irwin III
  2004-05-24  7:18     ` Cef (LKML)
@ 2004-05-25 19:12     ` Pavel Machek
  1 sibling, 0 replies; 10+ messages in thread
From: Pavel Machek @ 2004-05-25 19:12 UTC (permalink / raw)
  To: William Lee Irwin III, Cef (LKML), linux-kernel, Randy.Dunlap

Hi!

> 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
-- 
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-05-27 19:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-24 23:20 [announce/OT] kerneltop ver. 0.7 Albert Cahalan
  -- strict thread matches above, loose matches on Subject: below --
2004-05-24  4:50 Randy.Dunlap
2004-05-24  5:31 ` William Lee Irwin III
2004-05-24  9:55   ` Cef (LKML)
2004-05-24 21:49     ` Randy.Dunlap
2004-05-24 21:47   ` Randy.Dunlap
2004-05-24  5:53 ` Cef (LKML)
2004-05-24  6:00   ` William Lee Irwin III
2004-05-24  7:18     ` Cef (LKML)
2004-05-25 19:12     ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox