This time I want to share with you a script that can be used to parse the JMeter’s .jtl results file removing some not needed stuff from it.

When such script might be useful?

The script was already used in these situations:

  • you have a huge results .jtl file – I’m talking about gigabytes in size here. JMeter’s html report looks great, but in case of a big results .jtl, its generation takes a very long time and it’s actually quite plausible that it will fail, due to shortage of Java heap memory. You can use the script to simply remove the not needed stuff from it. An example would be to keep only transactions and remove all atomic requests (or vice-versa).
  • you input the .jtl into other tools – e.g. reporting tools used in your company and the results file needs to be pre-processed.
  • you don’t like the report generator filter or it’s not sufficient.¬†JMeter report generator enables to configure filters that kind of parses the .jtl on the fly¬†(unless it’s too big). If the filters don’t do the trick for you, you can go for the parsing the .jtl before-hand.

 

How to use it?

Copy and paste the following script into a .ps1 (powershell extension) file. Amend the filenames in the ‘Configurable variables’ section of the script. Then execute it in the console by running: powershell -f name_of_thse_script.ps1.

 

# powershell jtl parser

#--------------------CONFIGURABLE VARIABLES---------------------------------------------

$input_jtl_filename_to_strip = "C:\results.jtl"
$output_jtl_filename = "C:\results_TRANSACTIONS_ONLY.jtl"

[regex]$header_recognition_regex = "[^\d+]"  # header does not start with digits
[regex]$transaction_match_regex = 'Number of samples' # regex matching rows that you want to keep (in this case transactions)

$batch_line_count = 1000

#----------------------------------------------------------------------------------------

# Reading header and saving it to output file
(Select-String -Path $input_jtl_filename_to_strip -Pattern $header_recognition_regex -list).line |
    Out-File -Append $output_jtl_filename -Encoding ascii

# Parsing input file and saving transactions to output
Write-Host "Starting parsing file"

Get-Content $input_jtl_filename_to_strip -ReadCount $batch_line_count |
    ForEach {
             $_ -match $transaction_match_regex | Out-File -Append $output_jtl_filename -Encoding ascii
    }

Write-Host "Finished extracting to " $output_jtl_filename

 

You can also play with the batch_line_count variable to quicken things up.

It can be adapted to do other things, like: filter out requests with response times exceeding certain threshold or having specific response code.