Skip to content

Commit

Permalink
LDEV-5211 DebugExecutionLog MAX_PARTS
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Dec 18, 2024
1 parent 082d83c commit 671b934
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
35 changes: 20 additions & 15 deletions core/src/main/java/lucee/runtime/debug/DebuggerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, DebugEntryTemplateImpl> entries = new HashMap<String, DebugEntryTemplateImpl>();
private Map<String, DebugEntryTemplatePartImpl> partEntries;
Expand Down Expand Up @@ -236,7 +236,7 @@ public DebugEntryTemplatePart getEntry(PageContext pc, PageSource source, int st
if (de != null) {
de.countPP();
return de;
}
}
}
else {
partEntries = new HashMap<String, DebugEntryTemplatePartImpl>();
Expand Down Expand Up @@ -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<DebugEntryTemplatePart> filteredPartEntries = new ArrayList();
java.util.Collection<DebugEntryTemplatePartImpl> col = partEntries.values();
for (DebugEntryTemplatePart detp: col) {
List<DebugEntryTemplatePart> filteredPartEntries = new ArrayList<DebugEntryTemplatePart>();
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,12 +38,14 @@ protected void _init(PageContext pc, Map<String, String> 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);
}

Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/resource/setting/sysprop-envvar.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
8 changes: 6 additions & 2 deletions test/tickets/LDEV5206.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ component extends = "org.lucee.cfml.test.LuceeTestCase" {
);
});
});

describe( "LDEV-5206 DebugExecutionLog", function(){
it( "test DebugExecutionLog - cfm ", function(){
var logs = getDebugLogs();
Expand All @@ -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";
Expand Down Expand Up @@ -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 ];
Expand All @@ -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 );
Expand Down

0 comments on commit 671b934

Please sign in to comment.