Skip to content

Commit 7e1f60c

Browse files
EcljpseB0Tjukzi
authored andcommitted
[Debug] Show elapsed Time in Console & Properties
Elapsed duration formated as H:MM:SS.mmm While process is running console header is updated once per second.
1 parent 9d9bf70 commit 7e1f60c

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ public class DebugPreferencesMessages extends NLS {
192192

193193
public static String ProcessPropertyPage_11;
194194

195+
public static String ProcessPropertyPage_12;
196+
195197
public static String ProcessPropertyPage_1;
196198

197199
public static String ProcessPropertyPage_2;

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ ProcessPropertyPage_Command_Line__1=Co&mmand Line:
100100
ProcessPropertyPage_0=Run-&at time:
101101
ProcessPropertyPage_10=&Terminated-at time:
102102
ProcessPropertyPage_11=PID:
103+
ProcessPropertyPage_12=Elapsed:
103104
ProcessPropertyPage_1=&Path:
104105
ProcessPropertyPage_2=Process properties
105106
ProcessPropertyPage_3=No path information available

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/ProcessPropertyPage.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import java.text.DateFormat;
1919
import java.text.ParseException;
20+
import java.time.Duration;
21+
import java.time.Instant;
2022
import java.util.Arrays;
2123
import java.util.Date;
2224
import java.util.regex.Matcher;
@@ -75,6 +77,30 @@ protected Control createContents(Composite ancestor) {
7577
text.setBackground(parent.getBackground());
7678
SWTFactory.createVerticalSpacer(parent, 2);
7779

80+
// Elapsed Duration:
81+
SWTFactory.createLabel(parent, DebugPreferencesMessages.ProcessPropertyPage_12, fHeadingFont, 1);
82+
text = SWTFactory.createText(parent, SWT.READ_ONLY, 1);
83+
((GridData) text.getLayoutData()).horizontalIndent = 10;
84+
String elapsedString = "?"; //$NON-NLS-1$
85+
try {
86+
if (proc != null) {
87+
String launch = proc.getAttribute(DebugPlugin.ATTR_LAUNCH_TIMESTAMP);
88+
String terminate = proc.getAttribute(DebugPlugin.ATTR_TERMINATE_TIMESTAMP);
89+
Date launchTime = launch == null ? null : new Date(Long.parseLong(launch));
90+
Date terminateTime = terminate == null ? null : new Date(Long.parseLong(terminate));
91+
Duration elapsedTime = Duration.between(launchTime != null ? launchTime.toInstant() : Instant.now(),
92+
terminateTime != null ? terminateTime.toInstant() : Instant.now());
93+
elapsedString = String.format("%d:%02d:%02d.%03d", elapsedTime.toHours(), //$NON-NLS-1$
94+
elapsedTime.toMinutesPart(), elapsedTime.toSecondsPart(), elapsedTime.toMillisPart());
95+
}
96+
} catch (Exception e) {
97+
// ignore wrong time format
98+
}
99+
PlatformUI.getWorkbench().getHelpSystem().setHelp(text, IDebugHelpContextIds.PROCESS_PAGE_TERMINATE_AT);
100+
text.setText(elapsedString);
101+
text.setBackground(parent.getBackground());
102+
SWTFactory.createVerticalSpacer(parent, 2);
103+
78104
// create the process terminate time section
79105
SWTFactory.createLabel(parent, DebugPreferencesMessages.ProcessPropertyPage_10, fHeadingFont, 1);
80106
text = SWTFactory.createText(parent, SWT.READ_ONLY, 1);

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleMessages.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ ProcessConsole_0=<terminated> {0}
2525
ProcessConsole_1=[Console output redirected to file:{0}]\n
2626
ProcessConsole_2=[Invalid file specified for console output: {0}]\n
2727
ProcessConsole_3=[Invalid file specified for stdin file: {0}]\n
28-
ProcessConsole_commandLabel_withStart={0} ({1})
28+
ProcessConsole_commandLabel_withStart={0} ({1} elapsed: {2})
2929
ProcessConsole_commandLabel_withEnd={0} (Terminated {1})
30-
ProcessConsole_commandLabel_withStartEnd={0} ({1} \u2013 {2})
30+
ProcessConsole_commandLabel_withStartEnd={0} ({1} \u2013 {2} elapsed: {3})
3131
ShowStandardErrorAction_0=Show Console When Standard Error Changes
3232
ShowStandardOutAction_0=Show Console When Standard Out Changes

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.text.DateFormat;
3030
import java.text.MessageFormat;
3131
import java.text.ParseException;
32+
import java.time.Duration;
33+
import java.time.Instant;
3234
import java.time.LocalDateTime;
3335
import java.time.ZoneId;
3436
import java.time.temporal.ChronoUnit;
@@ -333,6 +335,14 @@ protected String computeName() {
333335
}
334336

335337
DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
338+
Duration elapsedTime = Duration.between(launchTime != null ? launchTime.toInstant() : Instant.now(),
339+
terminateTime != null ? terminateTime.toInstant() : Instant.now());
340+
String elapsedString = String.format("%d:%02d:%02d.%03d", elapsedTime.toHours(), //$NON-NLS-1$
341+
elapsedTime.toMinutesPart(), elapsedTime.toSecondsPart(), elapsedTime.toMillisPart());
342+
if (terminateTime == null) {
343+
DebugUIPlugin.getStandardDisplay().asyncExec(
344+
() -> DebugUIPlugin.getStandardDisplay().timerExec(1000, () -> resetName(false)));
345+
}
336346
if (launchTime != null && terminateTime != null) {
337347
String launchTimeStr = dateTimeFormat.format(launchTime);
338348
// Check if process started and terminated at same day. If so only print the
@@ -351,10 +361,10 @@ protected String computeName() {
351361
}
352362

353363
buffer.append(MessageFormat.format(ConsoleMessages.ProcessConsole_commandLabel_withStartEnd,
354-
procLabel, launchTimeStr, terminateTimeStr));
364+
procLabel, launchTimeStr, terminateTimeStr, elapsedString));
355365
} else if (launchTime != null) {
356366
buffer.append(MessageFormat.format(ConsoleMessages.ProcessConsole_commandLabel_withStart,
357-
procLabel, dateTimeFormat.format(launchTime)));
367+
procLabel, dateTimeFormat.format(launchTime), elapsedString));
358368
} else if (terminateTime != null) {
359369
buffer.append(MessageFormat.format(ConsoleMessages.ProcessConsole_commandLabel_withEnd,
360370
procLabel, dateTimeFormat.format(terminateTime)));
@@ -559,7 +569,7 @@ protected void init() {
559569
setName(computeName());
560570
if (fProcess.isTerminated()) {
561571
closeStreams();
562-
resetName();
572+
resetName(true);
563573
DebugPlugin.getDefault().removeDebugEventListener(this);
564574
}
565575
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
@@ -600,24 +610,26 @@ public void handleDebugEvents(DebugEvent[] events) {
600610
DebugPlugin.getDefault().removeDebugEventListener(this);
601611
}
602612

603-
resetName();
613+
resetName(true);
604614
}
605615
}
606616
}
607617

608618
/**
609619
* resets the name of this console to the original computed name
610620
*/
611-
private synchronized void resetName() {
621+
private synchronized void resetName(boolean changed) {
612622
final String newName = computeName();
613623
String name = getName();
614624
if (!name.equals(newName)) {
615625
UIJob job = new UIJob("Update console title") { //$NON-NLS-1$
616626
@Override
617627
public IStatus runInUIThread(IProgressMonitor monitor) {
618-
ProcessConsole.this.setName(newName);
619-
warnOfContentChange();
620-
return Status.OK_STATUS;
628+
ProcessConsole.this.setName(newName);
629+
if (changed) {
630+
warnOfContentChange();
631+
}
632+
return Status.OK_STATUS;
621633
}
622634
};
623635
job.setSystem(true);

0 commit comments

Comments
 (0)