# Profiling and debugging view templates

DevFeed: [Profiling and debugging view templates](<https://devfeed.tech/articles/profiling-and-debugging-view-templates-31967.md>)

Original publisher: [Read original article](<https://tech.finn.no2012/06/23/profiling-and-debugging-view-templates/>)

Author: mick

Published: 2012-06-23T10:31:21Z

Content type: tutorial

Language: en

Sources: [Finn.no](<https://devfeed.tech/sources/finn-no.md>)

Topics: [debug](<https://devfeed.tech/topics/debug.md>), [Template](<https://devfeed.tech/topics/template.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [debugging](<https://devfeed.tech/tags/debugging.md>), [html](<https://devfeed.tech/tags/html.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [profiling](<https://devfeed.tech/tags/profiling.md>), [render](<https://devfeed.tech/tags/render.md>), [setup](<https://devfeed.tech/tags/setup.md>), [templates](<https://devfeed.tech/tags/templates.md>)

## AI overview

A tutorial on using Tiles-3 PublisherRenderer to profile and debug server-side view-template trees. It explains how to register a renderer listener that exposes rendered templates, identifies slow templates, and adds wrapping comments to HTML output, with Java implementation examples.

## Source excerpt

Ever needed to profile the tree of JSPs rendered server-side? Most companies do and I've seen elaborate and rather convoluted ways to do so. With Tiles-3 you can use the PublisherRenderer to profile and debug not just the tree of JSPs but the full tree of all and any view templates rendered whether they be JSP, velocity, freemarker, or mustache. At FINN all web pages print such a tree at the bottom of the page. This helps us see what templates were involved in the rendering of that page, and which templates are slow to render. ] We also embed into the html source wrapping comments like ...template output... The code please To do this register and then attach your own listener to the PublisherRenderer. For example in your TilesContainerFactory (the class you extend to setup and configure Tiles) add to the methd createTemplateAttributeRenderer something like: @Override protected Renderer createTemplateAttributeRenderer(BasicRendererFactory rendererFactory, ApplicationContext applicationContext, TilesContainer container, AttributeEvaluatorFactory attributeEvaluatorFactory) { Renderer renderer = super.createTemplateAttributeRenderer(rendererFactory, applicationContext, container, attributeEvaluatorFactory); PublisherRenderer publisherRenderer = new PublisherRenderer(renderer); publisherRenderer.addListener(new MyListener()); return publisherRenderer; } Then implement your own listener, this implementation does just the wrapping comments with profiling information... class MyListener implements PublisherRenderer.RendererListener { @Override public void start(String template, Request request) throws IOException { boolean first = null == request.getContext("request").get("started"); if (!first) { // first check avoids writing before a template's doctype tag request.getPrintWriter().println("\n"); startStopWatch(request); } else { request.getContext("request").put("started", Boolean.TRUE); } } @Override public void end(String template, Request request) throws IOException { Lo