Skip to content

Commit e098fdc

Browse files
committed
Trim console output before processing it console document
When processing large amounts of console output of a process, its possible that the Eclipse UI will freeze. E.g. on Linux, very long lines (> 1 million symbols) result in such freezes. Using the console limit preference doesn't help preventing this freeze, despite limitting the contents seen in the console. This change adjusts IOConsolePartitioner.QueueProcessingJob.processPendingPartitions() to trim pending console output before setting this output in the console document, if a console limit is set in the Eclipse preferences. See: #2283
1 parent 8594fad commit e098fdc

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

debug/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ public boolean shouldRun() {
784784
* update partitioning.
785785
*/
786786
private void processPendingPartitions() {
787-
final List<PendingPartition> pendingCopy = new ArrayList<>();
787+
List<PendingPartition> pendingCopy = new ArrayList<>();
788788
// draining the whole buffer here is important - this way we get as much data as
789789
// available and may skip to draw text that exceeds the Console buffer size
790790
// anyway (see checkBufferSize()).
@@ -800,6 +800,36 @@ private void processPendingPartitions() {
800800
}
801801
sizeHint += p.text.length();
802802
}
803+
/*
804+
* Check if the output we want to process is over the console limit. If so, trim
805+
* the output before passing it to SWT.
806+
*/
807+
int hwm = highWaterMark;
808+
if (hwm > 0 && sizeHint > hwm) {
809+
List<PendingPartition> copy = new ArrayList<>();
810+
List<PendingPartition> trimmedCopy = new ArrayList<>();
811+
for (PendingPartition p : pendingCopy) {
812+
if (p.stream != stream) {
813+
break;
814+
}
815+
copy.add(p);
816+
}
817+
sizeHint = 0;
818+
int index = 0;
819+
for (int i = copy.size() - 1; i >= 0; --i) {
820+
PendingPartition p = copy.get(i);
821+
sizeHint += p.text.length();
822+
index = i;
823+
if (sizeHint > hwm) {
824+
break;
825+
}
826+
}
827+
for (int i = index; i < copy.size(); ++i) {
828+
PendingPartition p = copy.get(i);
829+
trimmedCopy.add(p);
830+
}
831+
pendingCopy = trimmedCopy;
832+
}
803833
synchronized (partitions) {
804834
if (document != null) {
805835
applyStreamOutput(pendingCopy, sizeHint);

0 commit comments

Comments
 (0)