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