Skip to content

Commit

Permalink
Allow to configure call weight type
Browse files Browse the repository at this point in the history
  • Loading branch information
0xaa4eb committed Jun 1, 2024
1 parent 9a1978f commit ab91b7e
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
public class CallRecord {

private final long callId;
@Getter
private final int subtreeSize;
@Getter
private final long nanosDuration;
Expand All @@ -55,10 +56,6 @@ public class CallRecord {

private List<CallRecord> children;

public int getSubtreeSize() {
return subtreeSize;
}

@NotNull
public ObjectRecord getCallee() {
if (method.isConstructor()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public int callCount() {
return recordingState.callCount();
}

public Duration rootDuration() {
return Duration.ofNanos(getRoot().getNanosDuration());
}

@NotNull
public RecordingMetadata getMetadata() {
return recordingState.getMetadata();
Expand Down
10 changes: 10 additions & 0 deletions ulyp-ui/src/main/kotlin/com/ulyp/ui/RenderSettings.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ulyp.ui

import com.ulyp.core.util.Preconditions
import com.ulyp.ui.settings.RecordedCallWeightType
import com.ulyp.ui.settings.Settings
import javafx.application.Platform
import org.springframework.stereotype.Component
Expand All @@ -26,4 +27,13 @@ class RenderSettings(val settings: Settings) {
Preconditions.checkState(Platform.isFxApplicationThread(), "Not in FX application thread")
field = value
}
var recordedCallWeightType: RecordedCallWeightType = settings.getRecordedCallWeightType()
get() {
Preconditions.checkState(Platform.isFxApplicationThread(), "Not in FX application thread")
return field
}
set(value) {
Preconditions.checkState(Platform.isFxApplicationThread(), "Not in FX application thread")
field = value
}
}
6 changes: 6 additions & 0 deletions ulyp-ui/src/main/kotlin/com/ulyp/ui/SettingsView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ulyp.ui

import com.ulyp.ui.looknfeel.Theme
import com.ulyp.ui.settings.RecordedCallWeightType
import com.ulyp.ui.settings.Settings
import com.ulyp.ui.util.connect
import javafx.fxml.FXML
Expand Down Expand Up @@ -44,6 +45,8 @@ class SettingsView(private val settings: Settings) : Initializable {
lateinit var recordingListSpacingSlider: Slider
@FXML
lateinit var recordingListSpacingLabel: Label
@FXML
lateinit var recordedCallWeightTypeChoiceBox: ChoiceBox<String>

override fun initialize(url: URL, rb: ResourceBundle?) {
sourceCodeViewerEnabled.selectedProperty().bindBidirectional(settings.sourceCodeViewerEnabled)
Expand All @@ -57,6 +60,9 @@ class SettingsView(private val settings: Settings) : Initializable {
recordingTreeFontChoiceBox.items.addAll(Font.getFamilies())
recordingTreeFontChoiceBox.connect(settings.recordingTreeFontName)

recordedCallWeightTypeChoiceBox.items.addAll(RecordedCallWeightType.values().map { it.name })
recordedCallWeightTypeChoiceBox.connect(settings.recordedCallWeightType)

systemFontSizeSlider.connect(systemFontSizeLabel, settings.systemFontSize)
recordingTreeFontSizeSlider.connect(recordingTreeFontSizeLabel, settings.recordingTreeFontSize)
recordingTreeFontSpacingSlider.connect(recordingTreeFontSpacingLabel, settings.recordingTreeFontSpacing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import com.ulyp.storage.tree.CallRecord
import com.ulyp.ui.RenderSettings
import javafx.geometry.Pos
import javafx.scene.layout.StackPane
import java.time.Duration


class RecordedCallNodeContent(node: CallRecord, renderSettings: RenderSettings, totalNodeCountInTree: Int) : StackPane() {
class RecordedCallNodeContent(node: CallRecord, renderSettings: RenderSettings, totalNodeCountInTree: Int, rootDuration: Duration) : StackPane() {

init {
alignment = Pos.CENTER_LEFT
children.addAll(
RecordedCallWeight(node, totalNodeCountInTree),
RecordedCallWeight(renderSettings, node, totalNodeCountInTree, rootDuration),
RecordedCallView(node, renderSettings)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class RecordedCallTreeItem(private val recording: Recording, private val callRec
RecordedCallNodeContent(
recording.getCallRecord(callRecordId),
renderSettings,
recording.callCount()
recording.callCount(),
recording.rootDuration()
)
) {

Expand All @@ -30,7 +31,7 @@ class RecordedCallTreeItem(private val recording: Recording, private val callRec

fun refresh() {
currentCallRecord = recording.getCallRecord(callRecordId)
value = RecordedCallNodeContent(currentCallRecord, renderSettings, recording.callCount())
value = RecordedCallNodeContent(currentCallRecord, renderSettings, recording.callCount(), recording.rootDuration())

if (loaded) {
val newChildren = currentCallRecord.childrenCallIds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
package com.ulyp.ui.elements.recording.tree

import com.ulyp.storage.tree.CallRecord
import com.ulyp.ui.RenderSettings
import com.ulyp.ui.settings.RecordedCallWeightType
import javafx.scene.layout.Region
import java.time.Duration

/**
* A background rectangle which approximately shows how many nested calls every call tree node has.
* Every call in a call tree has weight. It's drawn as a rectangle in a background.
* It represents how much time/calls current call's subtree has in comparison to other calls. Currently, weight can
* be either time spent or call count.
*/
class RecordedCallWeight(node: CallRecord, totalNodeCountInTree: Int) : Region() {
class RecordedCallWeight(renderSettings: RenderSettings, node: CallRecord, totalNodeCountInTree: Int, rootDuration: Duration) : Region() {
init {
val width = (600.0 * node.subtreeSize / totalNodeCountInTree).toInt()
// TODO move 600.0 to settings

val width: Int = when(renderSettings.recordedCallWeightType) {
RecordedCallWeightType.TIME ->
if (rootDuration.nano > 0) {
(600.0 * node.nanosDuration / rootDuration.nano).toInt()
} else {
// timestamps not enabled, do not draw rectangle
0
}
RecordedCallWeightType.CALLS ->
(600.0 * node.subtreeSize / totalNodeCountInTree).toInt()
}


styleClass += "ulyp-call-tree-call-node"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ulyp.ui.settings

/**
* Every call in a call tree has weight. It's drawn as a rectangle in a background.
* It represents how much time/calls current call's subtree has in comparison to other calls. Currently, weight can
* be either time spent or call count.
*/
enum class RecordedCallWeightType {
TIME,
CALLS
}
7 changes: 7 additions & 0 deletions ulyp-ui/src/main/kotlin/com/ulyp/ui/settings/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Settings {
val recordingTreeBoldElements: BooleanProperty = SimpleBooleanProperty(true)
@Serializable(with = IntegerPropertySerializer::class)
val recordingListSpacing = SimpleIntegerProperty(3)
@Serializable(with = StringPropertySerializer::class)
val recordedCallWeightType: StringProperty = SimpleStringProperty(RecordedCallWeightType.CALLS.name)

fun addListener(listener: ChangeListener<Any>) {
sourceCodeViewerEnabled.addListener(listener)
Expand All @@ -47,5 +49,10 @@ class Settings {
recordingListShowThreads.addListener(listener)
recordingTreeBoldElements.addListener(listener)
recordingListSpacing.addListener(listener)
recordedCallWeightType.addListener(listener)
}

fun getRecordedCallWeightType(): RecordedCallWeightType {
return RecordedCallWeightType.valueOf(recordedCallWeightType.get())
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.ulyp.ui.settings

import javafx.beans.property.IntegerPropertyBase
import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty

class SimpleIntegerProperty(initialValue: Int) : IntegerPropertyBase(initialValue) {

Expand All @@ -13,12 +11,4 @@ class SimpleIntegerProperty(initialValue: Int) : IntegerPropertyBase(initialValu
override fun getName(): String? {
return null
}

fun toStringProperty(): StringProperty {
val stringProp = SimpleStringProperty(this.get().toString())
this.addListener { _, oldValue, newValue ->
stringProp.set(newValue.toString())
}
return stringProp
}
}
27 changes: 27 additions & 0 deletions ulyp-ui/src/main/resources/SettingsView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,33 @@
<Insets left="20.0" top="20.0"/>
</VBox.margin>
</HBox>
<HBox prefHeight="20.0" prefWidth="200.0">
<children>
<Label text="Recording tree">
<HBox.margin>
<Insets left="20.0"/>
</HBox.margin>
<font>
<Font name="System Bold" size="15.0"/>
</font>
</Label>
</children>
<opaqueInsets>
<Insets/>
</opaqueInsets>
<VBox.margin>
<Insets top="40.0"/>
</VBox.margin>
</HBox>
<HBox prefWidth="200.0">
<children>
<Label prefWidth="200.0" text="Call weight*"/>
<ChoiceBox fx:id="recordedCallWeightTypeChoiceBox" prefWidth="200.0"/>
</children>
<VBox.margin>
<Insets left="20.0" top="20.0"/>
</VBox.margin>
</HBox>
</children>
</VBox>
</children>
Expand Down

0 comments on commit ab91b7e

Please sign in to comment.