Changeset 857
- Timestamp:
- 12/11/09 05:47:53 (4 years ago)
- Location:
- branches/atorf/personal playground/NXCProfiler/Analyzer
- Files:
-
- 3 modified
-
AnalyzeNXCProfile.py (modified) (7 diffs)
-
HTMLSnippets.py (modified) (3 diffs)
-
sample.nxc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/atorf/personal playground/NXCProfiler/Analyzer/AnalyzeNXCProfile.py
r856 r857 41 41 Vars.verbose = False 42 42 43 44 Consts.CODENOTPROFILED = 0 45 Consts.CODEDIDNTRUN = 1 46 Consts.CODEPROFILED = 2 43 47 44 48 verbosePrint = None # this is gonne be a method! … … 136 140 #def 137 141 142 def writeStringToFile(filename, str): 143 try: 144 f = file(filename, "w") 145 f.write(str) 146 except (IOError, OSError): 147 print "Could not open output file for writing or write to it" 148 f.close() 149 sys.exit(1) 150 #end try 151 152 f.close() 153 #end def 138 154 139 155 … … 159 175 elif tmp.startswith("PROFILER_ENDSECTION"): 160 176 val = int(tmp.partition("(")[2].partition(")")[0]) 161 out.append((i, " beginsection", val))177 out.append((i, "endsection", val)) 162 178 verbosePrint(' . found "endsection(%d)" in line %d' % (val, i)) 163 179 #end if … … 169 185 #end def 170 186 187 def findProfilerCommandLine(lines, cmd): 188 lineno = -1 189 for p in lines: 190 if p[1] == cmd: 191 lineno = p[0] 192 break 193 #end if 194 #end if 195 if lineno == -1: 196 print "Profiler command %s not found in source file." % cmd 197 sys.exit(1) 198 #end if 199 200 return lineno 201 #end def 202 203 def generateCoverageLines(sourcelines, proflines, stats): 204 coverage = [Consts.CODENOTPROFILED for tmp in sourcelines]; 205 # for all profiler commands 206 for (i, p) in enumerate(proflines): 207 # look for profiled sections 208 if p[1] == 'beginsection': 209 # find out if code was executed 210 verbosePrint(' . checking section %s, ExecutionCount = %d' % (p[2], stats.ExecutionCount[p[2]])) 211 if stats.ExecutionCount[p[2]] > 0: 212 val = Consts.CODEPROFILED 213 else: 214 val = Consts.CODEDIDNTRUN 215 #end if 216 217 #NOTE BAD 218 endline = -1 219 for nextp in proflines: 220 if nextp[1] == 'endsection': 221 if nextp[2] == p[2]: 222 endline = nextp[0] 223 break 224 if endline == -1: 225 print "Warning: Didn't find matching profiler command endsection for a certain startsection!" 226 227 #end if 228 # set all lines to the end... 229 for j in range(p[0], endline+1): 230 coverage[j] = val 231 #end for 232 #end if 233 return coverage 171 234 172 235 def generateHTMLHeader(sourcefile): … … 188 251 189 252 190 def writeStringToFile(filename, str): 191 try: 192 f = file(filename, "w") 193 f.write(str) 194 except (IOError, OSError): 195 print "Could not open output file for writing or write to it" 196 f.close() 197 sys.exit(1) 198 #end try 199 200 f.close() 201 #end def 253 254 255 def generateHTMLCodeTable(sourcelines, proflines, stats, coverage): 256 parts = []; 257 258 startline = findProfilerCommandLine(proflines, "start") 259 stopline = findProfilerCommandLine(proflines, "stop") 260 261 262 parts.append(HTMLSnippets.getHTMLCodeStart()) 263 264 for (i, line) in enumerate(sourcelines): 265 escapedCode = line.rstrip().replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"'); 266 escapedCode = escapedCode.replace('\t', ' ') 267 escapedCode = escapedCode.replace(' ', ' ') 268 if i == startline or i == stopline: 269 tmp = '<span class="profilercmd">' + escapedCode + "</span><br>\n" 270 else: 271 if coverage[i] == Consts.CODENOTPROFILED: 272 tmp = '<span class="codenotprofiled">' + escapedCode + "</span><br>\n" 273 elif coverage[i] == Consts.CODEDIDNTRUN: 274 tmp = '<span class="codedidntrun">' + escapedCode + "</span><br>\n" 275 else: 276 tmp = '<span class="codeprofiled">' + escapedCode + "</span><br>\n" 277 #end if 278 #end if 279 parts.append(tmp) 280 #end for 281 282 parts.append("</td></tr>") 283 284 return ''.join(parts) 202 285 203 286 … … 206 289 def doTheAnalysis(statsfile, sourcefile, outfile): 207 290 stats = parseProfileFile(statsfile) 208 sourceLines = readSourceFile(sourcefile) 209 proflines = findProfilerCommands(sourceLines) 291 sourcelines = readSourceFile(sourcefile) 292 proflines = findProfilerCommands(sourcelines) 293 coverage = generateCoverageLines(sourcelines, proflines, stats) 210 294 211 295 verbosePrint(" - Generating HTML output file") … … 214 298 HTMLparts.append(generateHTMLFileSummary(sourcefile, statsfile, stats)) 215 299 HTMLparts.append(generateHTMLRuntimeSummary(stats)) 300 HTMLparts.append(generateHTMLCodeTable(sourcelines, proflines, stats, coverage)) 216 301 HTMLparts.append(HTMLSnippets.getHTMLFooter()) 217 302 218 303 219 304 writeStringToFile(outfile, ''.join(HTMLparts)) 220 verbosePrint("%s written." % outfile) 305 verbosePrint(" - %s written." % outfile) 306 221 307 222 308 #end def -
branches/atorf/personal playground/NXCProfiler/Analyzer/HTMLSnippets.py
r856 r857 20 20 <style type="text/css"> 21 21 body { font-family:'Verdana'; } 22 th { font-size:14pt; font-style:bold; } 22 code { font-size:10pt; } 23 24 span { font-size:10pt; font-family:'Courier New' } 25 .codedidntrun { color:#A0A020; } 26 .codenotprofiled { color:#000000; } 27 .codeprofiled { color:#000060; } 28 .profilercmd { font-weight:bolder; color:#500000; } 29 .comment { color:#A9D668; } 30 31 th { font-size:12pt; font-weight:bold; } 23 32 .summaryth { background-color:#A9D668} 24 33 .codeth { background-color:#7DA2D1} … … 29 38 td { font-size:11pt; } 30 39 .summarytd { background-color:#DEFFBD} 31 .codedidntruntd { background-color:# CBDDFF}32 .codeprofiledtd { background-color:# CBDDFF}33 .codenotprofiledtd { background-color:# CBDDFF}40 .codedidntruntd { background-color:#EFEFEF} 41 .codeprofiledtd { background-color:#EFEFEF} 42 .codenotprofiledtd { background-color:#EFEFEF} 34 43 35 44 .standardtd { background-color:#CBDDFF} … … 78 87 <td class="summarytd"> 79 88 <ul> 80 <li><code>Total program runtime: %### .2f seconds</code>81 <li><code>Profiled part runtime: %### .2f seconds</code>89 <li><code>Total program runtime: %###0.2f seconds</code> 90 <li><code>Profiled part runtime: %###0.2f seconds</code> 82 91 </ul> 83 92 </td> 84 93 </tr> 94 </table> 85 95 ''' 86 96 #end def 97 98 99 def getHTMLCodeStart(): 100 return '''<table border="0" cellpadding="20" cellspacing="8" width="750"> 101 <tr> 102 <th class="codeth">Profiled source code</th> 103 </tr> 104 <tr> 105 <td class="codenotprofiledtd"> 106 107 ''' -
branches/atorf/personal playground/NXCProfiler/Analyzer/sample.nxc
r855 r857 217 217 218 218 // --- Done 219 219 220 /* DIRTY DIRTY HACK TEST 221 this code was not profiled 222 this is a quick hack... bad bad... 223 PROFILER_BEGINSECTION(6); 224 // something 225 // something 226 // this should never ever be executed 227 // different color highlighting? 228 PROFILER_ENDSECTION(6); 229 */ 220 230 221 231 }//end task
