From 05ce43e12ebd108dc53bdde3ad7414810fef8598 Mon Sep 17 00:00:00 2001 From: Philip Arickx Date: Wed, 12 Apr 2017 21:27:49 +0200 Subject: [PATCH 1/2] Feature : Show profile duration Show total duration of the profile, in ms. --- .../core/collector/lean/LeanLogCollector.java | 6 ++- .../core/profiles/lean/LeanProfile.java | 16 +++++- .../controller/ProfileRootController.java | 54 ++++++++++++++----- .../honest_profiler/ports/javafx/css/HPUI.css | 4 ++ .../ports/javafx/fxml/ProfileDiffRoot.fxml | 12 +---- .../ports/javafx/fxml/ProfileRoot.fxml | 7 ++- .../javafx/i18n/HPUIBundle_en.properties | 3 +- 7 files changed, 73 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/insightfullogic/honest_profiler/core/collector/lean/LeanLogCollector.java b/src/main/java/com/insightfullogic/honest_profiler/core/collector/lean/LeanLogCollector.java index 0da5249f1..d099d5fb9 100644 --- a/src/main/java/com/insightfullogic/honest_profiler/core/collector/lean/LeanLogCollector.java +++ b/src/main/java/com/insightfullogic/honest_profiler/core/collector/lean/LeanLogCollector.java @@ -54,6 +54,9 @@ public class LeanLogCollector implements LogEventListener, ProfileSource // Difference in ns between the previous and the current TraceStart. private long nanosSpent; + // The number of nanoseconds which elapsed between the first and last seen samples in the profile. + private long totalNanos; + // Indicates whether a profile was requested and should be emitted. private AtomicBoolean profileRequested; @@ -224,6 +227,7 @@ private void updateTime(long newSeconds, long newNanos) long nanosDiff = newNanos - prevNanos; nanosSpent = (secondsDiff * SECONDS_TO_NANOS) + nanosDiff; + totalNanos += nanosSpent; } prevSeconds = newSeconds; @@ -248,7 +252,7 @@ private void emitProfile() { if (!empty) { - listener.accept(new LeanProfile(methodMap, threadMap, threadData)); + listener.accept(new LeanProfile(methodMap, threadMap, threadData, totalNanos)); } } } diff --git a/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanProfile.java b/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanProfile.java index 2d10aa524..947b2d416 100644 --- a/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanProfile.java +++ b/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanProfile.java @@ -33,6 +33,7 @@ public class LeanProfile private final Map methodInfoMap; private final Map threadInfoMap; private final Map threads; + private final long totalNanos; // Instance constructors @@ -44,14 +45,17 @@ public class LeanProfile * @param threadMap a {@link Map} mapping the thread id to the corresponding {@link ThreadInfo} * @param threadData a {@link Map} mapping the thread id to the {@link LeanThreadNode} root of the {@link LeanNode} * tree containing the aggregated stack trace sample information for that thread + * @param totalNanos the total number of ns spent between the first and last recorded sample in the profile */ public LeanProfile(Map methodMap, Map threadMap, - Map threadData) + Map threadData, + long totalNanos) { this.methodInfoMap = new HashMap<>(methodMap); this.threadInfoMap = new HashMap<>(threadMap); this.threads = new HashMap<>(); + this.totalNanos = totalNanos; threadData.forEach((key, value) -> this.threads.put(key, value.copy())); } @@ -133,6 +137,16 @@ public String getThreadName(Long threadId) return info == null ? "Unknown <" + threadId + ">" : info.getIdentification(); } + /** + * Return the number of nanoseconds which elapsed between the first and last samples in the profile. + * + * @return the number of nanoseconds which elapsed between the first and last samples in the profile + */ + public long getTotalNanos() + { + return totalNanos; + } + // Object Implementation @Override diff --git a/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/controller/ProfileRootController.java b/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/controller/ProfileRootController.java index 7648ca0b6..c4088353a 100644 --- a/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/controller/ProfileRootController.java +++ b/src/main/java/com/insightfullogic/honest_profiler/ports/javafx/controller/ProfileRootController.java @@ -36,7 +36,7 @@ import static com.insightfullogic.honest_profiler.ports.javafx.util.BindUtil.flatExtractor; import static com.insightfullogic.honest_profiler.ports.javafx.util.BindUtil.treeExtractor; import static com.insightfullogic.honest_profiler.ports.javafx.util.ConversionUtil.getStringConverterForType; -import static com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.CONTENT_LABEL_PROFILESAMPLECOUNT; +import static com.insightfullogic.honest_profiler.ports.javafx.util.ConversionUtil.toMillis; import static com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.INFO_BUTTON_COMPARE; import static com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.INFO_BUTTON_FREEZE_FROZEN; import static com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.INFO_BUTTON_FREEZE_UNFROZEN; @@ -53,9 +53,11 @@ import java.util.List; import java.util.Map; +import com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile; import com.insightfullogic.honest_profiler.ports.javafx.ViewType; import com.insightfullogic.honest_profiler.ports.javafx.model.ApplicationContext; import com.insightfullogic.honest_profiler.ports.javafx.model.ProfileContext; +import com.insightfullogic.honest_profiler.ports.javafx.util.ConversionUtil; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -85,6 +87,8 @@ public class ProfileRootController extends AbstractController @FXML private Label profileSampleCount; @FXML + private Label profileDuration; + @FXML private AnchorPane content; @FXML private FlatViewController flatController; @@ -177,20 +181,12 @@ public void setProfileContext(ProfileContext prCtx) flameController.setProfileContext(prCtx); flameController.bind(prCtx.flameGraphProperty(), FLAME_EXTRACTOR); - // Bind the profile sample count display - prCtx.profileProperty().addListener( - (property, oldValue, newValue) -> profileSampleCount.setText( - newValue == null ? null : getText( - CONTENT_LABEL_PROFILESAMPLECOUNT, - newValue.getGlobalData().getTotalCnt()))); + // Bind the profile sample count display so it changes when new Profiles come in + prCtx.profileProperty() + .addListener((property, oldValue, newValue) -> updateSampleCount(newValue)); - if (prCtx.getProfile() != null) - { - profileSampleCount.setText( - getText( - CONTENT_LABEL_PROFILESAMPLECOUNT, - prCtx.getProfile().getGlobalData().getTotalCnt())); - } + // Display the initial sample count + updateSampleCount(prCtx); // Configure the View choice viewChoice.setConverter(getStringConverterForType(ViewType.class)); @@ -202,6 +198,36 @@ public void setProfileContext(ProfileContext prCtx) freezeButton.setDisable(prCtx.getMode() != LIVE); } + // Sample Count Display + + /** + * Update the sample count based on the {@link ProfileContext}. + * + * @param profileContext the {@link ProfileContext} + */ + private void updateSampleCount(ProfileContext profileContext) + { + updateSampleCount(profileContext == null ? null : profileContext.getProfile()); + } + + /** + * Update the sample count for the {@link AggregationProfile}. + * + * @param profile the {@link AggregationProfile} + */ + private void updateSampleCount(AggregationProfile profile) + { + + if (profile == null) + { + profileSampleCount.setText(null); + return; + } + + profileSampleCount.setText(Long.toString(profile.getGlobalData().getTotalCnt())); + profileDuration.setText(Long.toString(toMillis(profile.getSource().getTotalNanos())) + " ms"); + } + // View Methods /** diff --git a/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/css/HPUI.css b/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/css/HPUI.css index e712bf8b8..0a236cf89 100644 --- a/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/css/HPUI.css +++ b/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/css/HPUI.css @@ -27,6 +27,10 @@ -fx-font-smoothing-type: lcd; } +.genericLabel { + -fx-font-weight: bold; +} + .tab-pane:top *.tab-header-area { -fx-background-insets: 0, 0 0 1 0; -fx-padding: 0.416667em 0.166667em 0.0em 0.0em; diff --git a/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/fxml/ProfileDiffRoot.fxml b/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/fxml/ProfileDiffRoot.fxml index 4b873eb97..d28f26a4c 100644 --- a/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/fxml/ProfileDiffRoot.fxml +++ b/src/main/resources/com/insightfullogic/honest_profiler/ports/javafx/fxml/ProfileDiffRoot.fxml @@ -18,21 +18,13 @@ - +