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

Improvements #118

Merged
merged 5 commits into from
Aug 24, 2024
Merged
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 @@ -93,6 +93,8 @@ public class CallTracePanel extends JPanel
private int currentFocusedFoundElement = -1;
private int currentSelectedElement = -1;
private final ArrayList<ProfileRectangle> foundItems = new ArrayList<>();
private double foundTotalGlobalDuration;
private double foundTotalThreadDuration;
private final CalledStacktrace calledStacktrace;
private Grid scale;
private final SettingsFacade settings;
Expand Down Expand Up @@ -945,10 +947,15 @@ public void renderFoundItems(Finder.ThreadFindResult threadFindResult) {

currentFocusedFoundElement = 0;
ProfileRectangle element = foundItems.get(currentFocusedFoundElement);

foundTotalGlobalDuration = threadFindResult.getTotalGlobalDuration();
foundTotalThreadDuration = threadFindResult.getTotalThreadDuration();
foundNavigationListener.onSelected(
foundItems.size(),
currentFocusedFoundElement,
element.profileData
element.profileData,
foundTotalGlobalDuration,
foundTotalThreadDuration
);
zoomAndPanDelegate.fitZoom(element, FIT_PADDING, ZoomAndPanDelegate.VerticalAlign.ENABLED);

Expand Down Expand Up @@ -1070,7 +1077,9 @@ private void focusFoundItem(int currentFocusedFoundElement) {
foundNavigationListener.onSelected(
foundItems.size(),
currentFocusedFoundElement,
found.profileData
found.profileData,
foundTotalGlobalDuration,
foundTotalThreadDuration
);
}

Expand Down
10 changes: 8 additions & 2 deletions core/src/main/java/com/github/grishberg/profiler/chart/Finder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class Finder(
val shouldEndsWithText: Boolean = textToFind.endsWith("()")
val targetString = prepareTextToFind(shouldEndsWithText, textToFind, ignoreCase)

var totalGlobalDuration = 0.0
var totalThreadDuration = 0.0
val foundMethods = mutableSetOf<ProfileData>()
for (i in profileList.indices) {
val currentMethod = profileList[i]
Expand All @@ -144,11 +146,13 @@ class Finder(
)
if (isEquals) {
foundMethods.add(currentMethod)
totalGlobalDuration = currentMethod.globalEndTimeInMillisecond - currentMethod.globalStartTimeInMillisecond
totalThreadDuration = currentMethod.threadEndTimeInMillisecond - currentMethod.threadStartTimeInMillisecond
}
}
if (foundMethods.isNotEmpty()) {
val threadItem = analyzerResult.threads.find { it.threadId == threadId }!!
result.add(ThreadFindResult(foundMethods, threadId, threadItem))
result.add(ThreadFindResult(foundMethods, threadId, threadItem, totalGlobalDuration, totalThreadDuration))
}
}

Expand Down Expand Up @@ -191,7 +195,9 @@ class Finder(
data class ThreadFindResult(
val foundResult: Set<ProfileData>,
val threadId: Int,
val threadItem: ThreadItem
val threadItem: ThreadItem,
val totalGlobalDuration: Double,
val totalThreadDuration: Double
) {
fun hasMethod(method: ProfileData) = foundResult.contains(method)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.github.grishberg.profiler.chart

interface FoundNavigationListener<T> {
fun onSelected(count: Int, selectedIndex: Int, selectedElement: T)
fun onSelected(count: Int, selectedIndex: Int, selectedElement: T,
totalGlobalDuration: Double, totalThreadDuration: Double)
fun onNavigatedOverLastItem()
fun onNavigatedOverFirstItem()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ import com.github.grishberg.profiler.ui.dialogs.CloseByEscapeDialog
import java.awt.Color
import java.awt.Dimension
import java.awt.Frame
import java.awt.Point
import java.awt.event.ActionEvent
import java.awt.event.KeyEvent
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.*
import javax.swing.AbstractAction
import javax.swing.JScrollPane
import javax.swing.JTable
import javax.swing.JViewport
import javax.swing.KeyStroke
import javax.swing.ListSelectionModel
import kotlin.math.max


private const val THREAD_NAME_WIDTH = 180
private const val SELECT_ACTION = "Select"

Expand All @@ -32,6 +37,15 @@ class ThreadsViewDialog(
var selectedThreadItem: ThreadItem? = null
private set

private var _selectedRow: Int = -1
private var _verticalScrollPosition: Int = 0

val selectedRow: Int
get() = _selectedRow

val scrollPosition: Int
get() = _verticalScrollPosition

private val table = object : JTable(model) {
override fun getRowHeight(): Int {
return max(super.getRowHeight(), PREVIEW_IMAGE_HEIGHT)
Expand All @@ -41,6 +55,7 @@ class ThreadsViewDialog(
return false
}
}
private val scrollPane: JScrollPane

init {
controller.view = this
Expand All @@ -66,13 +81,14 @@ class ThreadsViewDialog(
table.showHorizontalLines = true
table.gridColor = Color.GRAY

val scrollPane = JScrollPane(table)
scrollPane = JScrollPane(table)
scrollPane.preferredSize = Dimension(PREVIEW_IMAGE_WIDTH + THREAD_NAME_WIDTH + 32, 600)
add(scrollPane)
pack()
}

private inner class EnterAction : AbstractAction() {

override fun actionPerformed(e: ActionEvent) {
val selected = table.selectedRow
if (selected < 0) {
Expand All @@ -83,6 +99,9 @@ class ThreadsViewDialog(
}

private fun setResultAndClose(selected: Int) {
val viewport = scrollPane.viewport
_selectedRow = selected
_verticalScrollPosition = viewport.viewPosition.y;
val modelRowIndex = table.convertRowIndexToModel(selected)
selectedThreadItem = model.getThreadInfo(modelRowIndex)
isVisible = false
Expand All @@ -91,4 +110,13 @@ class ThreadsViewDialog(
override fun showThreads(threads: List<ThreadItem>) {
model.setData(threads)
}

fun restoreSelection(selectedRow: Int, verticalScrollPosition: Int) {
if (selectedRow < 0) {
return
}
table.setRowSelectionInterval(selectedRow, selectedRow)
val viewport: JViewport = scrollPane.viewport
viewport.viewPosition = Point(0, verticalScrollPosition)
}
}
Loading
Loading