<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>neilkodner.com &#187; performance</title>
	<atom:link href="http://www.neilkodner.com/tag/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.neilkodner.com</link>
	<description>Data Driven.  Since 1971.</description>
	<lastBuildDate>Sun, 23 Oct 2011 16:40:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Generating multiple Oracle TKPROF reports using Python</title>
		<link>http://www.neilkodner.com/2009/11/generating-multiple-oracle-tkprof-reports-using-python/</link>
		<comments>http://www.neilkodner.com/2009/11/generating-multiple-oracle-tkprof-reports-using-python/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 17:44:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dba]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.neilkodner.com/?p=76</guid>
		<description><![CDATA[Recently, a customer told me that they felt a batch job was taking too long each night, I gave them a few commands to add to their nightly run. These commands named the tracefile and enabled 10046 logging. Since I&#8217;m lazy(the good kind), I figured I&#8217;d use Python to build the commands to run TKPROF [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, a customer told me that they felt a batch job was taking too long each night, I gave them a few commands to add to their nightly run.</p>
<pre class="brush: sql; title: ; notranslate">
alter session set tracefile_identifier='charging_batch';
exec dbms_monitor.session_trace_enable;
</pre>
<p>These commands named the tracefile and enabled 10046 logging.</p>
<p>Since I&#8217;m lazy(the good kind), I figured I&#8217;d use Python to build the commands to run TKPROF for each process.  The program expects to be run from the udump directory.  As I get more time I&#8217;ll enhance it to automatically grab the location of udump from the database.</p>
<p>The script takes an optional parameter for a tracefile identifier.  If the parameter is passed, filenames containing the identifier text will be processed.  Otherwise, all tracefiles are processed.  A to-do item is to make sure the tracefile is an actual 10046 before running TKPROF against it.</p>
<p>The output format is the optional tracefile identifier_process_id.out.  The file suffix can be overridden with variable tkprof_suffix.  I use .out as an homage to Michael Levy, wherever he may be, who showed me how to use the tool way back in 1998.</p>
<pre class="brush: python; title: ; notranslate">
#!/usr/local/bin/python
# tkprof.py
# kodner 2009
# and runs a simple tkprof on them
import sys
import os
import re
sort = &quot;fchqry&quot; #parameterize this
tkprof_suffix = 'out' #this too

# find a string to be used as a tracefile identifier
# to limit the tracefiles processed
try:
  tracefile_identifier = sys.argv[1]
  print &quot;&quot;
  print &quot;&quot;
  print &quot;tracefile identifier supplied is: %s&quot; % (tracefile_identifier)
  print &quot;&quot;
  print &quot;&quot;
except:
  tracefile_identifier = None

# lists the files with suffix .trc and contain out suffix .trc
traces=[x for x in os.listdir('.') if x.endswith('.trc')]

for file in traces:
  tracefile = None

  # extract the process id from the filename.
  # I'm sure this could be done better.  i split it into multiple
  # lines for readability.

  processNum = re.findall(r'ora_[0-9]+',file)
  processNum = processNum[0].split('_')[1]

  # if a tracefile_identifier is supplied then make sure our current file
  # contains the string.  we'll also make sure the output filename contains
  # the tracefile identifier.

  if tracefile_identifier:
    if file.find(tracefile_identifier) &gt; 0:
      tracefile = file
      outputfile=tracefile_identifier + '_' + processNum + '.' + tkprof_suffix
  else:
    tracefile=file
    outputfile=processNum + '.' + tkprof_suffix

  if tracefile:
    print &quot;processing tracefile %s ...&quot; % (tracefile)

    # using regexp, find the process number of the file.
    # the process number will be used to name the tkprof output file

    # we will assume that the tracefile name is in the format
    # $ORACLE_SID_ora_$PROCESSNUM.trc
    # and that the tracefile name may contain a tracefile identifier
    # set by using alter session set tracefile_identifier = 'foo';

    # generate the tkprof command use flags sys=no and waits=yes
    command=&quot;tkprof %s %s sys=no waits=yes sort=%s&quot; % (tracefile,outputfile,sort)

    # execute the command
    os.system(command)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.neilkodner.com/2009/11/generating-multiple-oracle-tkprof-reports-using-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

