source: main/multimechanize/trunk/multimechanize/reportwriterxml.py @ 7557

Last change on this file since 7557 was 7541, checked in by uli, 13 years ago

Add sources copied from current multi-mechanize GIT repos.

File size: 2.2 KB
Line 
1#!/usr/bin/env python
2#
3#  Copyright (c) 2010-2012 Corey Goldberg (corey@goldb.org)
4#  License: GNU LGPLv3
5#
6#  This file is part of Multi-Mechanize | Performance Test Framework
7#
8
9
10from xml.etree import ElementTree as ET
11
12
13
14def write_jmeter_output(mm_data, output_path):
15    """
16    Take the list of ResponseStats objects and write a JMeter 2.1
17    formatted XML file to output_path.
18
19    JMeter JTL file documentation:
20    http://jakarta.apache.org/jmeter/usermanual/listeners.html
21    """
22    root = ET.Element('testResults')
23    root.set('version', "1.2")
24
25    for test_transaction in mm_data:
26        # each transaction might have multiple timers
27        transaction_root = ET.SubElement(root, 'sample')
28        # JMeter uses ms for time
29        ms_trans_time = test_transaction.trans_time * 1000
30        transaction_root.set('t', '%d' % ms_trans_time)
31        ms_timestamp = test_transaction.epoch_secs * 1000
32        transaction_root.set('ts', '%d' % ms_timestamp)
33        transaction_root.set('lb', test_transaction.user_group_name)  # label
34        transaction_root.set('sc', '1')  # sample count
35
36        if test_transaction.error:
37            transaction_root.set('ec', '1') # was an error
38            transaction_root.set('s', 'false') # was an error
39            # errors don't have custom_timers
40            continue
41        else:
42            transaction_root.set('ec', '0')
43            transaction_root.set('s', 'true')
44
45        # parse the custom_timers and add each as a JMeter sub-sample
46        for timer_name, timer_duration in test_transaction.custom_timers.items():
47            timer_duration = float(timer_duration)
48            timer_element = ET.SubElement(transaction_root, 'sample')
49            ms_trans_time = timer_duration * 1000
50            timer_element.set('t', '%d' % ms_trans_time)
51            # subtimers don't have timestamps, so use the Transaction ts
52            timer_element.set('ts', '%d' % ms_timestamp)
53            timer_element.set('lb', timer_name)
54            timer_element.set('sc', '1')
55            timer_element.set('ec', '0')
56            timer_element.set('s', 'true')
57
58    tree = ET.ElementTree(root)
59    tree.write(output_path + '/results.jtl')
60    tree.write('last_results.jtl')
Note: See TracBrowser for help on using the repository browser.