You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/12/05 16:57:53 UTC
[groovy] branch GROOVY-9849 created (now 2bf5060)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch GROOVY-9849
in repository https://gitbox.apache.org/repos/asf/groovy.git.
at 2bf5060 GROOVY-9849: Show elapsed time in groovy console
This branch includes the following new commits:
new 2bf5060 GROOVY-9849: Show elapsed time in groovy console
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[groovy] 01/01: GROOVY-9849: Show elapsed time in groovy console
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-9849
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 2bf5060ac121d79754c70e43e9da3548d282a995
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Dec 6 00:57:23 2020 +0800
GROOVY-9849: Show elapsed time in groovy console
---
.../main/groovy/groovy/console/ui/Console.groovy | 23 +++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
index 72b8e5e..a96ffd5 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
@@ -991,11 +991,12 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
appendStacktrace("\n${sw.builder}\n")
}
- def finishNormal(Object result) {
+ def finishNormal(Object result, Long elapsedTime=null) {
+ String elapsedTimeStr = null != elapsedTime ? " Elapsed time: ${elapsedTime}ms." : ''
// Take down the wait/cancel dialog
history[-1].result = result
if (result != null) {
- statusLabel.text = 'Execution complete.'
+ statusLabel.text = "Execution complete.${elapsedTimeStr}"
appendOutputNl('Result: ', promptStyle)
def obj = (visualizeScriptResults
? OutputTransforms.transformResult(result, shell.getContext()._outputTransforms)
@@ -1004,7 +1005,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
// multi-methods are magical!
appendOutput(obj, resultStyle)
} else {
- statusLabel.text = 'Execution complete. Result was null.'
+ statusLabel.text = "Execution complete. Result was null.${elapsedTimeStr}"
}
bindResults()
if (detachedOutput) {
@@ -1357,23 +1358,23 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
if (beforeExecution) {
beforeExecution()
}
- def result
+ Tuple2<Object, Long> resultAndElapsedTime
if (useScriptClassLoaderForScriptExecution) {
ClassLoader savedThreadContextClassLoader = Thread.currentThread().contextClassLoader
try {
Thread.currentThread().contextClassLoader = shell.classLoader
- result = doRun(selected, st, record)
+ resultAndElapsedTime = doRun(selected, st, record)
}
finally {
Thread.currentThread().contextClassLoader = savedThreadContextClassLoader
}
} else {
- result = doRun(selected, st, record)
+ resultAndElapsedTime = doRun(selected, st, record)
}
if (afterExecution) {
afterExecution()
}
- SwingUtilities.invokeLater { finishNormal(result) }
+ SwingUtilities.invokeLater { finishNormal(resultAndElapsedTime.v1, resultAndElapsedTime.v2) }
} catch (Throwable t) {
if (t instanceof StackOverflowError) {
// set the flag that will be used in printing exception details in output pane
@@ -1401,9 +1402,13 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
}
@CompileStatic
- private Object doRun(boolean selected, SourceType st, HistoryRecord record) {
+ private Tuple2<Object, Long> doRun(boolean selected, SourceType st, HistoryRecord record) {
def src = record.getTextToRun(selected)
- return st.run(src)
+ long begin = System.currentTimeMillis()
+ Object result = st.run(src)
+ long end = System.currentTimeMillis()
+
+ return Tuple.tuple(result, (end - begin))
}
@CompileStatic