From 24c706fd58758ae6466fcd8c936f3682363894a3 Mon Sep 17 00:00:00 2001 From: calvin Date: Mon, 18 Nov 2002 23:23:06 +0000 Subject: [PATCH] added profiling options git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@607 e7d03fd6-7b0d-0410-9947-9c21f3af8025 --- ChangeLog | 1 + linkchecker | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7ae9dee..cde93848 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ than one link attribute in it. * Fix concatenation with relative base urls by first joining the parent url. + * New commandline option --profile to write profile data. 1.6.6 * Use the new HTTPConnection/HTTPResponse interface of httplib diff --git a/linkchecker b/linkchecker index 194a37eb..239e7cb9 100755 --- a/linkchecker +++ b/linkchecker @@ -29,6 +29,7 @@ linkcheck.timeoutsocket.setDefaultSocketTimeout(30) from linkcheck.debuglevels import * from linkcheck import StringUtil debug = linkcheck.debug +_profile = "linkchecker.prof" # main usage text Usage = linkcheck._("""USAGE\tlinkchecker [options] file-or-url... @@ -83,6 +84,10 @@ For single-letter option arguments the space is not a necessity. So Pause seconds between each url check. This option implies -t0. Default is no pause between requests. +--profile + Write profiling data into a file named %s in the + current working directory. + See also --viewprof. -q, --quiet Quiet operation. This is only useful with -F. -r depth, --recursion-level=depth @@ -104,6 +109,8 @@ For single-letter option arguments the space is not a necessity. So -v, --verbose Log all checked URLs (implies -w). Default is to log only invalid URLs. +--viewprof + Print out previously generated profiling data. See also --profile. -w, --warnings Log warnings. -W regex, --warning-regex=regex @@ -115,7 +122,7 @@ For single-letter option arguments the space is not a necessity. So message, for example 'This page has moved' or 'Oracle Application Server error'. This option implies -w. -""") % linkcheck.log.LoggerKeys +""") % (linkcheck.log.LoggerKeys, _profile) Notes = linkcheck._("""NOTES o LinkCheckers commandline parser treats "ftp." links like "ftp://ftp." @@ -167,6 +174,16 @@ def printUsage (msg): sys.exit(1) +def viewprof (): + if not os.path.exists(_profile): + sys.stderr.write(linkcheck._("Could not find profiling file %s.")%_profile) + sys.stderr.write(linkcheck._("Please run linkchecker with --profile to generate it.")) + sys.exit(1) + import pstats + stats = pstats.Stats(_profile) + stats.strip_dirs().sort_stats("cumulative").print_stats(50) + sys.exit(0) + # Read command line arguments try: # Note: cut out the name of the script @@ -186,6 +203,7 @@ try: "output=", "password=", "pause=", + "profile", "quiet", "recursion-level=", "wischiwaschi", @@ -196,6 +214,7 @@ try: "user=", "version", "verbose", + "viewprof", "warnings", "warning-regex="]) except getopt.error: @@ -221,6 +240,7 @@ if linkcheck.Config.DebugLevel > 0: _user = "anonymous" _password = "guest@" constructauth = 0 +do_profile = 0 for opt,arg in options: if opt=="-a" or opt=="--anchors": config["anchors"] = 1 @@ -273,6 +293,9 @@ for opt,arg in options: printUsage((linkcheck._("Illegal argument '%s' for option ") % arg) + "'-P, --pause'") + elif opt=="--profile": + do_profile = 1 + elif opt=="-q" or opt=="--quiet": config["quiet"] = 1 @@ -310,6 +333,9 @@ for opt,arg in options: config["verbose"] = 1 config["warnings"] = 1 + elif opt=="--viewprof": + viewprof() + elif opt=="--wischiwaschi": from linkcheck import util1 util1.abbuzze() @@ -358,7 +384,11 @@ for url in args: config.appendUrl(UrlData.GetUrlDataFrom(url, 0, config)) ############################# check the urls ################################ -linkcheck.checkUrls(config) +if do_profile: + import profile + profile.run("linkcheck.checkUrls(config)", _profile) +else: + linkcheck.checkUrls(config) ############################################################################# # interactive input end