head	1.2;
access;
symbols
	netbsd-11-0-RC4:1.2
	netbsd-11-0-RC3:1.2
	netbsd-11-0-RC2:1.2
	netbsd-11-0-RC1:1.2
	perseant-exfatfs-base-20250801:1.2
	netbsd-11:1.2.0.28
	netbsd-11-base:1.2
	netbsd-10-1-RELEASE:1.2
	perseant-exfatfs-base-20240630:1.2
	perseant-exfatfs:1.2.0.26
	perseant-exfatfs-base:1.2
	netbsd-8-3-RELEASE:1.2
	netbsd-9-4-RELEASE:1.2
	netbsd-10-0-RELEASE:1.2
	netbsd-10-0-RC6:1.2
	netbsd-10-0-RC5:1.2
	netbsd-10-0-RC4:1.2
	netbsd-10-0-RC3:1.2
	netbsd-10-0-RC2:1.2
	netbsd-10-0-RC1:1.2
	netbsd-10:1.2.0.24
	netbsd-10-base:1.2
	netbsd-9-3-RELEASE:1.2
	cjep_sun2x-base1:1.2
	cjep_sun2x:1.2.0.22
	cjep_sun2x-base:1.2
	cjep_staticlib_x-base1:1.2
	netbsd-9-2-RELEASE:1.2
	cjep_staticlib_x:1.2.0.20
	cjep_staticlib_x-base:1.2
	netbsd-9-1-RELEASE:1.2
	phil-wifi-20200421:1.2
	phil-wifi-20200411:1.2
	is-mlppp:1.2.0.18
	is-mlppp-base:1.2
	phil-wifi-20200406:1.2
	netbsd-8-2-RELEASE:1.2
	netbsd-9-0-RELEASE:1.2
	netbsd-9-0-RC2:1.2
	netbsd-9-0-RC1:1.2
	phil-wifi-20191119:1.2
	netbsd-9:1.2.0.16
	netbsd-9-base:1.2
	phil-wifi-20190609:1.2
	netbsd-8-1-RELEASE:1.2
	netbsd-8-1-RC1:1.2
	pgoyette-compat-merge-20190127:1.2
	pgoyette-compat-20190127:1.2
	pgoyette-compat-20190118:1.2
	pgoyette-compat-1226:1.2
	pgoyette-compat-1126:1.2
	pgoyette-compat-1020:1.2
	pgoyette-compat-0930:1.2
	pgoyette-compat-0906:1.2
	pgoyette-compat-0728:1.2
	netbsd-8-0-RELEASE:1.2
	phil-wifi:1.2.0.14
	phil-wifi-base:1.2
	pgoyette-compat-0625:1.2
	netbsd-8-0-RC2:1.2
	pgoyette-compat-0521:1.2
	pgoyette-compat-0502:1.2
	pgoyette-compat-0422:1.2
	netbsd-8-0-RC1:1.2
	pgoyette-compat-0415:1.2
	pgoyette-compat-0407:1.2
	pgoyette-compat-0330:1.2
	pgoyette-compat-0322:1.2
	pgoyette-compat-0315:1.2
	pgoyette-compat:1.2.0.12
	pgoyette-compat-base:1.2
	matt-nb8-mediatek:1.2.0.10
	matt-nb8-mediatek-base:1.2
	perseant-stdc-iso10646:1.2.0.8
	perseant-stdc-iso10646-base:1.2
	netbsd-8:1.2.0.6
	netbsd-8-base:1.2
	prg-localcount2-base3:1.2
	prg-localcount2-base2:1.2
	prg-localcount2-base1:1.2
	prg-localcount2:1.2.0.4
	prg-localcount2-base:1.2
	pgoyette-localcount-20170426:1.2
	bouyer-socketcan-base1:1.2
	pgoyette-localcount-20170320:1.2
	bouyer-socketcan:1.2.0.2
	bouyer-socketcan-base:1.2
	pgoyette-localcount-20170107:1.2
	pgoyette-localcount-20161104:1.1.1.1
	localcount-20160914:1.1.1.1
	pgoyette-localcount-20160806:1.1.1.1
	pgoyette-localcount-20160726:1.1.1.1
	pgoyette-localcount:1.1.1.1.0.2
	pgoyette-localcount-base:1.1.1.1
	dtracetoolkit-2015-09-29:1.1.1.1
	FreeBSD:1.1.1;
locks; strict;
comment	@# @;


1.2
date	2016.12.12.16.30.03;	author christos;	state Exp;
branches;
next	1.1;
commitid	MvLsp79myOknjIxz;

1.1
date	2015.09.30.22.01.06;	author christos;	state Exp;
branches
	1.1.1.1;
next	;
commitid	d9nN99160jbCfkDy;

1.1.1.1
date	2015.09.30.22.01.06;	author christos;	state Exp;
branches
	1.1.1.1.2.1;
next	;
commitid	d9nN99160jbCfkDy;

1.1.1.1.2.1
date	2017.01.07.08.54.16;	author pgoyette;	state Exp;
branches;
next	;
commitid	uEL0C1YuiJrlV0Bz;


desc
@@


1.2
log
@simple path fixes
@
text
@#!/usr/pkg/bin/perl -w
#
# hotkernel - sample on-CPU kernel-level functions and modules.
#             Written using Perl and DTrace (Solaris 10 03/05)
#
# This samples the on-CPU function at 1001 Hertz, for a simple yet
# effective kernel-level profiling tool for sampling exclusive function time.
# The output will identify which function is on the CPU the most - which is
# the hottest. See Notes/ALLexclusive_notes.txt for an explanation of
# exclusive time.
#
# $Id: hotkernel,v 1.1.1.1 2015/09/30 22:01:06 christos Exp $
#
# USAGE:        hotkernel [-hm]
#
#		-h              # help
#		-m              # match modules, not functions
#       eg,
#		hotkernel       # sample kernel functions
#		hotkernel -m    # sample kernel modules
#
# FIELDS:
#		FUNCTION        Function name
#		MODULE          Module name
#		COUNT           Number of samples
#		PCNT            Percentage of total samples
#
# COPYRIGHT: Copyright (c) 2006 Brendan Gregg.
#
# CDDL HEADER START
#
#  The contents of this file are subject to the terms of the
#  Common Development and Distribution License, Version 1.0 only
#  (the "License").  You may not use this file except in compliance
#  with the License.
#
#  You can obtain a copy of the license at Docs/cddl1.txt
#  or http://www.opensolaris.org/os/licensing.
#  See the License for the specific language governing permissions
#  and limitations under the License.
#
# CDDL HEADER END
#
# Author: Brendan Gregg  [Sydney, Australia]
#
# 29-Jun-2006	Brendan Gregg	Created this.
# 29-Jun-2006	   "      "	Last update.
#

use strict;
use Getopt::Std;

#
# Command Line Arguments
#
my $args;
usage() if defined $ARGV[0] and $ARGV[0] eq "--help";
getopts('hm') or usage();
usage() if defined $main::opt_h and $main::opt_h;
my $mods = defined $main::opt_m and $main::opt_m ? 1 : 0;

#
# Cleanup on signals
#
$SIG{INT} = \&cleanupsig;    # Ctrl-C
$SIG{QUIT} = \&cleanupsig;   # Ctrl-\
$SIG{TERM} = \&cleanupsig;   # TERM

#
# Declare DTrace script
#
my $dtrace = <<END;
/usr/sbin/dtrace -n '
	#pragma D option quiet
	profile:::profile-1001hz
	/arg0/
	{
		\@@pc[arg0] = count();
	}
	dtrace:::END
	{
		printa("%a %\@@d\\n", \@@pc);
	}
'
END

#
# Run DTrace, process output
#
my %Count;
my $total;
open DTRACE, "$dtrace |" or die "ERROR1: Can't run dtrace (perms?): $!\n";
print "Sampling... Hit Ctrl-C to end.\n";
while (my $line = <DTRACE>) {
    next if $line =~ /^\s*$/;
    my ($addr, $count) = split ' ', $line;
    my ($name, $offset) = split /\+/, $addr;
    next if $name eq "0x0";
    $name =~ s/\`.*// if $mods;
    $Count{$name} += $count;
    $total += $count;
}
close DTRACE;

#
# Print final report
#
printf "\n%-52s %8s %6s\n", $mods ? "MODULE" : "FUNCTION", "COUNT", "PCNT";
foreach my $name (sort { $Count{$a} <=> $Count{$b} } keys %Count) {
    printf "%-52s %8d %5.1f%%\n", $name, $Count{$name},
                                  100 * $Count{$name} / ($total ? $total : 1);
}

#
# Subroutines
#
sub cleanupsig {
}
sub usage {
    print STDERR "USAGE: hotkernel [-hm]\n";
    print STDERR "   eg,\n";
    print STDERR "       hotkernel       # sample kernel functions\n";
    print STDERR "       hotkernel -m    # sample kernel modules\n";
    exit 1;
}
@


1.1
log
@Initial revision
@
text
@d1 1
a1 1
#!/usr/bin/perl -w
d12 1
a12 1
# $Id: hotkernel 65 2007-10-04 11:09:40Z brendan $
@


1.1.1.1
log
@Import the dtrace toolkit from FreeBSD; simple scripts such as dtruss work
unmodified. For others we'll need to add the missing probes and adjust.
This is not attached to the build.
@
text
@@


1.1.1.1.2.1
log
@Sync with HEAD.  (Note that most of these changes are simply $NetBSD$
tag issues.)
@
text
@d1 1
a1 1
#!/usr/pkg/bin/perl -w
d12 1
a12 1
# $Id: hotkernel,v 1.2 2016/12/12 16:30:03 christos Exp $
@

