forked from OpenXiangShan/XiangShan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dev-lbuf-bpu
- Loading branch information
Showing
49 changed files
with
2,154 additions
and
709 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,79 @@ | ||
mymap = {} | ||
last = "" | ||
|
||
with open("../build/XSSimTop.v", "r") as f: | ||
line = f.readline() | ||
cnt = 0 | ||
while(line): | ||
if "module " in line: | ||
if last!="" : | ||
mymap[last] = cnt | ||
last = line[6:-2] | ||
cnt = 1 | ||
else: | ||
cnt = cnt + 1 | ||
import os | ||
import argparse | ||
|
||
def printMap(mp): | ||
len_key = max(map(lambda s: len(s), mp.keys())) | ||
len_value = max(map(lambda v: len(str(v)), mp.values())) | ||
pattern = "{:<" +str(len_key) + "} {:<" +str(len_value)+ "} {:<7}%" | ||
total = sum(mp.values()) | ||
for k,v in sorted(mp.items(), key=lambda x:x[1], reverse=True): | ||
print( | ||
pattern.format(k, v, round(v*100.0/total, 3)) | ||
) | ||
|
||
|
||
def analyzeVerilog(filename): | ||
mymap = {} | ||
last = "" | ||
with open(filename, "r") as f: | ||
line = f.readline() | ||
for k,v in mymap.items(): | ||
print(k, v) | ||
cnt = 0 | ||
while(line): | ||
if "module " in line: | ||
if last!="" : | ||
mymap[last] = cnt | ||
last = line[7:-2] | ||
cnt = 1 | ||
else: | ||
cnt = cnt + 1 | ||
line = f.readline() | ||
mymap[last] = cnt | ||
printMap(mymap) | ||
|
||
logLevels = ['ALL', 'DEBUG', 'INFO', 'WARN', 'ERROR'] | ||
|
||
def listToStr(lst): | ||
acc = '' | ||
for l in lst: | ||
acc += '|' + str(l) if acc else str(l) | ||
return acc | ||
|
||
def lineStrip(line): | ||
return line.replace('\n', '') | ||
|
||
def getNumLogLines(filename, modules, ll=logLevels): | ||
cmd = "grep -E '\[({0}).*\]\[time=.*\] ({1}):' {2} | wc -l".format( | ||
listToStr(ll), | ||
listToStr(modules), | ||
filename | ||
) | ||
res = os.popen(cmd) | ||
return int(lineStrip(res.readline()), 10) | ||
|
||
def analyzeLog(filename): | ||
cmd = "grep -E '\[time=.*\]' {0} ".format(filename) + " | awk -F '(:)' {'print $1'} | awk {'print $NF'} | sort | uniq" | ||
res = os.popen(cmd) | ||
modules = list(map(lineStrip, res.readlines())) | ||
mymap = {} | ||
for m in modules: | ||
mymap[m] = getNumLogLines(filename, [m]) | ||
printMap(mymap) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-v", "--verilogFile", help="verilog file path", type=str) | ||
parser.add_argument("-l", "--logFile", help="log file path", type=str) | ||
args = parser.parse_args() | ||
|
||
if args.verilogFile: | ||
analyzeVerilog(args.verilogFile) | ||
|
||
if args.logFile: | ||
analyzeLog(args.logFile) | ||
|
||
if not args.verilogFile and not args.logFile: | ||
parser.print_help() | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.