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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#!/usr/bin/python
# This file is part of the LibreOffice project.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
import os
import time
parseTrigger = "desc: Trigger: Client Request: "
parseTotal = "totals: "
separator = os.path.sep
lastCommitId = ""
needsCsvHeader = True
def processDirectory(rootDir):
if needsCsvHeader:
intermediateResult = "lastCommit\ttest name\tfiledatetime\tdump comment\tcount\n"
else:
intermediateResult = ""
for dirName, subdirList, fileList in os.walk(rootDir):
files = [ fi for fi in fileList if fi.startswith("callgrind.out.") ]
for fname in files:
found = parseFile(dirName, fname)
if found != "":
intermediateResult += found
return intermediateResult
def parseFile(dirname, filename):
path = dirname + separator + filename
callgrindFile = open(path,'r')
lines = callgrindFile.readlines()
message = ""
total = ""
for line in lines:
if line.startswith(parseTrigger):
message = line[len(parseTrigger):]
elif line.startswith(parseTotal):
total = line[len(parseTotal):]
callgrindFile.close()
if message == "" and total == "0\n":
return ""
dirs = dirname.split(separator)
currentTest = dirs[-1:]
testName = currentTest[0].replace(".test.core","")
message = message.replace("\n","")
fileDate = time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(os.path.getmtime(path)))
result = lastCommitId + "\t" + testName + "\t" + fileDate + "\t" + message + "\t" + total
return result
def getLastCommitId():
stream = os.popen("git log")
line = stream.readline()
return line.replace("commit ","").replace("\n","")
def displayUsage():
print
print "Parses the callgrind results of make percheck"
print
print "Usage: bin/parse_perfcheck.py [targetFileName = perfcheckResult.csv] [sourceDirectory = ./workdir/CppunitTest]"
print "default assumes running from core root directory"
print
if __name__ == '__main__':
#check args
if len(sys.argv) < 3:
if len(sys.argv) == 2:
if sys.argv[1] == "--help":
displayUsage()
sys.exit(1)
else:
targetFileName = sys.argv[1]
sourceDirectory = "./workdir/CppunitTest"
elif len(sys.argv) == 1:
targetFileName = "perfcheckResult.csv"
sourceDirectory = "./workdir/CppunitTest"
else:
displayUsage()
sys.exit(1)
else:
targetFileName = sys.argv[1]
sourceDirectory = sys.argv[2]
# check if sourceDirectorty exists
if not os.path.isdir(sourceDirectory):
print "sourceDirectorty %s not found - Aborting" % (sourceDirectory)
sys.exit(1)
# last commit Id
lastCommitId = getLastCommitId()
# needs header in csv file ?
needsCsvHeader = not os.path.isfile(targetFileName)
# call walker
globalResult = processDirectory(sourceDirectory)
print globalResult
# write result
fileResult = open(targetFileName,'a')
fileResult.write(globalResult)
fileResult.close()
|