Skip to content

Commit

Permalink
Merge pull request #29 from Nancy-Chauhan/master
Browse files Browse the repository at this point in the history
Modify extract-yosys-stats.py to output result compatible to Jenkins plot plugin
  • Loading branch information
oleg-nenashev authored Aug 21, 2019
2 parents 5e2d0a4 + bfb42e6 commit a6352c0
Showing 1 changed file with 42 additions and 71 deletions.
113 changes: 42 additions & 71 deletions librecores-ci/test-scripts/extract-yosys-stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,45 @@
import re
import csv

parser_state = 0
matches = []
cells = []

# Printing statistics are extracted from yosys.log
for line in sys.stdin:
if parser_state == 0:
if re.match(r"(?:\d+\.)* Printing statistics\.", line):
parser_state = 1
elif parser_state == 1:
match_result = re.match(r"\s{3}Number of ([\w\s]+):\s+(\d+)", line)
if match_result:
metric = match_result.group(1)
value = match_result.group(2)
matches.append((metric, value))

if metric == "cells":
parser_state = 2
elif parser_state == 2:
match_result = re.match(r"\s{5}(\w+)\s+(\d+)", line)
if match_result:
cell_type = match_result.group(1)
count = match_result.group(2)

cells.append((cell_type, count))

print(matches)
print(cells)

# Outputs the stats in CSV format
with open('result.csv', 'w') as csvFile:
writer = csv.writer(csvFile)
writer.writerows(matches)
writer.writerows(cells)

with open('result.csv', newline='') as f:
r = csv.reader(f)
data = [line for line in r]
with open('result.csv', 'w', newline='')as f:
w = csv.writer(f)
w.writerow(['label', 'elapsed'])
w.writerows(data)

# Code for getting JMeter compatible CSV file for Performance Plugin
# TODO: result.csv with Key Value has to be made compatible with Jenkins Perforamce plugin
in_file = 'result.csv'
out_file = 'report.csv'
with open(in_file, 'r') as in_f, open(out_file, 'w', newline='') as out_f:
rdr = csv.DictReader(in_f)
fieldnames = ['timeStamp', 'responseCode', 'responseMessage',
'threadName', 'dataType', 'success', 'bytes']
fieldnames.extend(rdr.fieldnames)
wrtr = csv.DictWriter(out_f, fieldnames=fieldnames)
wrtr.writeheader()
for row_id, row in enumerate(rdr, start=1):
row['timeStamp'] = '2019-08-14 14:15:25.321'.format(row_id)
row['responseCode'] = '200'.format(row_id)
row['responseMessage'] = 'OK'.format(row_id)
row['threadName'] = 'Thread Group 1-1'.format(row_id)
row['dataType'] = 'text'.format(row_id)
row['success'] = 'true'.format(row_id)
row['bytes'] = '3478'.format(row_id)
wrtr.writerow(row)

with open('report.csv', 'r') as infile, open('output.csv', 'a') as outfile:
fieldnames = ['timeStamp', 'elapsed', 'label', 'responseCode',
'responseMessage', 'threadName', 'dataType', 'success', 'bytes']
writer = csv.DictWriter(outfile, fieldnames=fieldnames)
writer.writeheader()
for row in csv.DictReader(infile):
writer.writerow(row)
def write_csv(file_path, content):
with open(file_path, 'w') as csvFile:
writer = csv.DictWriter(csvFile, content.keys())
writer.writeheader()
writer.writerow(content)


def main():
parser_state = 0
metrics = {}
cells = {}

# Printing statistics are extracted from yosys.log
for line in sys.stdin:
if parser_state == 0:
if re.match(r"(?:\d+\.)* Printing statistics\.", line):
parser_state = 1
elif parser_state == 1:
match_result = re.match(r"\s{3}Number of ([\w\s]+):\s+(\d+)", line)
if match_result:
metric = match_result.group(1)
value = match_result.group(2)
metrics[metric] = value

if metric == "cells":
parser_state = 2
elif parser_state == 2:
match_result = re.match(r"\s{5}(\w+)\s+(\d+)", line)
if match_result:
cell_type = match_result.group(1)
count = match_result.group(2)

cells[cell_type] = count


# Outputs the stats in CSV format
write_csv('yosys-stats.csv', metrics)
write_csv('yosys-cell-stats.csv', cells)


if __name__ == "__main__":
main()

0 comments on commit a6352c0

Please sign in to comment.