Skip to content

Commit

Permalink
Added Quick Filtering on FQMN
Browse files Browse the repository at this point in the history
Allows to add an extra filter on classname+"."+methodname without having
to go into the Filter Creation dialog.
  • Loading branch information
arickp authored and arickp committed Jan 2, 2017
1 parent 322d0b0 commit 524f650
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static com.insightfullogic.honest_profiler.core.filters.Filters.parse;
import static java.util.Collections.emptyList;

import java.util.ArrayList;
import java.util.List;

public class ProfileFilter implements ProfileListener
Expand All @@ -48,6 +49,10 @@ public void updateFilters(String filterDescription)
filters = parse(filterDescription);
}

public List<Filter> getFilters() {
return new ArrayList<>(filters);
}

public void setFilters(List<Filter> filters)
{
this.filters = filters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.FUNNEL_ACTIVE_16;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.viewFor;

import java.util.ArrayList;
import java.util.List;

import com.insightfullogic.honest_profiler.core.collector.FlatProfileEntry;
import com.insightfullogic.honest_profiler.core.filters.Filter;
import com.insightfullogic.honest_profiler.core.filters.ProfileFilter;
import com.insightfullogic.honest_profiler.core.filters.StringFilter;
import com.insightfullogic.honest_profiler.core.profiles.Profile;
import com.insightfullogic.honest_profiler.ports.javafx.controller.filter.FilterDialogController;
import com.insightfullogic.honest_profiler.ports.javafx.model.ApplicationContext;
Expand All @@ -58,6 +61,7 @@
import javafx.scene.control.MenuItem;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
Expand All @@ -70,7 +74,10 @@ public class FlatViewController extends ProfileViewController<Profile>
private Button compareButton;
@FXML
private Button exportButton;

@FXML
private TextField quickFilterText;
@FXML
private Button quickFilterButton;
@FXML
private TableView<FlatProfileEntry> flatProfileView;
@FXML
Expand All @@ -94,6 +101,7 @@ public class FlatViewController extends ProfileViewController<Profile>
private ObjectProperty<FilterSpecification> filterSpec;

private ProfileFilter currentFilter;
private StringFilter quickFilter;

@FXML
protected void initialize()
Expand All @@ -103,6 +111,8 @@ protected void initialize()
info(filterButton, "Specify filters restricting the visible entries");
info(compareButton, "Click to select another open profile to compare this profile against");
info(exportButton, "Export the visible entries to a CSV file");
info(quickFilterText, "Specify text for quickly filtering the Fully Qualified Method Name (= <fully_qualified_class_name>.<method_name>)");
info(quickFilterButton, "Apply the Quick Filter");
info(flatProfileView, "Shows methods and their Self and Total usage percentages");

currentFilter = new ProfileFilter();
Expand Down Expand Up @@ -188,6 +198,22 @@ private void initializeFilter()
filterButton.setTooltip(new Tooltip("Specify filters"));
filterButton
.setOnAction(event -> filterSpec.set(filterDialogController.showAndWait().get()));

quickFilterButton.setGraphic(viewFor(FUNNEL_16));
quickFilterButton
.setTooltip(new Tooltip("Specify quick filter on classname + method name"));
quickFilterButton.setOnAction(event -> applyQuickFilter());
}

private void applyQuickFilter()
{
String input = quickFilterText.getText();
this.quickFilter = input.isEmpty() ? null
: new StringFilter(
Filter.Mode.CONTAINS,
frame -> frame.getClassName() + "." + frame.getMethodName(),
input);
refresh(getTarget());
}

private void initializeTable()
Expand Down Expand Up @@ -223,7 +249,7 @@ protected void refresh(Profile profile)
return;
}

CopyAndFilterProfile task = new CopyAndFilterProfile(profile, currentFilter);
CopyAndFilterProfile task = new CopyAndFilterProfile(profile, getAdjustedProfileFilter());
task.setOnSucceeded(state ->
{
flatProfile.clear();
Expand All @@ -233,6 +259,20 @@ protected void refresh(Profile profile)
appCtx().getExecutorService().execute(task);
}

private ProfileFilter getAdjustedProfileFilter()
{
if (quickFilter == null)
{
return currentFilter;
}
else
{
List<Filter> filters = new ArrayList<>();
filters.add(quickFilter);
return new ProfileFilter(filters);
}
}

// Compare Helper Methods

private void refreshContextMenu(ContextMenu menu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
import static com.insightfullogic.honest_profiler.ports.javafx.view.Rendering.renderMethod;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Rendering.renderPercentage;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import com.insightfullogic.honest_profiler.core.filters.Filter;
import com.insightfullogic.honest_profiler.core.filters.ProfileFilter;
import com.insightfullogic.honest_profiler.core.filters.StringFilter;
import com.insightfullogic.honest_profiler.core.profiles.Profile;
import com.insightfullogic.honest_profiler.core.profiles.ProfileNode;
import com.insightfullogic.honest_profiler.ports.javafx.controller.filter.FilterDialogController;
Expand All @@ -53,6 +57,7 @@
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
Expand All @@ -67,6 +72,10 @@ public class TreeViewController extends ProfileViewController<Profile>
private Button expandAllButton;
@FXML
private Button collapseAllButton;
@FXML
private TextField quickFilterText;
@FXML
private Button quickFilterButton;

@FXML
private TreeTableView<ProfileNode> treeView;
Expand All @@ -83,6 +92,7 @@ public class TreeViewController extends ProfileViewController<Profile>
private ObjectProperty<FilterSpecification> filterSpec;

private ProfileFilter currentFilter;
private StringFilter quickFilter;

private RootNodeAdapter rootNode;

Expand All @@ -94,6 +104,10 @@ private void initialize()
info(filterButton, "Specify filters restricting the visible entries");
info(expandAllButton, "Expand all trees");
info(collapseAllButton, "Collapse all trees");
info(
quickFilterText,
"Specify text for quickly filtering the Fully Qualified Method Name (= <fully_qualified_class_name>.<method_name>)");
info(quickFilterButton, "Apply the Quick Filter");
info(
treeView,
"Shows the Threads in the profiled application. Right-click any node for expand/collapse and export options.");
Expand Down Expand Up @@ -131,6 +145,11 @@ private void initialize()
collapseAllButton.setOnAction(
event -> treeView.getRoot().getChildren().stream().forEach(TreeUtil::collapseFully));

quickFilterButton.setGraphic(viewFor(FUNNEL_16));
quickFilterButton
.setTooltip(new Tooltip("Specify quick filter on classname + method name"));
quickFilterButton.setOnAction(event -> applyQuickFilter());

treeView.setRoot(rootNode);

totalColumn.setCellValueFactory(data -> wrapDouble(data, ProfileNode::getTotalTimeShare));
Expand Down Expand Up @@ -190,6 +209,17 @@ private StringProperty wrapDouble(CellDataFeatures<ProfileNode, String> data,
? renderPercentage(accessor.apply(data.getValue().getValue())) : "");
}

private void applyQuickFilter()
{
String input = quickFilterText.getText();
this.quickFilter = input.isEmpty() ? null
: new StringFilter(
Filter.Mode.CONTAINS,
frame -> frame.getClassName() + "." + frame.getMethodName(),
input);
refresh(getTarget());
}

@Override
protected void refresh(Profile profile)
{
Expand All @@ -198,8 +228,22 @@ protected void refresh(Profile profile)
return;
}

CopyAndFilterProfile task = new CopyAndFilterProfile(profile, currentFilter);
CopyAndFilterProfile task = new CopyAndFilterProfile(profile, getAdjustedProfileFilter());
task.setOnSucceeded(state -> rootNode.update(task.getValue().getTrees()));
appCtx().getExecutorService().execute(task);
}

private ProfileFilter getAdjustedProfileFilter()
{
if (quickFilter == null)
{
return currentFilter;
}
else
{
List<Filter> filters = new ArrayList<>();
filters.add(quickFilter);
return new ProfileFilter(filters);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
Expand All @@ -19,6 +20,8 @@
<ColumnConstraints hgrow="SOMETIMES" maxWidth="25.0" minWidth="25.0" prefWidth="25.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="25.0" minWidth="25.0" prefWidth="25.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="25.0" minWidth="25.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="25.0" minWidth="25.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="200.0" minWidth="25.0" prefWidth="200.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="25.0" minHeight="25.0" prefHeight="25.0" vgrow="SOMETIMES" />
Expand All @@ -27,6 +30,12 @@
<Button fx:id="filterButton" alignment="CENTER" maxHeight="20.0" maxWidth="20.0" minHeight="20.0" minWidth="20.0" mnemonicParsing="false" prefHeight="20.0" prefWidth="20.0" />
<Button fx:id="compareButton" alignment="CENTER" maxHeight="20.0" maxWidth="20.0" minHeight="20.0" minWidth="20.0" mnemonicParsing="false" prefHeight="20.0" prefWidth="20.0" GridPane.columnIndex="1" />
<Button fx:id="exportButton" alignment="CENTER" maxHeight="20.0" maxWidth="20.0" minHeight="20.0" minWidth="20.0" mnemonicParsing="false" prefHeight="20.0" prefWidth="20.0" GridPane.columnIndex="2" />
<HBox maxHeight="20.0" minHeight="20.0" prefHeight="20.0" GridPane.columnIndex="4" GridPane.vgrow="NEVER">
<children>
<TextField fx:id="quickFilterText" maxHeight="20.0" maxWidth="1.7976931348623157E308" minHeight="20.0" prefHeight="20.0" promptText="Quick FQMN Filter" HBox.hgrow="ALWAYS" />
<Button fx:id="quickFilterButton" alignment="CENTER" maxHeight="20.0" maxWidth="20.0" minHeight="20.0" minWidth="20.0" mnemonicParsing="false" prefHeight="20.0" prefWidth="20.0" HBox.hgrow="NEVER" />
</children>
</HBox>
</children>
</GridPane>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TreeTableColumn?>
<?import javafx.scene.control.TreeTableView?>
<?import javafx.scene.layout.ColumnConstraints?>
Expand All @@ -10,7 +11,7 @@
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>

<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.insightfullogic.honest_profiler.ports.javafx.controller.TreeViewController">
<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.TreeViewController">
<children>
<HBox alignment="CENTER_LEFT" maxHeight="25.0" maxWidth="1.7976931348623157E308" minHeight="25.0" prefHeight="25.0" spacing="6.0">
<children>
Expand All @@ -19,6 +20,8 @@
<ColumnConstraints hgrow="SOMETIMES" maxWidth="25.0" minWidth="25.0" prefWidth="25.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="25.0" minWidth="25.0" prefWidth="25.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="25.0" minWidth="25.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="25.0" minWidth="25.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="200.0" minWidth="25.0" prefWidth="200.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="25.0" minHeight="25.0" prefHeight="25.0" vgrow="SOMETIMES" />
Expand All @@ -27,6 +30,12 @@
<Button fx:id="filterButton" alignment="CENTER" maxHeight="20.0" maxWidth="20.0" minHeight="20.0" minWidth="20.0" mnemonicParsing="false" prefHeight="20.0" prefWidth="20.0" GridPane.hgrow="NEVER" GridPane.vgrow="NEVER" />
<Button fx:id="expandAllButton" maxHeight="20.0" maxWidth="20.0" minHeight="20.0" minWidth="20.0" mnemonicParsing="false" prefHeight="20.0" prefWidth="20.0" GridPane.columnIndex="1" GridPane.hgrow="NEVER" GridPane.vgrow="NEVER" />
<Button fx:id="collapseAllButton" maxHeight="20.0" maxWidth="20.0" minHeight="20.0" minWidth="20.0" mnemonicParsing="false" prefHeight="20.0" prefWidth="20.0" GridPane.columnIndex="2" GridPane.hgrow="NEVER" GridPane.vgrow="NEVER" />
<HBox maxHeight="20.0" minHeight="20.0" prefHeight="20.0" GridPane.columnIndex="4">
<children>
<TextField fx:id="quickFilterText" maxHeight="20.0" maxWidth="1.7976931348623157E308" minHeight="20.0" prefHeight="20.0" promptText="Quick FQMN Filter" HBox.hgrow="ALWAYS" />
<Button fx:id="quickFilterButton" alignment="CENTER" maxHeight="20.0" maxWidth="20.0" minHeight="20.0" minWidth="20.0" mnemonicParsing="false" prefHeight="20.0" prefWidth="20.0" HBox.hgrow="NEVER" />
</children>
</HBox>
</children>
</GridPane>
</children>
Expand Down

0 comments on commit 524f650

Please sign in to comment.