Search in sources :

Example 1 with ObjectGraphNode

use of com.github.bordertech.wcomponents.util.ObjectGraphNode in project wcomponents by BorderTech.

the class WComponentRenderPerfTest method runRenderTest.

/**
 * Runs the render test.
 */
private static void runRenderTest() {
    UIContextImpl uic = new UIContextImpl();
    PrintWriter printWriter = new PrintWriter(new NullWriter());
    RenderContext renderContext = new WebXmlRenderContext(printWriter);
    WComponent component = null;
    long baseLineMemory = getHeapUsed();
    try {
        component = (WComponent) Class.forName(CLASS_TO_TEST).newInstance();
    } catch (Exception e) {
        String msg = "Unable to instantiate test component: " + CLASS_TO_TEST;
        LOG.error(LINE_PREFIX + msg);
        throw new SystemException(msg, e);
    }
    long memBeforePaint = getHeapUsed() - baseLineMemory;
    // Set up velocity etc. to obtain a memory reading, and
    // so that the performance results aren't skewed too much
    UIContextHolder.pushContext(uic);
    try {
        component.paint(renderContext);
        long memAfterOnePaint = getHeapUsed() - baseLineMemory;
        long startTime = System.currentTimeMillis();
        // Figure out the loop overhead
        for (int i = 0; i < NUM_RENDERS; i++) {
        }
        long loopOverhead = System.currentTimeMillis() - startTime;
        startTime = System.currentTimeMillis();
        // Now run the render test
        for (int i = 0; i < NUM_RENDERS; i++) {
            component.paint(renderContext);
        }
        long elapsedTime = System.currentTimeMillis() - startTime - loopOverhead;
        long memAfterAllPaints = getHeapUsed() - baseLineMemory;
        LOG.info(LINE_PREFIX + "Memory use before paint: " + memBeforePaint);
        LOG.info(LINE_PREFIX + "Memory use after 1 paint: " + memAfterOnePaint);
        LOG.info(LINE_PREFIX + "Memory use after " + NUM_RENDERS + " paints: " + memAfterAllPaints);
        LOG.info(LINE_PREFIX + "Render time: " + (elapsedTime / (double) NUM_RENDERS) + "ms");
        Object[] treeAndSession = new Object[] { component, uic };
        ObjectGraphNode root = ObjectGraphDump.dump(treeAndSession);
        LOG.info(LINE_PREFIX + "Component mem use: " + ((ObjectGraphNode) root.getChildAt(0)).getSize());
        LOG.info(LINE_PREFIX + "UIC mem use: " + ((ObjectGraphNode) root.getChildAt(1)).getSize());
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) IOException(java.io.IOException) SystemException(com.github.bordertech.wcomponents.util.SystemException) WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) ObjectGraphNode(com.github.bordertech.wcomponents.util.ObjectGraphNode) PrintWriter(java.io.PrintWriter)

Example 2 with ObjectGraphNode

use of com.github.bordertech.wcomponents.util.ObjectGraphNode in project wcomponents by BorderTech.

the class UIContextDumpInterceptor method paint.

/**
 * Paints the component.
 *
 * @param renderContext the renderContext to send the output to.
 */
@Override
public void paint(final RenderContext renderContext) {
    boolean enabled = ConfigurationProperties.getDeveloperDumpUIContext();
    super.paint(renderContext);
    if (enabled) {
        UIContext uic = UIContextHolder.getCurrent();
        // We want to dump the shared WComponent tree (UIC) first, so that all the
        // references from the UI context are shown as such
        Object[] treeAndSession = new Object[] { uic.getUI(), uic };
        try {
            ObjectGraphNode root = ObjectGraphDump.dump(treeAndSession);
            // We only want to dump the tree once
            boolean treeDumped = "true".equalsIgnoreCase((String) uic.getFwkAttribute(UICONTEXT_TREE_DUMPED_KEY));
            if (!treeDumped) {
                uic.setFwkAttribute(UICONTEXT_TREE_DUMPED_KEY, "true");
                // The UI will be the 1st child
                LOG.info("UI dump follows:");
                LOG.info(((ObjectGraphNode) root.getChildAt(0)).toXml());
            }
            // The UI context will be the 2nd child
            LOG.info("UI Context dump follows:");
            LOG.info(((ObjectGraphNode) root.getChildAt(1)).toXml());
        } catch (Exception e) {
            LOG.error("Failed to dump context", e);
        }
    }
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) ObjectGraphNode(com.github.bordertech.wcomponents.util.ObjectGraphNode)

Aggregations

ObjectGraphNode (com.github.bordertech.wcomponents.util.ObjectGraphNode)2 RenderContext (com.github.bordertech.wcomponents.RenderContext)1 UIContext (com.github.bordertech.wcomponents.UIContext)1 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)1 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1