package org.javarosa.core.model.utils;

import org.javarosa.core.model.trace.EvaluationTrace;
import org.javarosa.core.model.trace.EvaluationTraceReporter;
import org.javarosa.core.model.trace.StringEvaluationTraceSerializer;

/**
 * Utility functions for instrumentation in the engine
 *
 * Created by ctsims on 7/6/2017.
 */

public class InstrumentationUtils {

    /**
     * Prints out traces (if any exist) from the provided reporter with a description into sysout
     */
    public static void printAndClearTraces(EvaluationTraceReporter reporter, String description) {
        if (reporter != null) {
            if (reporter.wereTracesReported()) {
                System.out.println(description);
            }

            StringEvaluationTraceSerializer serializer = new StringEvaluationTraceSerializer();

            for (EvaluationTrace trace : reporter.getCollectedTraces()) {
                System.out.println(trace.getExpression() + ": " + trace.getValue());
                System.out.print(serializer.serializeEvaluationLevels(trace));
            }

            reporter.reset();
        }
    }
}

@@ -1112,10 +1112,833 @@
 %7D%0A    %7D%0A
+%0A    /**%0A     * Prints out traces (if any exist) from the provided reporter with a description into sysout%0A     */%0A    public static String collectAndClearTraces(EvaluationTraceReporter reporter, String description) %7B%0A        String returnValue = %22%22;%0A        if (reporter != null) %7B%0A            if (reporter.wereTracesReported()) %7B%0A                returnValue += description + %22%5Cn%22;%0A            %7D%0A%0A            StringEvaluationTraceSerializer serializer = new StringEvaluationTraceSerializer();%0A%0A            for (EvaluationTrace trace : reporter.getCollectedTraces()) %7B%0A                returnValue += trace.getExpression() + %22: %22 + trace.getValue()  + %22%5Cn%22;%0A                returnValue += serializer.serializeEvaluationLevels(trace);%0A            %7D%0A%0A            reporter.reset();%0A        %7D%0A        return returnValue;%0A    %7D%0A%0A
 %7D%0A

Add a way to evaluate traces into a single string output