Changeset 859
- Timestamp:
- 12/11/09 16:22:31 (3 years ago)
- Location:
- branches/atorf/personal playground/NXCProfiler
- Files:
-
- 4 modified
-
Analyzer/AnalyzeNXCProfile.py (modified) (7 diffs)
-
Analyzer/HTMLSnippets.py (modified) (5 diffs)
-
Analyzer/sample.prf (modified) (previous)
-
Profiler01.nxc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/atorf/personal playground/NXCProfiler/Analyzer/AnalyzeNXCProfile.py
r857 r859 101 101 out.ExecutionsSameMs = [] 102 102 out.ElapsedTicks = [] 103 out.AllSectionsTicks = 0 103 104 104 105 verbosePrint(" - Parsing section data") … … 108 109 out.ExecutionCount.append(unflatten4(f.read(4))) 109 110 out.ExecutionsSameMs.append(unflatten4(f.read(4))) 110 out.ElapsedTicks.append(unflatten4(f.read(4))) 111 tmpTicks = unflatten4(f.read(4)) 112 out.ElapsedTicks.append(tmpTicks) 113 out.AllSectionsTicks += tmpTicks 111 114 #end for 112 115 except: … … 201 204 #end def 202 205 206 207 def getSectionsFromProfilerCmds(proflines): 208 sections = [] 209 for (i, p) in enumerate(proflines): 210 startline = -1 211 endline = -1 212 # look for profiled sections 213 if p[1] == 'beginsection': 214 section = p[2] 215 startline = p[0] 216 for nextp in proflines: 217 if nextp[1] == 'endsection': 218 if nextp[2] == section: 219 endline = nextp[0] 220 break 221 #end if 222 #end if 223 #end for 224 if endline == -1: 225 print "Warning: Didn't find matching profiler command endsection for a certain startsection!" 226 #end if 227 sections.append((section, startline, endline)) 228 #end if 229 #end for 230 return sections 231 232 #end def 233 203 234 def generateCoverageLines(sourcelines, proflines, stats): 204 235 coverage = [Consts.CODENOTPROFILED for tmp in sourcelines]; … … 208 239 if p[1] == 'beginsection': 209 240 # find out if code was executed 210 verbosePrint(' . checking section % s, ExecutionCount = %d' % (p[2], stats.ExecutionCount[p[2]]))241 verbosePrint(' . checking section %d (ExecCnt = %d, ElapsTcks = %d, ExecsSameMs = %d)' % (p[2], stats.ExecutionCount[p[2]], stats.ElapsedTicks[p[2]], stats.ExecutionsSameMs[p[2]])) 211 242 if stats.ExecutionCount[p[2]] > 0: 212 243 val = Consts.CODEPROFILED … … 246 277 247 278 def generateHTMLRuntimeSummary(stats): 248 str = HTMLSnippets.getHTMLRuntimeStats() % (stats.TotalRunTime/1000.0, stats.ProfiledRunTime/1000.0 )279 str = HTMLSnippets.getHTMLRuntimeStats() % (stats.TotalRunTime/1000.0, stats.ProfiledRunTime/1000.0, stats.AllSectionsTicks/1000.0) 249 280 return str 250 281 251 282 252 283 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 284 def escapeCodeLine(line): 285 out = line.rstrip().replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"'); 286 out = out.expandtabs(4) 287 out = out.replace(' ', ' ') 288 return out 289 #end def 290 291 292 def getUnprofiledCodeTablePart(sourcelines, start, end): 293 parts = [] 294 parts.append('<tr><td class="codenotprofiledtd" colspan="2" align="center"><i>Not profiled</i></td><td class="codestandardtd">') 295 for line in sourcelines[start:end+1]: 296 escapedCode = escapeCodeLine(line) 297 tmp = '<span class="codenotprofiled">' + escapedCode + "</span><br>\n" 279 298 parts.append(tmp) 280 299 #end for 281 282 parts.append("</td></tr>") 300 parts.append("</td></tr>\n") 301 return ''.join(parts) 302 303 304 def getProfiledCodeTablePart(sourcelines, sectionNo, stats, start, end): 305 parts = [] 306 if stats.ExecutionCount[sectionNo] > 0: 307 parts.append('<tr><td class="codeprofiledcallstd" align="right"><b>%d</b></td>' % stats.ExecutionCount[sectionNo]) 308 parts.append('<td class="codeprofiledtimetd"> <br> <br><b>> %d ms (%.1f%%)</b><br><br>+ %d calls < 1ms</td>' % (stats.ElapsedTicks[sectionNo], stats.ElapsedTicks[sectionNo]/stats.ProfiledRunTime*100, stats.ExecutionsSameMs[sectionNo])) 309 else: 310 parts.append('<tr><td class="codedidntruntd" colspan="2" align="center"><b>Never executed</b></td>') 311 #end if 312 parts.append('<td class="codestandardtd">') 313 314 for line in sourcelines[start:end+1]: 315 escapedCode = escapeCodeLine(line) 316 tmp = '<span class="codestandard">' + escapedCode + "</span><br>\n" 317 parts.append(tmp) 318 #end for 319 parts.append("</td></tr>\n") 320 return ''.join(parts) 321 322 323 def generateHTMLCodeTable(sourcelines, proflines, stats, sections): 324 parts = []; 325 326 #startline = findProfilerCommandLine(proflines, "start") 327 #stopline = findProfilerCommandLine(proflines, "stop") 328 329 330 parts.append(HTMLSnippets.getHTMLCodeStart()) 331 332 curLine = 0 333 for (sectionNo, start, end) in sections: 334 # if we have non-profiled code: 335 if curLine < start: 336 # "pad" with plain stuff 337 parts.append(getUnprofiledCodeTablePart(sourcelines, curLine, start-1)) 338 #end if 339 parts.append(getProfiledCodeTablePart(sourcelines, sectionNo, stats, start, end)) 340 curLine = end + 1 341 #end for 342 343 # "pad" with plain stuff 344 parts.append(getUnprofiledCodeTablePart(sourcelines, curLine, len(sourcelines)-1)) 345 346 347 # # old shit 348 # for line in sourcelines[0:sections[0][1]]: 349 # escapedCode = escapeCodeLine(line) 350 # tmp = '<span class="codenotprofiled">' + escapedCode + "</span><br>\n" 351 # parts.append(tmp) 352 # #end for 353 # parts.append("</td></tr>\n") 354 # 355 # 356 # elif coverage[i] == Consts.CODEDIDNTRUN: 357 # tmp = '<span class="codedidntrun">' + escapedCode + "</span><br>\n" 358 # else: 359 # tmp = '<span class="codeprofiled">' + escapedCode + "</span><br>\n" 360 # 361 # parts.append("</td></tr>") 283 362 284 363 return ''.join(parts) … … 291 370 sourcelines = readSourceFile(sourcefile) 292 371 proflines = findProfilerCommands(sourcelines) 293 coverage = generateCoverageLines(sourcelines, proflines, stats) 372 sections = getSectionsFromProfilerCmds(proflines) 373 #coverage = generateCoverageLines(sourcelines, proflines, stats) 374 294 375 295 376 verbosePrint(" - Generating HTML output file") … … 298 379 HTMLparts.append(generateHTMLFileSummary(sourcefile, statsfile, stats)) 299 380 HTMLparts.append(generateHTMLRuntimeSummary(stats)) 300 HTMLparts.append(generateHTMLCodeTable(sourcelines, proflines, stats, coverage))381 HTMLparts.append(generateHTMLCodeTable(sourcelines, proflines, stats, sections)) 301 382 HTMLparts.append(HTMLSnippets.getHTMLFooter()) 302 383 -
branches/atorf/personal playground/NXCProfiler/Analyzer/HTMLSnippets.py
r858 r859 20 20 <style type="text/css"> 21 21 body { font-family:'Verdana'; } 22 code { font-size:1 0pt; }22 code { font-size:11pt; } 23 23 24 24 span { font-size:10pt; font-family:'Courier New' } 25 .codestandard { color:#000000; } 25 26 .codedidntrun { color:#A0A020; } 26 27 .codenotprofiled { color:#000000; } … … 36 37 .greenth { background-color:#A9D668} 37 38 .orangeth { background-color:#FDB75D} 38 td { font-size:1 1pt; }39 td { font-size:10pt; } 39 40 .summarytd { background-color:#DEFFBD} 40 .codedidntruntd { background-color:#EFEFEF} 41 .codeprofiledtd { background-color:#EFEFEF} 41 .codestandardtd { background-color:#EFEFEF } 42 .codedidntruntd { background-color:#FFD791 } 43 .codeprofiledcallstd { background-color:#CBDDFF } 44 .codeprofiledtimetd { background-color:#CBDDFF } 42 45 .codenotprofiledtd { background-color:#EFEFEF} 43 46 … … 62 65 63 66 def getHTMLFileInfo(): 64 return '''<table border="0" cellpadding="20" cellspacing="8" width="750">67 return '''<table border="0" cellpadding="20" cellspacing="8" align="center"> 65 68 <tr> 66 <th class="summaryth" >File summary</th>69 <th class="summaryth" align="center">File summary</th> 67 70 </tr> 68 71 <tr> … … 82 85 return ''' 83 86 <tr> 84 <th class="summaryth" >Runtime summary</th>87 <th class="summaryth" align="center">Runtime summary</th> 85 88 </tr> 86 89 <tr> 87 90 <td class="summarytd"> 88 < ul>89 <li><code>Total program runtime: %###0.2f seconds</code>90 <li><code>Profiled part runtime: %###0.2f seconds</code>91 </ul>91 <pre> 92 - Total program runtime (until STOP): %7.2f seconds 93 - Profiler runtime (between START and STOP): %7.2f seconds 94 - Sections runtime (sum of all sections > 1ms): %7.2f seconds</pre> 92 95 </td> 93 96 </tr> … … 98 101 99 102 def getHTMLCodeStart(): 100 return '''<table border="0" cellpadding=" 20" cellspacing="8" width="750">103 return '''<table border="0" cellpadding="12" cellspacing="8" align="center"> 101 104 <tr> 102 <th class="codeth" >Profiled source code</th>105 <th class="codeth" colspan="3" align="center">Profiled source code</th> 103 106 </tr> 104 <tr> 105 <td class="codenotprofiledtd"> 107 <tr> 108 <td class="standardtd" align="center"><b>Calls</b></th> 109 <td class="standardtd" align="center"><b>Time</b></th> 110 <td class="standardtd" align="center"><b>Code</b></th> 111 </tr> 106 112 107 113 ''' -
branches/atorf/personal playground/NXCProfiler/Profiler01.nxc
r855 r859 111 111 112 112 // record elapsed time (if possible) 113 if (CurrentTick() != __PROFILER_LastTick[no]) {113 if (CurrentTick() == __PROFILER_LastTick[no]) { 114 114 // count the number of times where no tick has happened 115 115 __PROFILER_ExecutionsSameMs[no] = __PROFILER_ExecutionsSameMs[no] + 1;

