Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Explain Perl parser a bit better, especially regarding HTTP redirects

...

Please add your tips and tricks to this page. Extraction scripts and Excel Macros etc welcome!

...

Here 's how Sonam imports are the steps Sonam Chauhan uses to import and process JMeter log data in Excel. Steps #3 and 4 are quite painstaking. It would be nice to have a macro to automate those steps - however, it is beyond my Excel abilities at the moment.:

  1. First, I have to get the data generate delimited file for import into Excel.

I use Perl to parse the XML logs and generate a delimited file for import into Excel

...

.

...

The heart of my the Perl data-mangler script is this the regular expression :below. Each line in the JMeter logfile must be matched to this expression:

No Format

# Regular expression extracts relevant fields
No Format

# Each line in logfile is matched to this regular expression to grab relevant details from the log entry. 

/timeStamp="(\d+)".+?threadName="(.*?)".+?label="(.+?)" time="(\d+?)".+?success="(.+?)"/;

# Explanation for regex:
# A normal log entry line logs one HTTP 'sampler' operation:
# 	<sampleResult timeStamp="..." ... threadName="..." label="..." time="..." />
# In case the opertion had HTTP redirects, the redirects show up as 
# nested <sampleResult> elements,  but still on the same line:
# 	<sampleResult timeStamp= ... > <sampleResult timeStamp=.... > ... </sampleResult>
# We are only interested in the data in the first <sampleResult> element, 
# so we use non-greedy pattern match operator ( '.*?' or '.+?') to ignore 
# any latter <sampleResult> elements,

# The temporary Perl variables this regular expression generates are used to write a comma-delimited line.
my $timestamp = $1; # unix timestamp 
my $threadname = $2; # thread label
my $label = $3; # operation label 
my $time = $4; # operation time in milliseconds
my $success = $5; # boolean success indicator for this operation
 Data in the regex variables is accessed for use in building suitably-delimited line
my $timestamp = $1; # unix timestamp 
my $threadname = $2; # thread label
my $label = $3; # operation label 
my $time = $4; # operation time in milliseconds
my $success = $5; # boolean success indicator for this operation

The complexity of the regular expression is required to parse nested log entries that occur during HTTP redirects. A normal log entry line logs one HTTP 'sampler' operation. For eg:

No Format

<sampleResult ... time="156" ... />

However, when the opertion had a HTTP redirect (HTTP status code 302), JMeter records the redirects as nested <sampleResult> elements – these which still occur on the same line as the log entry:
{{{<sampleResult ... time="2750"> <sampleResult ... time="2468" ... /> <sampleResult time="141" .../> <sampleResult ... time="141" .../> </sampleResult>
}}}

The outermost <sampleResult> element has time = 2750 milliseconds. This is the sum of times of the nested redirect elements. We are only interested in the data contained in the outermost element. Hence the regular expression uses the non-greedy pattern match operator ( .*? or .+?) to ignore the latter <sampleResult> elements.

On the other hand, Excel 2002 can directly import JMeter XML format logs. However, it has problems with entries for HTTP 302 redirects. The nested log entry example above will generate three rows in Excel, with the total time repeated thrice. i.e:

No Format

Login	2750
Login	2750
Login	2750 

2. Convert Timestamps to Excel Format

2. Once the data is in Excel, I convert the timestamp column from Jmeter's Unix timestamp format (base year 1970) to the Excel format (base year 1900) using this following formula. This formula is applied to the entire timestamp column. (NOTE: a better formula was mentioned on JMeter users list sometime back)

No Format
=(x/1000+((365*70+17)*86400))/86400

3. I then Now sort rows are sorted by on the operation name (i.e. JMeter sampler name)

4. I can now generate Generate suitable reports and graphs manually.

For instance, I one can generate a graph of page load times v/s time for different operations (e.g.: login, add 1 line to the order, etc). A different series in the graph is needed for each operation type is used. Steps #3 and 4 are quite painstaking. It would be nice to have a macro to automate those steps - however, it is beyond my Excel abilities at the momentused - this can be quite painstaking to add to a graph when there is a lot of data.

...