Skip to content

Commit 2776d6f

Browse files
trancexpressiloveeclipse
authored andcommitted
Trim console output before processing it in 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 e33c137 commit 2776d6f

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

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

Lines changed: 32 additions & 4 deletions
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()).
@@ -793,12 +793,40 @@ private void processPendingPartitions() {
793793
if (pendingCopy.isEmpty()) {
794794
return;
795795
}
796+
int pendingSize = 0;
796797
IOConsoleOutputStream stream = pendingCopy.get(0).stream;
797798
for (PendingPartition p : pendingCopy) {
798-
if (p.stream != stream) {
799-
break;
799+
if (p.stream == stream) {
800+
sizeHint += p.text.length();
801+
}
802+
pendingSize += p.text.length();
803+
}
804+
/*
805+
* Check if the output we want to process is over the console limit. If so, trim
806+
* the output before passing it to SWT.
807+
*/
808+
int limit = highWaterMark;
809+
if (limit > 0 && pendingSize > limit) {
810+
sizeHint = Math.min(sizeHint, limit);
811+
int n = pendingCopy.size();
812+
// check at which pending change we need to cut the output, to comply with the character limit
813+
int index = 0;
814+
int characters = 0;
815+
for (int i = n - 1; i >= 0; --i) {
816+
PendingPartition p = pendingCopy.get(i);
817+
characters += p.text.length();
818+
index = i;
819+
if (characters > limit) {
820+
break;
821+
}
822+
}
823+
// copy from that index onward
824+
List<PendingPartition> trimmedCopy = new ArrayList<>(n - index);
825+
for (int i = index; i < n; ++i) {
826+
PendingPartition p = pendingCopy.get(i);
827+
trimmedCopy.add(p);
800828
}
801-
sizeHint += p.text.length();
829+
pendingCopy = trimmedCopy;
802830
}
803831
synchronized (partitions) {
804832
if (document != null) {

0 commit comments

Comments
 (0)