Skip to content

Commit

Permalink
Merge pull request #86 from Grigory-Rylov/fix_finding_only_in_current…
Browse files Browse the repository at this point in the history
…_thread

Fix finding only in current thread
  • Loading branch information
Grigory-Rylov committed Aug 10, 2022
2 parents 92fad8b + 21fdfac commit b2036fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
39 changes: 32 additions & 7 deletions core/src/main/java/com/github/grishberg/profiler/ui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public enum StartMode {
private final JLabel foundInfo;
private final NewBookmarkDialog newBookmarkDialog;
private final LoadingDialog loadingDialog;
private final LoadingDialog searchingDialog;
private final JavaMethodsRecorderDialogView methodTraceRecordDialog;
private final ScaleRangeDialog scaleRangeDialog;
private final SwitchThreadButton switchThreadsButton;
Expand Down Expand Up @@ -290,9 +291,12 @@ public void focusProfileElement(@NotNull ProfileData selectedElement) {
newBookmarkDialog = new NewBookmarkDialog(frame);
newBookmarkDialog.pack();

loadingDialog = new LoadingDialog(frame, appIconDelegate, allowModalDialogs);
loadingDialog = new LoadingDialog("Loading...", frame, appIconDelegate, allowModalDialogs);
loadingDialog.pack();

searchingDialog = new LoadingDialog("Searching...", frame, appIconDelegate, true);
searchingDialog.pack();

methodTraceRecordDialog = viewFactory.createJavaMethodsRecorderDialog(
coroutineScope, coroutinesDispatchers, frame, settings, log);

Expand Down Expand Up @@ -855,11 +859,14 @@ private void findMethods() {
}

methodsFinder.findMethods(resultContainer.getResult(), textToFind, !caseInsensitiveToggle.isSelected());
showSearchingProgressDialog();
}

private class MethodsFinderListener implements Finder.FindResultListener {
@Override
public void onFindDone(@NotNull Finder.FindResult findResult) {
hideSerchingProgressDialog();

if (findResult.getThreadResults().isEmpty()) {
JOptionPane.showMessageDialog(chart, "Not found");
return;
Expand All @@ -876,7 +883,12 @@ public void onFindDone(@NotNull Finder.FindResult findResult) {
return;
}

onResultsFoundInCurrentAndOtherThreads(threadFindResult, findResult);
if (findResult.getThreadResults().size() > 1) {
onResultsFoundInCurrentAndOtherThreads(threadFindResult, findResult);
return;
}

onResultsFoundInCurrentThread(threadFindResult);
}
}

Expand All @@ -891,12 +903,15 @@ private void onResultsFoundInOtherThreads(Finder.FindResult findResult) {

private void onResultsFoundInCurrentAndOtherThreads(Finder.ThreadFindResult threadFindResult, Finder.FindResult findResult) {
JOptionPane.showMessageDialog(frame, "Found results in multiple threads: \n" +
findResult.generateFoundThreadNames() +
"\"\n");
findResult.generateFoundThreadNames());

chart.renderFoundItems(threadFindResult);
}

private void onResultsFoundInCurrentThread(Finder.ThreadFindResult threadFindResult) {
chart.renderFoundItems(threadFindResult);
}

@Override
public void onSelected(int count, int selectedIndex, ProfileData selectedElement) {
foundInfo.setText(String.format("found %d, current %d", count, selectedIndex));
Expand Down Expand Up @@ -1047,13 +1062,13 @@ public void openTraceFile(File file) {
public void openTraceFile(File file, SystraceRecordResult systraceRecords) {
currentOpenedFile = file;
new ParseWorker(file, systraceRecords).execute();
showProgressDialog(file);
showProgressDialog();
}

public void openCompareTraceFile(File file, OpenTraceToCompareCallback callback) {
currentOpenedFile = file;
new ParseToCompareWorker(file, callback).execute();
showProgressDialog(file);
showProgressDialog();
}

public void highlightCompareResult(ComparableProfileData rootCompareData) {
Expand Down Expand Up @@ -1098,7 +1113,7 @@ public void fitSelectedElement() {
chart.fitSelectedElement();
}

private void showProgressDialog(File file) {
private void showProgressDialog() {
loadingDialog.setLocationRelativeTo(frame);
loadingDialog.setVisible(true);
}
Expand All @@ -1107,6 +1122,16 @@ private void hideProgressDialog() {
loadingDialog.setVisible(false);
}

private void showSearchingProgressDialog() {
searchingDialog.setLocationRelativeTo(frame);
searchingDialog.setVisible(true);
}

private void hideSerchingProgressDialog() {
searchingDialog.setVisible(false);
}


public void showErrorDialog(String title, String errorMessage) {
JOptionPane.showMessageDialog(
frame,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import javax.swing.JPanel
import javax.swing.WindowConstants

class LoadingDialog(
title: String = "Loading...",
owner: Frame,
appIconDelegate: AppIconDelegate,
allowModalDialogs: Boolean,
Expand All @@ -23,7 +24,7 @@ class LoadingDialog(
val iconLabel = JLabel()
appIconDelegate.updateLoadingIcon(iconLabel)

val label = JLabel("Loading...")
val label = JLabel(title)
label.setHorizontalAlignment(JLabel.CENTER);
iconLabel.setHorizontalAlignment(JLabel.CENTER);
panel.add(iconLabel, BorderLayout.CENTER)
Expand Down

0 comments on commit b2036fe

Please sign in to comment.