Skip to content

Commit 41a71ab

Browse files
Andrei MaletsAndrei_Malets
authored andcommitted
MAGETWO-72076: Update benchmark.jmx and README files in Performance Toolkit, add performance analytics script
- Refactored script for generation of aggregate reports
1 parent 0184090 commit 41a71ab

File tree

3 files changed

+84
-44
lines changed

3 files changed

+84
-44
lines changed

setup/performance-toolkit/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ By default, the percentage ratio between thread groups is as follows:
259259

260260
### Results Interpretation
261261

262-
In order to build an aggregate report from the results of the `benchmark.kmx` scenario run, use the script `generate.php` in the folder `setup/performance-toolkit/aggregate-report`.
262+
In order to build an aggregate report from the results of the `benchmark.kmx` scenario run, use the script `generate-b2c.php` in the folder `setup/performance-toolkit/aggregate-report`.
263263

264264
The script parses the JTL file and generates an aggregate report in CSV format. The report consists of the 4 sections separated by two empty lines:
265265

@@ -281,7 +281,7 @@ After that, the information about memory usage for each request will be logged i
281281

282282
To generate the aggregate report, run the following command from the Magento root directory:
283283

284-
php setup/performance-toolkit/aggregate-report/generate.php -j {path to folder with JTL file}/jmeter_report.jtl -m var/log/memory_usage.log -o aggregate_report.csv
284+
php setup/performance-toolkit/aggregate-report/generate-b2c.php -j {path to folder with JTL file}/jmeter_report.jtl -m var/log/memory_usage.log -o aggregate_report.csv
285285

286286
**Legacy Scenario**
287287

setup/performance-toolkit/aggregate-report/generate.php renamed to setup/performance-toolkit/aggregate-report/common.php

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,41 @@
55
*/
66

77
/**
8-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
9-
* @SuppressWarnings(PHPMD.NPathComplexity)
10-
*/
11-
12-
$usageMessage =
13-
'Usage:' . PHP_EOL
14-
. ' php generate.php -j jmeter_report.jtl -m memory_usage.log -o output_file.csv' . PHP_EOL
15-
. PHP_EOL
16-
. 'Parameters:' . PHP_EOL
17-
. ' -j - jmeter report file' . PHP_EOL
18-
. ' -m - memory usage report file (optional)' . PHP_EOL
19-
. ' -o - output report file' . PHP_EOL
20-
. ' -f - include failed requests in report (optional)' . PHP_EOL;
8+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
9+
* @SuppressWarnings(PHPMD.NPathComplexity)
10+
*/
2111

22-
$args = getopt('j:m:o:f');
23-
if (empty($args['j']) || empty($args['o'])) {
24-
echo $usageMessage;
25-
exit(0);
26-
}
12+
/**
13+
* Generate aggregate report in CSV format based on JTL file.
14+
*
15+
* @param array $mapping
16+
* @param callable $generateSummary
17+
* @param callable $rowCallback [optional]
18+
* @return void
19+
*/
20+
function generateReport(array $mapping, callable $generateSummary, callable $rowCallback = null)
21+
{
22+
$usageMessage =
23+
'Usage:' . PHP_EOL
24+
. ' php generate.php -j jmeter_report.jtl -m memory_usage.log -o output_file.csv' . PHP_EOL
25+
. PHP_EOL
26+
. 'Parameters:' . PHP_EOL
27+
. ' -j - jmeter report file' . PHP_EOL
28+
. ' -m - memory usage report file (optional)' . PHP_EOL
29+
. ' -o - output report file' . PHP_EOL
30+
. ' -f - include failed requests in report (optional)' . PHP_EOL;
2731

28-
require_once("b2c_mappings.php");
32+
$args = getopt('j:m:o:f');
33+
if (empty($args['j']) || empty($args['o'])) {
34+
echo $usageMessage;
35+
exit(0);
36+
}
2937

30-
list($jmeterData, $executionTime) = parseJmeterReport($args['j'], isset($args['f']));
31-
$memoryUsageData = !empty($args['m']) ? parseMemoryUsageLog($args['m']) : [];
32-
$aggregatedResult = prepareAggregatedResult($jmeterData, $memoryUsageData, $mapping);
33-
parseReportAndWriteToCsv($aggregatedResult, $executionTime, $args['o']);
38+
list($jmeterData, $executionTime) = parseJmeterReport($args['j'], isset($args['f']));
39+
$memoryUsageData = !empty($args['m']) ? parseMemoryUsageLog($args['m']) : [];
40+
$aggregatedResult = prepareAggregatedResult($jmeterData, $memoryUsageData, $mapping);
41+
parseReportAndWriteToCsv($aggregatedResult, $executionTime, $args['o'], $generateSummary, $rowCallback);
42+
}
3443

3544
/**
3645
* Read memory usage log into array.
@@ -116,6 +125,7 @@ function prepareAggregatedResult(array $jmeterData, array $memoryUsageData, arra
116125
$aggregatedResult[$key]['label'] = $mapping['label'];
117126
$aggregatedResult[$key]['scenario'] = $mapping['scenario'] ?? 'Total';
118127
$aggregatedResult[$key]['is_service_url'] = $mapping['is_service_url'] ?? false;
128+
$aggregatedResult[$key]['is_requisition'] = $mapping['is_requisition'] ?? false;
119129
$aggregatedResult[$key]['is_storefront'] = $mapping['is_storefront'] ?? false;
120130
$aggregatedResult[$key]['time'] = [];
121131
$aggregatedResult[$key]['labels'] = [];
@@ -161,10 +171,17 @@ function ($a, $b) {
161171
* @param array $aggregatedResult
162172
* @param int $executionTime
163173
* @param string $outputFile Path to the output report
174+
* @param callable $generateSummary
175+
* @param callable $rowCallback [optional]
164176
* @return void
165177
*/
166-
function parseReportAndWriteToCsv(array $aggregatedResult, $executionTime, $outputFile)
167-
{
178+
function parseReportAndWriteToCsv(
179+
array $aggregatedResult,
180+
$executionTime,
181+
$outputFile,
182+
callable $generateSummary,
183+
callable $rowCallback = null
184+
) {
168185
$headersArray = [
169186
'Scenario',
170187
'Label',
@@ -179,23 +196,7 @@ function parseReportAndWriteToCsv(array $aggregatedResult, $executionTime, $outp
179196
'Memory Usage, Mb'
180197
];
181198
$fp = fopen($outputFile, 'w');
182-
183-
$pageViews = 0;
184-
$checkoutCount = 0;
185-
foreach ($aggregatedResult as $row) {
186-
if ($row['is_storefront']) {
187-
$pageViews += count($row['time']);
188-
}
189-
if (strpos($row['label'], 'Checkout Success Page') !== false) {
190-
$checkoutCount += count($row['time']);
191-
}
192-
}
193-
fputcsv($fp, ['Checkouts Per Hour:', round($checkoutCount / $executionTime * 3600000, 2)]);
194-
fputcsv($fp, ['Page Views Per Hour:', round($pageViews / $executionTime * 3600000, 2)]);
195-
fputcsv($fp, ['Test Duration, s:', round($executionTime / 1000)]);
196-
fputcsv($fp, ['']);
197-
fputcsv($fp, ['']);
198-
fputcsv($fp, $headersArray);
199+
$generateSummary($fp, $aggregatedResult, $headersArray, $executionTime);
199200
foreach ($aggregatedResult as $row) {
200201
if (count($row['time']) && !$row['is_service_url']) {
201202
sort($row['time']);
@@ -212,6 +213,9 @@ function parseReportAndWriteToCsv(array $aggregatedResult, $executionTime, $outp
212213
round(count($row['time']) / $executionTime * 3600000, 2),
213214
$row['memory']
214215
];
216+
if ($rowCallback) {
217+
$rowCallback($row, $ar);
218+
}
215219
fputcsv($fp, $ar);
216220
}
217221
}
@@ -233,6 +237,9 @@ function parseReportAndWriteToCsv(array $aggregatedResult, $executionTime, $outp
233237
round(count($row['time']) / $executionTime * 3600000, 2),
234238
$row['memory']
235239
];
240+
if ($rowCallback) {
241+
$rowCallback($row, $ar);
242+
}
236243
fputcsv($fp, $ar);
237244
}
238245
}
@@ -241,6 +248,9 @@ function parseReportAndWriteToCsv(array $aggregatedResult, $executionTime, $outp
241248
foreach ($aggregatedResult as $row) {
242249
if (count($row['time']) == 0) {
243250
$ar = [$row['scenario'], $row['label'], '-', '-', '-', '-', '-', '-', '-', 0, '-'];
251+
if ($rowCallback) {
252+
$rowCallback($row, $ar);
253+
}
244254
fputcsv($fp, $ar);
245255
}
246256
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require_once('b2c_mappings.php');
8+
require_once('common.php');
9+
10+
generateReport(
11+
$mapping,
12+
function ($fp, $aggregatedResult, $headersArray, $executionTime) {
13+
$pageViews = 0;
14+
$checkoutCount = 0;
15+
foreach ($aggregatedResult as $row) {
16+
if ($row['is_storefront']) {
17+
$pageViews += count($row['time']);
18+
}
19+
if (strpos($row['label'], 'Checkout Success Page') !== false) {
20+
$checkoutCount += count($row['time']);
21+
}
22+
}
23+
fputcsv($fp, ['Checkouts Per Hour:', round($checkoutCount / $executionTime * 3600000, 2)]);
24+
fputcsv($fp, ['Page Views Per Hour:', round($pageViews / $executionTime * 3600000, 2)]);
25+
fputcsv($fp, ['Test Duration, s:', round($executionTime / 1000)]);
26+
fputcsv($fp, ['']);
27+
fputcsv($fp, ['']);
28+
fputcsv($fp, $headersArray);
29+
}
30+
);

0 commit comments

Comments
 (0)