Changeset 864

Show
Ignore:
Timestamp:
12/13/09 16:59:59 (3 years ago)
Author:
atorf
Message:

NXCProfiler:

  • More debug infos in Analyzer
  • Tried to profile MotorControl, first results seem uncool (problem with analyzing to small chunks of code, problem if firmware "ticks" during a fast executing function (and profiler "thinks" it took a while))
Location:
branches/atorf/personal playground/NXCProfiler
Files:
4 added
5 modified
1 copied

Legend:

Unmodified
Added
Removed
  • branches/atorf/personal playground/NXCProfiler/Analyzer

    • Property svn:ignore set to
      *.html
  • branches/atorf/personal playground/NXCProfiler/Analyzer/AnalyzeNXCProfile.py

    r862 r864  
    7474        f = file(filename, "rb") 
    7575    except (IOError, OSError): 
    76         print "Could not find or open input file" 
     76        print "Could not find or open input file %s" % filename 
    7777        sys.exit(1) 
    7878    #end try 
     
    112112            out.ElapsedTicks.append(tmpTicks) 
    113113            out.AllSectionsTicks += tmpTicks 
     114            verbosePrint("     Executed=%d, Elapsed=%d, SameMs=%d" % (out.ExecutionCount[-1], out.ElapsedTicks[-1], out.ExecutionsSameMs[-1])) 
    114115        #end for 
    115116    except: 
     
    131132        lines = f.readlines() 
    132133    except (IOError, OSError): 
    133         print "Could not find, open or read input file" 
     134        print "Could not find, open or read input file %s" % filename 
    134135        f.close() 
    135136        sys.exit(1) 
  • branches/atorf/personal playground/NXCProfiler/profiled MotorControl

    • Property svn:ignore set to
      *.bak
      AnalyzeNXCProfile.py
      HTMLSnippets.py
      *.html
  • branches/atorf/personal playground/NXCProfiler/profiled MotorControl/ControllerCore.nxc

    r863 r864  
    7777*/ 
    7878 
     79    PROFILER_BEGINSECTION(15); 
    7980 
    8081    //much simpler approach now... 
     
    104105                Wait(300); 
    105106            #endif 
     107            PROFILER_ENDSECTION(15); 
    106108            return true; 
    107109        }//end if 
     
    110112 
    111113        if (CurrentTick() >= timeoutTick) { 
     114            PROFILER_ENDSECTION(15); 
    112115            break; 
    113116        }//end if 
    114117    }//end while 
    115118 
     119    PROFILER_ENDSECTION(15); 
    116120    return false; 
    117121 
     
    210214// - Absolute acceleration power during rampup (in discrete steps like 10, 20, etc) 
    211215 
    212  
     216    PROFILER_BEGINSECTION(16); 
    213217// --- Some DECLARATIONS -- not all of them, this is timecritical 
    214218    long i; 
     
    266270    #endif 
    267271 
    268  
     272    PROFILER_ENDSECTION(16); 
     273    PROFILER_BEGINSECTION(17); 
     274     
    269275// --- Declare and Initialize various variables 
    270276//     * STAGE is RAMPUP 
     
    360366#endif 
    361367 
     368    PROFILER_ENDSECTION(17); 
     369 
    362370// --- MAIN LOOP --------------------- 
    363371    while(true) { 
    364372     
     373        PROFILER_BEGINSECTION(18); 
    365374//    * record time 
    366375        loopStartTick = CurrentTick(); 
     
    412421        if (SpeedLogIndex > SPEEDHISTORY-1) SpeedLogIndex = 0; 
    413422 
     423        PROFILER_ENDSECTION(18); 
     424         
    414425 
    415426//    * if RAMPUP STAGE: 
     
    425436            if (smoothstart) { 
    426437             
     438                PROFILER_BEGINSECTION(19); 
    427439                rampupLoopCount++; 
    428440                // when rampup is done 
     
    466478                }//end if 
    467479                 
     480                PROFILER_ENDSECTION(19); 
     481                 
    468482            } else { // no rampup 
    469483             
     484                PROFILER_BEGINSECTION(20); 
    470485                // full power right away 
    471486                if (speedreg) { 
     
    481496 
    482497                curStage = STAGE_DRIVING; 
     498 
     499                PROFILER_ENDSECTION(20); 
    483500                 
    484501            }//end if 
     
    496513        //optimized, OLD: if ((curStage == STAGE_DRIVING) || (curStage == STAGE_RAMPUP)) { 
    497514        if (curStage <= STAGE_DRIVING) { 
     515         
     516            PROFILER_BEGINSECTION(21); 
     517 
    498518            #ifdef ENABLEDEBUGGING_LCD_SLOW_ANTIBUG 
    499519                if (curStage == STAGE_DRIVING) { 
     
    554574            }//end if 
    555575             
    556  
     576            PROFILER_ENDSECTION(21); 
    557577 
    558578        }//end if 
     
    567587//        . clip power and set 
    568588        if (curStage == STAGE_BRAKING) { 
     589         
     590            PROFILER_BEGINSECTION(22); 
     591         
    569592            #ifdef ENABLEDEBUGGING_LCD_SLOW_ANTIBUG 
    570593                TextOut(0, DebugLinePos[port], "BRAKING:top        "); 
     
    580603                }//end if 
    581604            #endif// - - - - - - - - - - 
    582  
    583605 
    584606            // TODO maybe replace this variable (dont use it) and do it inline? 
     
    671693            #endif// - - - - - - - - - - 
    672694             
     695            PROFILER_ENDSECTION(22); 
     696             
    673697        }//end if 
    674698 
     
    682706        #endif 
    683707 
     708        PROFILER_BEGINSECTION(23); 
    684709        waitEndTick = loopStartTick + LOOP_DURATION; //precalc loop-end 
    685710        while (CurrentTick() < waitEndTick) { 
     
    733758 
    734759        }//end while (times out when static worst case looptime is over (~10 to 20ms) 
     760        PROFILER_ENDSECTION(23); 
    735761 
    736762        #ifdef ENABLEDEBUGGING_LCD_SLOW_ANTIBUG 
     
    756782            #endif 
    757783 
    758  
     784            PROFILER_BEGINSECTION(24); 
    759785            // fast inner loop now! 
    760786            // don't forget TIMEOUT or something, avoid possible lock up, 
     
    820846            #endif 
    821847 
     848            PROFILER_ENDSECTION(24); 
     849 
    822850            //now there's a little time for debug... 
    823851            #ifdef ENABLEDEBUGGING_ACOUSTIC 
     
    872900    #endif 
    873901 
     902    PROFILER_BEGINSECTION(25); 
    874903    bool stoppedByDirectCmd = false; 
    875904    stoppedByDirectCmd = _ADD_MOTORNAME(WaitUntilMotorStopped)(port); 
     905    PROFILER_ENDSECTION(25); 
    876906 
    877907 
  • branches/atorf/personal playground/NXCProfiler/profiled MotorControl/MotorControl21.nxc

    r863 r864  
    3131 
    3232 
     33 
     34// SET UP THE PROFILER 
     35// comment this out to silently disable profiling without any side effects! 
     36#define PROFILER_ENABLE 
     37// how many times did we use PROFILER_BEGINSECTION (and ENDSECTION) 
     38#define PROFILER_MAXSECTIONS 27 
     39// name of the binary results file we later analyze 
     40#define PROFILER_RESULTSFILE "MotorControl21.prf" 
     41// this does all the magic :-) 
     42#include "Profiler01.nxc" 
     43 
     44 
     45 
    3346// *************** GLOBAL DEFINES 
    3447// important to be before includes, 
     
    478491task main(){ 
    479492 
     493    PROFILER_START(); 
     494    PROFILER_BEGINSECTION(0); 
     495     
    480496    // parameter initialization 
    481497    string in = ""; 
     
    508524    taskCrunning = false; 
    509525 
    510  
     526    PROFILER_ENDSECTION(0); 
     527    PROFILER_BEGINSECTION(1); 
    511528    DisplayMainScreen(); 
    512529    //Wait(9000); 
    513  
     530    PROFILER_ENDSECTION(1); 
     531     
     532    PROFILER_BEGINSECTION(2); 
    514533    // don't forget this 
    515534    InitSpeedFromPosLUT(); 
    516  
    517  
     535    PROFILER_ENDSECTION(2); 
     536     
     537     
     538    PROFILER_BEGINSECTION(3); 
    518539    // purge mailboxes to make sure, in case something is left over, 
    519540    // I don't know... 
     
    540561    #endif 
    541562 
     563    PROFILER_ENDSECTION(3); 
     564 
    542565    while(true){ 
    543566 
     567        PROFILER_BEGINSECTION(4); 
    544568        ReceiveRemoteString(INBOX, true, in); 
     569        PROFILER_ENDSECTION(4); 
    545570 
    546571        if(StrLen(in) > 0) { 
     
    554579            #endif 
    555580 
    556  
     581            PROFILER_BEGINSECTION(5); 
    557582            // take first value, decide what to do... 
    558583            tmp        = SubStr(in,  0, 1);  // pos 0 
    559584            packetType = StrToNum(tmp); 
     585            PROFILER_ENDSECTION(5); 
    560586 
    561587            // main packet handler! 
     
    563589            case PROTO_CONTROLLED_MOTORCMD: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    564590             
     591                PROFILER_BEGINSECTION(6); 
    565592                // parse... 
    566593                tmp      = SubStr(in,  1, 1);  // pos 1 
     
    575602                tmp      = SubStr(in,  11, 1); // pos 11 
    576603                modebits = StrToNum(tmp); 
     604                PROFILER_ENDSECTION(6); 
    577605                 
    578  
     606                PROFILER_BEGINSECTION(7); 
    579607                // process... 
    580608                // power 
     
    601629                    smoothstart = false; 
    602630                }//end if 
     631                PROFILER_ENDSECTION(7); 
    603632 
    604633 
     
    606635                if (port == 0) { // OUT_A 
    607636 
     637                    PROFILER_BEGINSECTION(8); 
    608638                    motorParamsA.power = power; 
    609639                    motorParamsA.tacholimit = angle; 
     
    617647                        TaskBusySignal(); 
    618648                    } // end if 
     649                    PROFILER_ENDSECTION(8); 
    619650 
    620651                } else if (port == 1) { // OUT_B 
     
    700731                break; 
    701732            case PROTO_ISMOTORREADY:  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    702              
     733 
     734                PROFILER_BEGINSECTION(9); 
    703735                tmp      = SubStr(in,  1, 1);  // pos 1 
    704736                port     = StrToNum(tmp); 
     737                PROFILER_ENDSECTION(9); 
    705738                 
     739                PROFILER_BEGINSECTION(10); 
    706740                // send answer string: portnum, then if ready or not 
    707741                if (IsMotorReady(port)) { 
     
    710744                    tmp = StrCat(tmp, "0"); 
    711745                }//end if 
     746                PROFILER_ENDSECTION(10); 
     747                 
     748                PROFILER_BEGINSECTION(11); 
    712749                SendMessage(OUTBOX, tmp); 
     750                PROFILER_ENDSECTION(11); 
     751                 
    713752                 
    714753                break; 
    715754            case PROTO_CLASSIC_MOTORCMD: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    716755             
     756                PROFILER_BEGINSECTION(12); 
    717757                // parse... 
    718758                tmp      = SubStr(in,  1, 1);  // pos 1 
     
    742782                //% OUT_BC      0x05 
    743783                //% OUT_ABC     0x06 
     784                PROFILER_ENDSECTION(12); 
     785 
    744786 
    745787                if (port <= 2) { 
     
    773815                    }//end switch 
    774816 
    775  
     817                    PROFILER_BEGINSECTION(13); 
    776818                    // if no current tacholimit and no new one, allow speed change 
    777819                    if ((MotorTachoLimit(port1) == 0) && (MotorTachoLimit(port2) == 0)  && (angle == 0)) { 
     
    805847                         
    806848                    }//end if 
    807  
     849                    PROFILER_ENDSECTION(13); 
    808850                }//end if 
    809851             
     
    832874            MotorOff(OUT_B); 
    833875            MotorOff(OUT_C); 
     876             
     877            PROFILER_STOP(); 
    834878             
    835879            TextOut(5,LCD_LINE7, "EMERGENCY STOP    ", false);