Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : Show profile duration #214

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -248,7 +252,7 @@ private void emitProfile()
{
if (!empty)
{
listener.accept(new LeanProfile(methodMap, threadMap, threadData));
listener.accept(new LeanProfile(methodMap, threadMap, threadData, totalNanos));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class LeanProfile
private final Map<Long, MethodInfo> methodInfoMap;
private final Map<Long, ThreadInfo> threadInfoMap;
private final Map<Long, LeanThreadNode> threads;
private final long totalNanos;

// Instance constructors

Expand All @@ -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<Long, MethodInfo> methodMap,
Map<Long, ThreadInfo> threadMap,
Map<Long, LeanThreadNode> threadData)
Map<Long, LeanThreadNode> threadData,
long totalNanos)
{
methodInfoMap = new HashMap<>(methodMap);
threadInfoMap = new HashMap<>(threadMap);
threads = new HashMap<>();
this.totalNanos = totalNanos;
threadData.forEach((key, value) -> threads.put(key, value.copy()));
}

Expand Down Expand Up @@ -171,6 +175,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,13 @@
<Tooltip text="%choice.viewtype.tooltip" />
</tooltip>
</ChoiceBox>
<Label text="%label.base.content">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
<Label text="%label.base.content" styleClass="genericLabel" />
<Label fx:id="baseSourceLabel" text="&lt;none&gt;">
<tooltip>
<Tooltip text="%label.baseSource.tooltip" />
</tooltip>
</Label>
<Label text="%label.new.content">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
<Label text="%label.new.content" styleClass="genericLabel" />
<Label fx:id="newSourceLabel" text="&lt;none&gt;">
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.insightfullogic.honest_profiler.ports.javafx.controller.ProfileRootController">
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.insightfullogic.honest_profiler.ports.javafx.controller.ProfileRootController">
<children>
<HBox alignment="CENTER_LEFT" maxHeight="35.0" minHeight="35.0" prefHeight="35.0" prefWidth="200.0" spacing="5.0" VBox.vgrow="NEVER">
<children>
Expand Down Expand Up @@ -46,11 +46,14 @@
</ImageView>
</graphic>
</Button>
<Label fx:id="profileSampleCount" prefHeight="15.0" prefWidth="104.0">
<Label text="%label.profileSampleCount.content" styleClass="genericLabel" />
<Label fx:id="profileSampleCount">
<tooltip>
<Tooltip text="%label.profileSampleCount.tooltip" />
</tooltip>
</Label>
<Label text="%label.profileDuration.content" styleClass="genericLabel" />
<Label fx:id="profileDuration" />
</children>
<VBox.margin>
<Insets />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ input.filterValue.info=Specify the value the filter will use for comparison.

label.profileSampleCount.tooltip=Number of samples in the profile
label.profileSampleCount.info=Shows the number of samples in the profile.
label.profileSampleCount.content={0} samples
label.profileSampleCount.content=Samples :
label.profileDuration.content=Duration :
label.base.content=Baseline :
label.new.content=New :
label.baseSource.tooltip=Baseline profile in the comparison
Expand Down