From jbeich@tormail.net  Sun Dec 25 01:41:09 2011
Return-Path: <jbeich@tormail.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 73B88106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 25 Dec 2011 01:41:09 +0000 (UTC)
	(envelope-from jbeich@tormail.net)
Received: from server2.hudsonvalleyhost.com (server2.hudsonvalleyhost.com [66.7.195.77])
	by mx1.freebsd.org (Postfix) with ESMTP id 0918D8FC08
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 25 Dec 2011 01:41:08 +0000 (UTC)
Received: from rainbowwarrior.torservers.net ([77.247.181.164]:24618 helo=internal.tormail.net)
	by server2.hudsonvalleyhost.com with esmtpsa (TLSv1:RC4-SHA:128)
	(Exim 4.69)
	(envelope-from <jbeich@tormail.net>)
	id 1Red5H-00028G-R0
	for FreeBSD-gnats-submit@freebsd.org; Sat, 24 Dec 2011 20:41:08 -0500
Received: from jbeich by internal.tormail.net with local (Exim 4.63)
	(envelope-from <jbeich@tormail.net>)
	id 1Red4a-0004CK-Ue
	for FreeBSD-gnats-submit@freebsd.org; Sun, 25 Dec 2011 01:40:27 +0000
Message-Id: <1Red4a-0004CK-Ue@internal.tormail.net>
Date: Sat, 24 Dec 2011 15:40:09 -1000
From: Jan Beich <jbeich@tormail.net>
To: FreeBSD-gnats-submit@freebsd.org
Subject: pmcstat(8) doesn't search symbols under /boot/modules

>Number:         163602
>Category:       bin
>Synopsis:       pmcstat(8) doesn't search symbols under /boot/modules
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 25 01:50:10 UTC 2011
>Closed-Date:    
>Last-Modified:  Tue Jan 14 19:50:00 UTC 2014
>Originator:     Jan Beich
>Release:        FreeBSD 10.0-CURRENT amd64
>Organization:
>Environment:
>Description:
pmcstat(8) should search under /boot/modules by default as that is the
place kernel modules are installed by ports/ framework. It could be
implemented similar to kldload(8) as a semicolon-separated list of paths
to search with default being kern.module_path sysctl.
>How-To-Repeat:
$ sudo pmcstat -S instructions -O /tmp/all.pmc
^C

$ pmcstat -R /tmp/all.pmc -G all.graph
pmcstat: WARNING: Cannot determine the type of "/boot/kernel/nvidia.ko".
pmcstat: WARNING: Cannot determine the type of "/boot/kernel/uvhid.ko".
pmcstat: WARNING: Cannot determine the type of "unknown".
pmcstat: WARNING: Cannot determine the type of "/usr/local/bin/sudo".
[...]
CONVERSION STATISTICS:
 #exec/elf                                9
 #samples/total                           10915
 #samples/unknown-function                566
 #callchain/dubious-frames                62

$ grep '_nv.*rm' all.graph | sort -rk1 | head
Exit 1
>Fix:
A known workaround:

  $ cd /boot/kernel
  $ ln -s ../modules/*.ko* .
>Release-Note:
>Audit-Trail:

From: Ulf Lilleengen <lulf@FreeBSD.org>
To: bug-followup@FreeBSD.org, jbeich@tormail.net
Cc:  
Subject: Re: bin/163602: pmcstat(8) doesn&#39;t search symbols under /boot/modules
Date: Tue, 14 Jan 2014 20:44:15 +0100

 This is a multi-part message in MIME format.
 --------------030308020102060505000202
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 I'm not able to reproduce this at the moment. Any tips on how? Or maybe 
 you could test out this patch:
 
 http://people.freebsd.org/~lulf/patches/pmcstat_modules.diff
 
 
 --------------030308020102060505000202
 Content-Type: text/x-patch;
  name="pmcstat_modules.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="pmcstat_modules.diff"
 
 diff --git a/usr.sbin/pmcstat/pmcstat.c b/usr.sbin/pmcstat/pmcstat.c
 index cc43b82..d0db9c5 100644
 --- a/usr.sbin/pmcstat/pmcstat.c
 +++ b/usr.sbin/pmcstat/pmcstat.c
 @@ -583,7 +583,7 @@ main(int argc, char **argv)
  	args.pa_verbosity	= 1;
  	args.pa_logfd		= -1;
  	args.pa_fsroot		= "";
 -	args.pa_kernel		= strdup("/boot/kernel");
 +	args.pa_kernel		= strdup("/boot/kernel;/boot/modules");
  	args.pa_samplesdir	= ".";
  	args.pa_printfile	= stderr;
  	args.pa_graphdepth	= DEFAULT_CALLGRAPH_DEPTH;
 diff --git a/usr.sbin/pmcstat/pmcstat_log.c b/usr.sbin/pmcstat/pmcstat_log.c
 index fdcf9c4..6606fa5 100644
 --- a/usr.sbin/pmcstat/pmcstat_log.c
 +++ b/usr.sbin/pmcstat/pmcstat_log.c
 @@ -230,6 +230,8 @@ float pmcstat_threshold = 0.5; /* Cost filter for top mode. */
  static struct pmcstat_image *pmcstat_image_from_path(pmcstat_interned_string
      _path, int _iskernelmodule);
  static void pmcstat_image_get_aout_params(struct pmcstat_image *_image);
 +static void pmcstat_locate_kernelmodule(char *_buffer, size_t _buffer_length,
 +	const char *_path);
  static void pmcstat_image_get_elf_params(struct pmcstat_image *_image);
  static void	pmcstat_image_link(struct pmcstat_process *_pp,
      struct pmcstat_image *_i, uintfptr_t _lpc);
 @@ -602,6 +604,22 @@ pmcstat_image_add_symbols(struct pmcstat_image *image, Elf *e,
  			symptr->ps_end = (symptr+1)->ps_start;
  }
  
 +static void
 +pmcstat_locate_kernelmodule(char *buffer, size_t buffer_length,
 +    const char *path)
 +{
 +	char * module_paths = strdup(args.pa_kernel);
 +	char * module_path = NULL;
 +	while ((module_path = strsep(&module_paths, ";")) != NULL) {
 +		(void) snprintf(buffer, buffer_length, "%s%s/%s", args.pa_fsroot,
 +	        module_path, path);
 +		if (access(buffer, R_OK) == 0) {
 +			break;
 +		}
 +	}
 +	free(module_paths);
 +}
 +
  /*
   * Examine an ELF file to determine the size of its text segment.
   * Sets image->pi_type if anything conclusive can be determined about
 @@ -641,8 +659,7 @@ pmcstat_image_get_elf_params(struct pmcstat_image *image)
  	 * and user mode executable objects under FSROOT/PATHNAME.
  	 */
  	if (image->pi_iskernelmodule)
 -		(void) snprintf(buffer, sizeof(buffer), "%s%s/%s",
 -		    args.pa_fsroot, args.pa_kernel, path);
 +		(void) pmcstat_locate_kernelmodule(buffer, sizeof(buffer), path);
  	else
  		(void) snprintf(buffer, sizeof(buffer), "%s%s",
  		    args.pa_fsroot, path);
 
 --------------030308020102060505000202--
>Unformatted:
