Changeset 859

Show
Ignore:
Timestamp:
12/11/09 16:22:31 (3 years ago)
Author:
atorf
Message:

NXCProfiler: Really great version working now :-)

Location:
branches/atorf/personal playground/NXCProfiler
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/atorf/personal playground/NXCProfiler/Analyzer/AnalyzeNXCProfile.py

    r857 r859  
    101101    out.ExecutionsSameMs = [] 
    102102    out.ElapsedTicks     = [] 
     103    out.AllSectionsTicks = 0 
    103104 
    104105    verbosePrint(" - Parsing section data") 
     
    108109            out.ExecutionCount.append(unflatten4(f.read(4))) 
    109110            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 
    111114        #end for 
    112115    except: 
     
    201204#end def 
    202205 
     206 
     207def 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 
    203234def generateCoverageLines(sourcelines, proflines, stats): 
    204235    coverage = [Consts.CODENOTPROFILED for tmp in sourcelines]; 
     
    208239        if p[1] == 'beginsection': 
    209240            # 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]])) 
    211242            if stats.ExecutionCount[p[2]] > 0: 
    212243                val = Consts.CODEPROFILED 
     
    246277 
    247278def 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)     
    249280    return str 
    250281 
    251282 
    252283 
    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('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;'); 
    266         escapedCode = escapedCode.replace('\t', '    ') 
    267         escapedCode = escapedCode.replace(' ', '&nbsp;') 
    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 
     284def escapeCodeLine(line): 
     285    out = line.rstrip().replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;'); 
     286    out = out.expandtabs(4) 
     287    out = out.replace(' ', '&nbsp;') 
     288    return out 
     289#end def 
     290 
     291 
     292def 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" 
    279298        parts.append(tmp) 
    280299    #end for 
    281  
    282     parts.append("</td></tr>") 
     300    parts.append("</td></tr>\n") 
     301    return ''.join(parts) 
     302     
     303     
     304def 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">&nbsp;<br>&nbsp;<br><b>&gt; %d ms (%.1f%%)</b><br><br>+ %d calls &lt; 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 
     323def 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>") 
    283362     
    284363    return ''.join(parts) 
     
    291370    sourcelines = readSourceFile(sourcefile) 
    292371    proflines   = findProfilerCommands(sourcelines) 
    293     coverage    = generateCoverageLines(sourcelines, proflines, stats) 
     372    sections    = getSectionsFromProfilerCmds(proflines) 
     373    #coverage    = generateCoverageLines(sourcelines, proflines, stats) 
     374     
    294375     
    295376    verbosePrint(" - Generating HTML output file") 
     
    298379    HTMLparts.append(generateHTMLFileSummary(sourcefile, statsfile, stats)) 
    299380    HTMLparts.append(generateHTMLRuntimeSummary(stats)) 
    300     HTMLparts.append(generateHTMLCodeTable(sourcelines, proflines, stats, coverage)) 
     381    HTMLparts.append(generateHTMLCodeTable(sourcelines, proflines, stats, sections)) 
    301382    HTMLparts.append(HTMLSnippets.getHTMLFooter()) 
    302383     
  • branches/atorf/personal playground/NXCProfiler/Analyzer/HTMLSnippets.py

    r858 r859  
    2020        <style type="text/css"> 
    2121            body { font-family:'Verdana'; } 
    22             code { font-size:10pt; } 
     22            code { font-size:11pt; } 
    2323             
    2424            span { font-size:10pt; font-family:'Courier New' } 
     25            .codestandard { color:#000000; } 
    2526            .codedidntrun { color:#A0A020; } 
    2627            .codenotprofiled { color:#000000; } 
     
    3637            .greenth { background-color:#A9D668} 
    3738            .orangeth { background-color:#FDB75D} 
    38             td { font-size:11pt; } 
     39            td { font-size:10pt; } 
    3940            .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 } 
    4245            .codenotprofiledtd { background-color:#EFEFEF} 
    4346             
     
    6265 
    6366def getHTMLFileInfo(): 
    64     return '''<table border="0" cellpadding="20" cellspacing="8" width="750"> 
     67    return '''<table border="0" cellpadding="20" cellspacing="8" align="center"> 
    6568        <tr> 
    66             <th class="summaryth">File summary</th> 
     69            <th class="summaryth" align="center">File summary</th> 
    6770        </tr> 
    6871        <tr> 
     
    8285    return ''' 
    8386        <tr> 
    84             <th class="summaryth">Runtime summary</th> 
     87            <th class="summaryth" align="center">Runtime summary</th> 
    8588        </tr> 
    8689        <tr> 
    8790            <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> 
    9295            </td> 
    9396        </tr> 
     
    98101 
    99102def getHTMLCodeStart(): 
    100     return '''<table border="0" cellpadding="20" cellspacing="8" width="750"> 
     103    return '''<table border="0" cellpadding="12" cellspacing="8" align="center"> 
    101104        <tr> 
    102             <th class="codeth">Profiled source code</th> 
     105            <th class="codeth" colspan="3" align="center">Profiled source code</th> 
    103106        </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> 
    106112             
    107113        ''' 
  • branches/atorf/personal playground/NXCProfiler/Profiler01.nxc

    r855 r859  
    111111         
    112112        // record elapsed time (if possible) 
    113         if (CurrentTick() != __PROFILER_LastTick[no]) { 
     113        if (CurrentTick() == __PROFILER_LastTick[no]) { 
    114114            // count the number of times where no tick has happened 
    115115            __PROFILER_ExecutionsSameMs[no] = __PROFILER_ExecutionsSameMs[no] + 1;