internal static void TemplateOptimizerStarting( this IProfilerScope ps, string codeProvider, bool usingOptimizer) { ps.AddMetric("codeProvider", codeProvider); ps.AddMetric("usingOptimizer", usingOptimizer); }
internal static void EndParsing( this IProfilerScope ps, string name, int contentLength) { ps.MarkEnd(); ps.AddMetric("templateName", name); ps.AddMetric("templateLength", contentLength); }
internal static void SourceCodeMetrics( this IProfilerScope ps, bool completelyInlined, int domNodeCount, int generatedCodeLength, int renderIslandCount, int variableCount) { // TODO Currently unsupported in HTML lib - ps.AddMetric("documentNodeCount", this.SourceDocument.Descendents.Count()); ps.AddMetric("generatedCodeLength", generatedCodeLength); ps.AddMetric("nodeCount", domNodeCount); ps.AddMetric("renderIslandCount", renderIslandCount); ps.AddMetric("variableCount", variableCount); ps.AddMetric("completelyInlined", completelyInlined); ps.MarkEnd(); }
private bool IsCompletelyInlined(DomContainer document, IProfilerScope scope) { if (document.ChildNodes.Count != 1) { return(false); } var hxlRenderElement = document.ChildNodes[0] as HxlRenderWorkElement; if (hxlRenderElement == null || hxlRenderElement.ChildNodes.Count > 0) { return(false); } scope.AddMetric("completelyInlined", true); CSTemplateGenerator g = new CSTemplateGenerator(); ApplySettings(template, g); g.TransformTextCore = string.Join(Environment.NewLine, hxlRenderElement.PreLines) + string.Join(Environment.NewLine, hxlRenderElement.PostLines); g.HasDocument = false; string code = g.TransformText(); output.WriteLine(code); if (Metrics.EnableAdvancedParserMetrics) { scope.SourceCodeMetrics(true, 1, code.Length, 0, 0); } return(true); }
public void WriteCode(IProfilerScope scope) { var result = this.template.PreparedDocument; if (IsCompletelyInlined(result, scope)) { return; } // We buffer this output so that we can present variables upfront for readability var buffer = new StringWriter(); var visitor = new GenerateInitTextVisitor(buffer, this.template); visitor.Visit(result); CSTemplateGenerator g = new CSTemplateGenerator(); ApplySettings(template, g); g.DomNodeVariables = visitor.AllDomNodeVariables; g.DomObjectVariables = visitor.AllDomObjectVariables; g.InitializeComponent = buffer.ToString(); g.RenderIslands = visitor.RenderIslands; g.HasDocument = true; g.Accessibility = "public"; string code = g.TransformText(); output.WriteLine(code); if (Metrics.EnableAdvancedParserMetrics) { scope.SourceCodeMetrics(false, this.template.PreparedDocument.DescendantNodes.Count(), code.Length, visitor.RenderIslandCount, g.DomNodeVariables.Count + g.DomNodeVariables.Count); } }
public ParsedTemplate(string text, string name, HxlCompilerSettings settings) { _metrics = Metrics.ForTemplateParsing(); _metrics.StartParsing(); _sourceDocument = HtmlDocumentFragment.Parse(text, new HtmlReaderSettings { Mode = HtmlTreeBuilderMode.Xml }); _metrics.EndParsing(name, text.Length); _settings = settings; _nodeFactory = DomNodeFactory.Compose( HxlDomNodeFactory.Compiler, _settings.NodeFactories, new InvalidFactory()); Signature = string.Concat(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(text)) .Take(8) .Select(b => b.ToString("x2")) ); if (string.IsNullOrEmpty(name)) { this.TemplateName = "Template" + this.Signature; } else { this.TemplateName = CodeUtility.Slug(name); } this.Namespace = "Generated"; this.ClassName = this.TemplateName; using (UsingNamespaceResolver()) { this._preparedDocument = PrepareDocument(); } }
internal static void EndOptimizer( this IProfilerScope ps) { ps.MarkEnd(); // TODO Compute optimizer efficiency }
internal static void StartOptimizer( this IProfilerScope ps) { ps.MarkStart("optimizerTime"); }
internal static void EndSourceGenerator( this IProfilerScope ps) { ps.MarkEnd(); }
internal static void StartSourceGenerator( this IProfilerScope ps) { ps.MarkStart("sourceGeneratorTime"); }
internal static void StartParsing( this IProfilerScope ps) { ps.MarkStart("parserTime"); }
internal static void EndPreprocessor( this IProfilerScope ps) { ps.MarkEnd(); }
internal static void StartPreprocessor( this IProfilerScope ps) { ps.MarkStart("preprocessorTime"); }
internal static IDisposable NewTiming(IProfilerScope self, string name) { self.MarkStart(name); return(new DisposableAction(self.MarkEnd)); }