source: main/waeup.sirp/branches/ulif-stress-multimech/multi-mechanize/lib/reportwriterxml.py @ 7543

Last change on this file since 7543 was 7478, checked in by uli, 13 years ago

Sample usage of multi-mechanize (not finished).

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