Announcement

Collapse
No announcement yet.

EFS Debug tool

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • EFS Debug tool

    As part of my own code development, I have put together a small efs which saves data. What I found nice about it is it can be used to trace the execution of an efs, thus the name (trace.efs).

    PHP Code:
    /************************************************
    Steve Hare © January 2004                          
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.                      
    *************************************************/
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The purpose of this efs is to record the data from an efs wherever you choose to place "trace()" .The data 
    must be within the parenthesis.  Care should be taken, as too much data can be overwhelming.  Depending
    on how your code is written, and how much branching is used, the order of the recorded information may vary.
    Therefore, use spaces and labels to assist in helping understand where the data being recorded is from. The
    recorded data is saved in the default formula output directory, change variable nStudy to match up with 
    the name of your code
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/



    var tracedata = new Array();
    var 
    tracefile "";
    var 
    nStudy "sample";
    var 
    barcount 0;
    var 
    nLastRawTime 0;

    function 
    preMain() { 
            
    tracefile = new File("Trace "+nStudy+".txt");
            
    tracefile.open("wt+");tracefile.close();//opens and overwrites previous file
    }

    function 
    main(){


        if (
    /* getValue("rawtime",0) != nLastRawTime || */ getBarState() == BARSTATE_NEWBAR) {//runs portion of code every bar     
            
    nLastRawTime getValue("rawtime",0);
            
    barcount++;

            
            
    //example usage
            
    trace(barcount);//always record barcount first
            
            
    trace(open());
            
            
    trace("close:"+close());
            
            
    trace("put text or description of code");// need to describe where in program the data is being recorded
            
            
    trace("         long buy function");// use spaces to make identification of different sections of the code
            
            
    trace("step 37");
            
            
    trace();// blanks, or null values are not recorded
            
            
    trace("save");//this saves the data accumulated as a line in the file, put right before end of main
            
            
    return;
        }
    }


    function 
    trace(data1){//routine that saves the data
        
    if(data1==null){return;}
        
    tracedata.push(data1);//adds datapoint to array
        
    if(data1 == "save"){//section saves data to a file
            
    tracedata.pop();//removes "save" from array
            
    tracefile.open("at+");tracefile.writeln(tracedata);tracefile.close();
            var 
    i;
            var 
    iend tracedata.length;
            for (
    i=0;i<=iend;i++){tracedata.pop();}//removes all data from array
        
    }

    I am currently using this to troubleshoot my own code. I typically will add trace(); on the same line as the data I am recording. Put the variable in the parenthesis.
    PHP Code:
    sto0=vMAofStoch1.getValue(MAStudy.MA);trace(sto0); 
    When no longer required, you can remove the data from between the parenthesis, as this will no longer be recorded, and is not a significant performance hit.

    I have uploaded this in my fileshare area

    trace()

    This efs is written to record all the data from the initial efs load and will continue in real time. Hopefully someone will find this useful.
    Last edited by Guest; 01-31-2004, 06:38 PM.

  • #2
    For those interested, I just finished developing some code which required extensive debugging because of my unfamiliarity with some of the methods I used. Attached is the efs that I finally got right after this debugging.

    This efs demonstrates the extensive use of the trace() function I discussed in the previous post. It is also in my fileshare area for those interested. The file generated which traces the efs steps is in the formula output directory and may be looked at with a text editor.
    Attached Files

    Comment

    Working...
    X