mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
1746 trick view variable search causes large spike in cpu usage (#1786)
* Add new "greedy search" option to toggle multi-threaded variable search * Back down to a single thread * Fixed a typo. --------- Co-authored-by: Hong Chen <hong.chen-1@nasa.gov>
This commit is contained in:
parent
c007cfc88a
commit
d34844e76c
@ -115,7 +115,8 @@ public class SearchPanel extends JXPanel {
|
|||||||
listModel.clear();
|
listModel.clear();
|
||||||
searcher.search(textField.getText().trim(),
|
searcher.search(textField.getText().trim(),
|
||||||
caseSensitiveCheckBox.isSelected(),
|
caseSensitiveCheckBox.isSelected(),
|
||||||
regularExpressionCheckBox.isSelected());
|
regularExpressionCheckBox.isSelected(),
|
||||||
|
greedySearchCheckBox.isSelected());
|
||||||
if (searcher.elementCount == 0) {
|
if (searcher.elementCount == 0) {
|
||||||
progressBar.setIndeterminate(true);
|
progressBar.setIndeterminate(true);
|
||||||
}
|
}
|
||||||
@ -136,6 +137,12 @@ public class SearchPanel extends JXPanel {
|
|||||||
setToolTipText("Toggle regular expression searching.");
|
setToolTipText("Toggle regular expression searching.");
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
/** toggles case-insensitive searching */
|
||||||
|
JCheckBox greedySearchCheckBox = new JCheckBox("Greedy Search") {{
|
||||||
|
setName("greedySearchCheckBox");
|
||||||
|
setToolTipText("Toggle multi-threaded search (Warning: may cause overruns).");
|
||||||
|
}};
|
||||||
|
|
||||||
/** search results list model */
|
/** search results list model */
|
||||||
EfficientListModel listModel = new EfficientListModel();
|
EfficientListModel listModel = new EfficientListModel();
|
||||||
|
|
||||||
@ -227,6 +234,7 @@ public class SearchPanel extends JXPanel {
|
|||||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||||
add(caseSensitiveCheckBox);
|
add(caseSensitiveCheckBox);
|
||||||
add(regularExpressionCheckBox);
|
add(regularExpressionCheckBox);
|
||||||
|
add(greedySearchCheckBox);
|
||||||
}});
|
}});
|
||||||
}}, constraints);
|
}}, constraints);
|
||||||
|
|
||||||
@ -306,6 +314,7 @@ public class SearchPanel extends JXPanel {
|
|||||||
textField.setEnabled(enabled);
|
textField.setEnabled(enabled);
|
||||||
caseSensitiveCheckBox.setEnabled(enabled);
|
caseSensitiveCheckBox.setEnabled(enabled);
|
||||||
regularExpressionCheckBox.setEnabled(enabled);
|
regularExpressionCheckBox.setEnabled(enabled);
|
||||||
|
greedySearchCheckBox.setEnabled(enabled);
|
||||||
list.setEnabled(enabled);
|
list.setEnabled(enabled);
|
||||||
list.setComponentPopupMenu(enabled ? popupMenu : null);
|
list.setComponentPopupMenu(enabled ? popupMenu : null);
|
||||||
}
|
}
|
||||||
|
@ -89,9 +89,10 @@ public class Searcher {
|
|||||||
* @param targetText the text for which to search
|
* @param targetText the text for which to search
|
||||||
* @param caseSensitive enables case sensitive searching
|
* @param caseSensitive enables case sensitive searching
|
||||||
* @param regularExpression enables regular expression searching
|
* @param regularExpression enables regular expression searching
|
||||||
|
* @param greedSearch enabled multi-threaded search
|
||||||
*/
|
*/
|
||||||
public void search(final String targetText, final boolean caseSensitive,
|
public void search(final String targetText, final boolean caseSensitive,
|
||||||
final boolean regularExpression) {
|
final boolean regularExpression, final boolean greedySearch) {
|
||||||
|
|
||||||
final SearchFunction searchFunction = regularExpression ?
|
final SearchFunction searchFunction = regularExpression ?
|
||||||
|
|
||||||
@ -124,7 +125,11 @@ public class Searcher {
|
|||||||
|
|
||||||
cancelSearch();
|
cancelSearch();
|
||||||
count = 0;
|
count = 0;
|
||||||
threads = Runtime.getRuntime().availableProcessors();
|
if (greedySearch) {
|
||||||
|
threads = Runtime.getRuntime().availableProcessors();
|
||||||
|
} else {
|
||||||
|
threads = 1;
|
||||||
|
}
|
||||||
propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "progress", 0, 0));
|
propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "progress", 0, 0));
|
||||||
final ConcurrentLinkedQueue<SieTemplate> roots = new ConcurrentLinkedQueue<SieTemplate>(rootTemplates);
|
final ConcurrentLinkedQueue<SieTemplate> roots = new ConcurrentLinkedQueue<SieTemplate>(rootTemplates);
|
||||||
executorService = Executors.newFixedThreadPool(threads);
|
executorService = Executors.newFixedThreadPool(threads);
|
||||||
|
Loading…
Reference in New Issue
Block a user