⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mkdemo.pl

📁 Sun Solaris 10 中的 DTrace 组件的源代码。请参看: http://www.sun.com/software/solaris/observability.jsp
💻 PL
字号:
#!/usr/perl5/bin/perl -w## Copyright 2005 Sun Microsystems, Inc.  All rights reserved.## The contents of this file are subject to the terms of the# Common Development and Distribution License, Version 1.0 only.# See the file usr/src/LICENSING.NOTICE in this distribution or# http://www.opensolaris.org/license/ for details.## ident	"@(#)mkdemo.pl	1.1	04/10/25 SMI"require 5.005;use strict;use warnings;use Time::localtime;use File::Basename;our ($cmd, $chapfile, $htmlfile, $dtrace_url, %chaps);$cmd = "mkdemo";$chapfile = "chapters";$htmlfile = "index.html";$dtrace_url = "http://www.sun.com/bigadmin/content/dtrace";sub chaps_read {	my $fatal;	my %hash;	open(CHAPS, "$chapfile");	while (<CHAPS>) {		my $field;		my $value;		chop;		if (/^#/) {			next;		}		if (!/:/) {			if (exists $hash{'name'}) {				if (exists $chaps{$hash{'name'}}) {					print "$cmd: chapter $hash{'name'} ";					print "has two entries.\n";					$fatal = 1;				}				$chaps{$hash{'name'}} = { %hash };				%hash = ();				next;			}			%hash = ();			next;		}		($field, $value) = split /:\s*/, $_, 2;		if ($field eq "descr") {			$value .= " ";		}		$hash{$field} .= $value;	}	if ($fatal) {		print "$cmd: fatal errors; cannot proceed.\n";		exit;	}	close (CHAPS);}	sub chaps_ascending {	$chaps{$a}{number} <=> $chaps{$b}{number};}sub demo_process {	my $chap = $_[0];	my $demo = $_[1];	my $year = localtime->year() + 1900;	open DEMO, "<$chap/$demo" or die "Can't open demo $chap/$demo";	open OUT, ">$demo" or die "Can't open $demo";	print OUT <<EOF;/* * Copyright $year Sun Microsystems, Inc.  All rights reserved. * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only. * See the file usr/src/LICENSING.NOTICE in this distribution or * http://www.opensolaris.org/license/ for details. * * This D script is used as an example in the Solaris Dynamic Tracing Guide * in Chapter $chaps{$chap}{number}, \"$chaps{$chap}{title}\". * * The full text of Chapter $chaps{$chap}{number} may be found here: * *   $chaps{$chap}{url} * * On machines that have DTrace installed, this script is available as * $demo in /usr/demo/dtrace, a directory that contains all D scripts * used in the Solaris Dynamic Tracing Guide.  A table of the scripts and their * corresponding chapters may be found here: * *   file:///usr/demo/dtrace/index.html */EOF	while (<DEMO>) {		print OUT $_;	}}sub demo_find {	my $demo = $_[0];	my $chap;	foreach $chap (keys %chaps) {		if (!stat("$chap/$demo")) {			next;		}		demo_process($chap, $demo);		return;	}	die "Couldn't find $demo in any chapter";}sub chaps_process {	my $outfile = $_[0];	my $chap;	open HTML, ">$outfile" or die "Can't open $outfile.";	print HTML "<html>\n<head>\n";	print HTML "<title>Example DTrace Scripts</title>\n";	print HTML "</head>\n<body bgcolor=\"#ffffff\">\n";	print HTML "<table width=\"85%\" border=0 align=\"center\"><tr><td>";	print HTML "<table width=\"100%\" border=0><tr>";	print HTML "<td align=\"left\">";	print HTML "<h2>DTrace Examples</h2>\n";	print HTML "</td>";	print HTML "<td align=\"right\">";	print HTML "<img src=\"sunlogo.gif\"></td></tr></table>\n";	print HTML "<hr><p>\n";	print HTML "Here are the <a href=\"$dtrace_url\">DTrace</a> scripts\n";	print HTML "that are used as examples in the\n";	print HTML "<a href=\"$chaps{book}{url}\">$chaps{book}{title}</a>. ";	print HTML "For more information on any one script, follow the link\n";	print HTML "to its corresponding chapter.\n";	print HTML "<p>\n<hr><p>\n";	print HTML "<left><table width=\"85%\" border=1 cellpadding=4 ";	print HTML "cellspacing=0 align=\"center\" bgcolor=\"#e8e8f0\">\n";	print HTML "<tr bgcolor=\"#455693\"><td width=\"50%\">";	print HTML "<font color=\"#ffffff\"><b>Chapter</b></td></font>\n";	print HTML "<td><font color=\"#ffffff\"><b>Script</b></td>\n";	print HTML "</font></tr>\n";	foreach $chap (sort chaps_ascending (keys %chaps)) {		my @demos;		my $demo;		#		# Open the directory associated with the chapter.		#		if ($chap =~ /^book$/) {			next;		}		opendir(DEMOS, $chap) || die("Cannot open directory $chap");		@demos = readdir(DEMOS);		closedir(DEMOS);		print HTML "<tr>\n";		print HTML "<td align=left>";		print HTML "<a href=\"$chaps{$chap}{url}\">";		print HTML "Chapter $chaps{$chap}{number}: ";		print HTML "$chaps{$chap}{title}</a></td>\n";		print HTML "<td><table border=0>\n";		foreach $demo (@demos) {			if ($demo !~ /^[a-z].*\.d$/) {				next;			}			print HTML "<tr><td><a href=\"$demo\">$demo</a>";			print HTML "</td></tr>\n";			demo_process($chap, $demo);		}		print HTML "</table></td></tr>\n";	}	print HTML "</table>\n</td>\n<p>\n\n";	print HTML "</td></tr>\n";	print HTML "<tr><td><hr><small>Copyright ";	print HTML localtime->year() + 1900;	print HTML " Sun Microsystems</small>\n";	print HTML "</table>\n";	print HTML "</body>\n</html>\n";	close HTML;}chaps_read();if (basename($ARGV[0]) ne "$htmlfile") {	demo_find(basename($ARGV[0]));} else {	chaps_process($htmlfile);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -