Skip to content

Latest commit

 

History

History
181 lines (149 loc) · 4.44 KB

CETx-2023.md

File metadata and controls

181 lines (149 loc) · 4.44 KB

Local Closure

Comment the functions you don't need so you can see them in action individually.

/***********************************************************************
 * Local Closure
 ***********************************************************************/
{
     runPlns();
     runTracers();

     inspect(anyFrameWindow);

     simplePtime();
     ptimeWithThreshold();

     runProbesCallRoot();

     runProfilerCallsRoot();
}

Helper functions

Functions that are used in this file.

/***********************************************************************
 * Helpers
 ***********************************************************************/
private void chainedCallChild0() { chainedCallChild1(); }
private void chainedCallChild1() { chainedCallChild2(); }
private void chainedCallChild2() { sleep(10); pln("Child 2"); }

private void runTracers() { 
     runCfd();
     runCfd(secondParam="Say what?");
     runCfd(firstParam=123);

     runSsd();

     runSd();

     usd(id=myUsdCallKey, reset=true);
     for (i in 1..10) aa3();

     runSt();
}

Print

All the different ways you can pln things in CET.

/***********************************************************************
 * Print.
 ***********************************************************************/

private void runPlns() { 
    str data = "CETx 2023";

    /// Simple Print empty Line
    pln();

    /// Print Line with String
    pln("Hello World!");

    /// Print Line with variable's value
    pln("Hey ", data, " is cool!");

    /// Print Line with variable's name AND value
    pln("Hey ", #data, " is cool!");

    /// Use ";" for auto-spacing
    pln("Hey"; #data; "is cool!");
}

Tracers

Different ways to explore the Stack in CET.

/***********************************************************************
 * Tracers.
 ***********************************************************************/
private const str myUsdCallKey = "usdCallKey";
private void runCfd(int firstParam=15, str secondParam="Hello World!") { 
    /// Call Frame Dump / Compact Function Dump
    /// From: \base\cm\basic\debug.cm
    cfd();
}

private void runSsd() { 
    /// Print call stack short dump. Does not expand frames. Use stackDump() for expanded frames.
    /// From: \base\cm\lang\debug.cm
    ssd();
}

private void runSd() { 
    /// Print call stack dump which is equivalent with a call stack trace plus expanded frames.
    /// From: \base\cm\lang\debug.cm
    sd();
}

private void runSt() {
    /// Stack Trace
    /// From: \base\cm\runtime\usd.cm
    st();
}

private void runUsd() {
    /// Unique filtered short stack dump
    ///  - This will only PRINT once per id/session.
    /// From: \base\cm\runtime\usd.cm
    usd(id=myUsdCallKey, n=4, levels=2);
}
private void aa() { runUsd(); }
private void aa1() { aa(); }
private void aa2() { aa1(); }
private void aa3() { aa2(); }

Performance Tracers

Ways for you to keep your code in check and avoid performance issues.

/***********************************************************************
 * Performance Tracers.
 ***********************************************************************/
private void simplePtime() { 
    /// Print Time it took to run a block of code
    /// From: \basic\basic.syntax.cm
    ptime("Check this out") { 
        sleep(1000);
    }
}

private void ptimeWithThreshold() {
    /// Print Time it took to run a block of code
    /// From: \basic\basic.syntax.cm
    ptime("Check this out", warning=1.6s) { 
        sleep(1600);
    }
}

Probes

Yet another way to help you find issues in your code.

/***********************************************************************
 * Probes
 ***********************************************************************/
private void runProbesCallRoot() {
    use cm.track.probe;
    initProbe("CET X Probe");
    for (i in 1..10) {
        startProbe(spnn("Probe for ", i));
        chainedCallChild0();
        stopProbe(spnn("Probe for ", i));
    }
    probeReport();
}

Profiler

Arguably, this is the easiest way to troubleshoot issues in CET's code.

/***********************************************************************
 * Profiler
 ***********************************************************************/
private void runProfilerCallsRoot() {
    /// From \base\cm\core\debug\profiler.cm

    /// use cm.core.debug;
    profilerStart();
    for (i in 1..10) {
        chainedCallChild0();
    }
    profilerStop();
    profilerReport();
}