diff --git a/core/src/main/java/lucee/runtime/debug/DebuggerImpl.java b/core/src/main/java/lucee/runtime/debug/DebuggerImpl.java index 0ce13d3bba..80c742dfdd 100644 --- a/core/src/main/java/lucee/runtime/debug/DebuggerImpl.java +++ b/core/src/main/java/lucee/runtime/debug/DebuggerImpl.java @@ -108,7 +108,7 @@ public final class DebuggerImpl implements Debugger { private static final Collection.Key GENERIC_DATA = KeyConstants._genericData; private static final Collection.Key PAGE_PARTS = KeyConstants._pageParts; - private static final int MAX_PARTS = 100; + private static final int MAX_PARTS = Caster.toIntValue(SystemUtil.getSystemPropOrEnvVar("lucee.debugging.maxPageParts", null), 0); private final Map entries = new HashMap(); private Map partEntries; @@ -236,7 +236,7 @@ public DebugEntryTemplatePart getEntry(PageContext pc, PageSource source, int st if (de != null) { de.countPP(); return de; - } + } } else { partEntries = new HashMap(); @@ -559,26 +559,31 @@ public Struct getDebuggingData(PageContext pc, boolean addAddionalInfo) throws D int qrySize = 0; Query qryPart = null; if (hasParts) { - String slowestTemplate = arrPages.get(0).getPath(); - List filteredPartEntries = new ArrayList(); java.util.Collection col = partEntries.values(); - for (DebugEntryTemplatePart detp: col) { + List filteredPartEntries = new ArrayList(); + DebugEntryTemplatePart[] parts = new DebugEntryTemplatePart[qrySize]; + if (MAX_PARTS == 0 || col.size() < MAX_PARTS){ + qrySize = col.size(); + parts = new DebugEntryTemplatePart[qrySize]; + filteredPartEntries.addAll(col); + parts = filteredPartEntries.toArray(parts); + } else { + // TODO add slowest templates till we reach MAX_PARTS, currently just grabs only the slowest template's parts + String slowestTemplate = arrPages.get(0).getPath(); + for (DebugEntryTemplatePart detp: col) { + if (detp.getPath().equals(slowestTemplate)) filteredPartEntries.add(detp); + } + qrySize = Math.min(filteredPartEntries.size(), MAX_PARTS); + parts = new DebugEntryTemplatePart[qrySize]; - if (detp.getPath().equals(slowestTemplate)) filteredPartEntries.add(detp); - } - qrySize = Math.min(filteredPartEntries.size(), MAX_PARTS); + if (filteredPartEntries.size() > MAX_PARTS) parts = filteredPartEntries.subList(0, MAX_PARTS).toArray(parts); + else parts = filteredPartEntries.toArray(parts); + } qryPart = new QueryImpl(PAGE_PART_COLUMNS, qrySize, "query"); debugging.setEL(PAGE_PARTS, qryPart); int row = 0; - Collections.sort(filteredPartEntries, DEBUG_ENTRY_TEMPLATE_PART_COMPARATOR); - - DebugEntryTemplatePart[] parts = new DebugEntryTemplatePart[qrySize]; - - if (filteredPartEntries.size() > MAX_PARTS) parts = filteredPartEntries.subList(0, MAX_PARTS).toArray(parts); - else parts = filteredPartEntries.toArray(parts); - try { DebugEntryTemplatePart de; // PageSource ps; diff --git a/core/src/main/java/lucee/runtime/engine/ConsoleExecutionLog.java b/core/src/main/java/lucee/runtime/engine/ConsoleExecutionLog.java index b86d9ae498..c165ec98e7 100644 --- a/core/src/main/java/lucee/runtime/engine/ConsoleExecutionLog.java +++ b/core/src/main/java/lucee/runtime/engine/ConsoleExecutionLog.java @@ -72,7 +72,7 @@ protected void _log(int startPos, int endPos, long startTime, long endTime) { @Override protected void _release() { - if (pw != null) pw.close(); + //if (pw != null) pw.close(); snippetsMap = null; } diff --git a/core/src/main/java/lucee/runtime/engine/DebugExecutionLog.java b/core/src/main/java/lucee/runtime/engine/DebugExecutionLog.java index cd4e517d73..e188356b5c 100644 --- a/core/src/main/java/lucee/runtime/engine/DebugExecutionLog.java +++ b/core/src/main/java/lucee/runtime/engine/DebugExecutionLog.java @@ -21,6 +21,7 @@ import java.util.Map; import lucee.runtime.PageContext; +import lucee.runtime.PageSource; import lucee.runtime.debug.DebugEntry; import lucee.runtime.util.PageContextUtil; @@ -37,12 +38,14 @@ protected void _init(PageContext pc, Map arguments) { protected void _log(int startPos, int endPos, long startTime, long endTime) { if (!PageContextUtil.debug(pc)) return; - + PageSource ps = pc.getCurrentPageSource(null); + if (ps == null) return; + long diff = endTime - startTime; if (unit == UNIT_MICRO) diff /= 1000; else if (unit == UNIT_MILLI) diff /= 1000000; - DebugEntry de = pc.getDebugger().getEntry(pc, pc.getCurrentPageSource(), startPos, endPos); + DebugEntry de = pc.getDebugger().getEntry(pc, ps, startPos, endPos); de.updateExeTime((int) diff); } diff --git a/core/src/main/java/resource/setting/sysprop-envvar.json b/core/src/main/java/resource/setting/sysprop-envvar.json index c1369ccb4a..1cead067f6 100644 --- a/core/src/main/java/resource/setting/sysprop-envvar.json +++ b/core/src/main/java/resource/setting/sysprop-envvar.json @@ -396,5 +396,10 @@ "sysprop": "lucee.threads.maxDefault", "envvar": "LUCEE_THREADS_MAXDEFAULT", "desc": "Sets the default max number of parallel threads, default 20" + }, + { + "sysprop": "lucee.debugging.maxPageParts", + "envvar": "LUCEE_DEBUGGING_MAXPAGEPARTS", + "desc": "Maximum number of debugging page parts (executionLogs to output), 0 to disable max limit" } ] \ No newline at end of file diff --git a/test/tickets/LDEV5206.cfc b/test/tickets/LDEV5206.cfc index e911559587..2cbe9be23b 100644 --- a/test/tickets/LDEV5206.cfc +++ b/test/tickets/LDEV5206.cfc @@ -25,6 +25,7 @@ component extends = "org.lucee.cfml.test.LuceeTestCase" { ); }); }); + describe( "LDEV-5206 DebugExecutionLog", function(){ it( "test DebugExecutionLog - cfm ", function(){ var logs = getDebugLogs(); @@ -35,6 +36,7 @@ component extends = "org.lucee.cfml.test.LuceeTestCase" { expect( pageParts ).toBeQuery(); //systemOutput( pageParts.toString(), true ); pageParts = _toPartsStruct( pageParts ); + //systemOutput( structKeyList(pageParts), true ); //systemOutput( pageParts, true ); var key = "ldev5206.cfm:3:3"; @@ -64,7 +66,7 @@ component extends = "org.lucee.cfml.test.LuceeTestCase" { expect( pageParts[ key ].snippet ).toBe( "cfc.doSleep()" ); // LDEV-5207 }); - xit( "test DebugExecutionLog - cfc parts ", function(){ + it( "test DebugExecutionLog - cfc parts ", function(){ var logs = getDebugLogs(); expect( len( logs ) ).toBe( 1 ); var log = logs[ 1 ]; @@ -74,9 +76,11 @@ component extends = "org.lucee.cfml.test.LuceeTestCase" { //systemOutput( pageParts.toString(), true ); pageParts = _toPartsStruct( pageParts ); + /* key = "ldev5206.cfc:5:5"; expect( pageParts ).toHaveKey( key ); - expect( pageParts[ key ].snippet ).toBe( "sleep(5)" ); + expect( pageParts[ key ].snippet ).toBe( "sleep(5)" ); // LDEV-5207 + */ key = "ldev5206_tag.cfc:6:6"; expect( pageParts ).toHaveKey( key );