Skip to content

Commit dded8c6

Browse files
committed
#97 all threads dialog
1 parent 1eb446d commit dded8c6

9 files changed

Lines changed: 109 additions & 24 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.grishberg.profiler.analyzer
2+
3+
import com.github.grishberg.profiler.core.AnalyzerResult
4+
import java.io.File
5+
6+
class AllThreadsMethodsReportGenerator(
7+
private val data: AnalyzerResult,
8+
) : ReportGenerator {
9+
10+
override fun generate(
11+
file: File, onlyConstructor: Boolean, minimumDurationInMs: Int, packageFilter: String
12+
) {
13+
val baseDir = file.path
14+
15+
data.threads.forEach { threadItem ->
16+
val profileData = data.data[threadItem.threadId] ?: return
17+
val reportFile = File(baseDir, normalizeFileName(threadItem.name))
18+
val singleThreadReportGenerator = FlatMethodsReportGenerator(profileData)
19+
singleThreadReportGenerator.generate(
20+
reportFile, onlyConstructor, minimumDurationInMs, packageFilter
21+
)
22+
}
23+
}
24+
25+
private fun normalizeFileName(threadName: String): String {
26+
return threadName.replace("/", "_").replace("\\", "_").replace(":", "_")
27+
}
28+
}

core/src/main/java/com/github/grishberg/profiler/analyzer/FlatMethodsReportGenerator.kt

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,51 @@
11
package com.github.grishberg.profiler.analyzer
22

3-
import com.github.grishberg.profiler.core.ProfileData
43
import com.github.grishberg.profiler.chart.BookmarksRectangle
54
import com.github.grishberg.profiler.chart.CallTracePanel
5+
import com.github.grishberg.profiler.core.ProfileData
66
import java.io.BufferedWriter
77
import java.io.File
88
import java.io.FileOutputStream
99
import java.io.OutputStreamWriter
1010

1111
class FlatMethodsReportGenerator(
12-
private val data: CallTracePanel.ProfilerPanelData
12+
private val profileData: List<ProfileData>,
13+
private val markers: List<BookmarksRectangle> = emptyList(),
1314
) : ReportGenerator {
1415

15-
override fun generate(file: File, onlyConstructor: Boolean, minimumDurationInMs: Int, packageFilter: String) {
16+
override fun generate(
17+
file: File,
18+
onlyConstructor: Boolean,
19+
minimumDurationInMs: Int,
20+
packageFilter: String
21+
) {
1622
val fos = FileOutputStream(file)
1723

1824
BufferedWriter(OutputStreamWriter(fos)).use { bw ->
1925
bw.write("name\tglobal time\tthread time\tglobal self time\tthread self time")
2026
bw.newLine()
2127

22-
data.profileData.forEach {
23-
val threadDuration =
24-
it.profileData.threadEndTimeInMillisecond - it.profileData.threadStartTimeInMillisecond
25-
val globalDuration =
26-
it.profileData.globalEndTimeInMillisecond - it.profileData.globalStartTimeInMillisecond
27-
if (threadDuration > minimumDurationInMs && (!onlyConstructor || isConstructor(it.profileData.name)) &&
28-
(packageFilter.isEmpty() || it.profileData.name.startsWith(packageFilter))) {
28+
profileData.forEach {
29+
val threadDuration = it.threadEndTimeInMillisecond - it.threadStartTimeInMillisecond
30+
val globalDuration = it.globalEndTimeInMillisecond - it.globalStartTimeInMillisecond
31+
if (threadDuration > minimumDurationInMs && (!onlyConstructor || isConstructor(it.name)) && (packageFilter.isEmpty() || it.name.startsWith(
32+
packageFilter
33+
))
34+
) {
2935
bw.write(
3036
String.format(
3137
"%s\t%.3f\t%.3f\t%.3f\t%.3f",
32-
it.profileData.name, globalDuration, threadDuration,
33-
it.profileData.globalSelfTime, it.profileData.threadSelfTime
38+
it.name,
39+
globalDuration,
40+
threadDuration,
41+
it.globalSelfTime,
42+
it.threadSelfTime
3443
)
3544
)
3645
bw.newLine()
3746
}
3847

39-
val markerRectangle = findMarkerForElement(it.profileData)
48+
val markerRectangle = findMarkerForElement(it)
4049
if (markerRectangle != null) {
4150
bw.write("<marker>: ${markerRectangle.name}")
4251
bw.newLine()
@@ -46,7 +55,7 @@ class FlatMethodsReportGenerator(
4655
}
4756

4857
private fun findMarkerForElement(profileData: ProfileData): BookmarksRectangle? {
49-
for (marker in data.markersData) {
58+
for (marker in markers) {
5059
if (marker.isForElement(profileData)) {
5160
return marker
5261
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package com.github.grishberg.profiler.analyzer
22

3+
import com.github.grishberg.profiler.core.ProfileData
34
import java.io.File
45

56
interface ReportGenerator {
6-
fun generate(file: File, onlyConstructor: Boolean, minimumDurationInMs: Int, packageFilter: String)
7+
fun generate(
8+
file: File,
9+
onlyConstructor: Boolean,
10+
minimumDurationInMs: Int,
11+
packageFilter: String
12+
)
713
}

core/src/main/java/com/github/grishberg/profiler/ui/KeyBinder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class KeyBinder(
322322

323323
private inner class GenerateReportsAction : AbstractAction() {
324324
override fun actionPerformed(e: ActionEvent) {
325-
dialogDelegate.showReportsDialog()
325+
dialogDelegate.showCurrentThreadMethodsReportsDialog()
326326
}
327327
}
328328

core/src/main/java/com/github/grishberg/profiler/ui/Main.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.github.grishberg.profiler.ui;
22

3+
import com.github.grishberg.profiler.analyzer.AllThreadsMethodsReportGenerator;
34
import com.github.grishberg.profiler.analyzer.FlatMethodsReportGenerator;
5+
import com.github.grishberg.profiler.analyzer.ReportGenerator;
46
import com.github.grishberg.profiler.chart.*;
57
import com.github.grishberg.profiler.chart.flame.FlameChartController;
68
import com.github.grishberg.profiler.chart.flame.FlameChartDialog;
@@ -492,6 +494,12 @@ private JMenu createFileMenu() {
492494

493495
JMenuItem deleteCurrentFile = new JMenuItem("Delete current file");
494496

497+
JMenuItem generateCurrentThreadMethodsReportFor = new JMenuItem("Current thread methods duration report");
498+
generateCurrentThreadMethodsReportFor.setAccelerator(MenuAcceleratorHelperKt.createControlAccelerator('P'));
499+
500+
JMenuItem generateAllThreadMethodsReportFor = new JMenuItem("All threads methods duration report");
501+
502+
495503
file.add(openFile);
496504
file.add(openFileInNewWindow);
497505
file.add(openMappingFile);
@@ -502,6 +510,10 @@ private JMenu createFileMenu() {
502510
file.addSeparator();
503511
file.add(openTracesDirInExternalFileManager);
504512
file.add(deleteCurrentFile);
513+
file.addSeparator();
514+
file.add(generateCurrentThreadMethodsReportFor);
515+
file.add(generateAllThreadMethodsReportFor);
516+
505517

506518
openFile.addActionListener(arg0 -> showOpenFileChooser(false));
507519
openFileInNewWindow.addActionListener(arg0 -> showOpenFileChooser(true));
@@ -511,6 +523,9 @@ private JMenu createFileMenu() {
511523
exportTraceWithBookmarks.addActionListener(arg0 -> exportTraceWithBookmarks());
512524
openTracesDirInExternalFileManager.addActionListener(arg -> openTracesDirInExternalFileManager());
513525
deleteCurrentFile.addActionListener(arg -> deleteCurrentFile());
526+
generateCurrentThreadMethodsReportFor.addActionListener(arg -> showCurrentThreadMethodsReportsDialog());
527+
generateAllThreadMethodsReportFor.addActionListener(arg -> showAllThreadReportsDialog());
528+
514529
file.addSeparator();
515530
return file;
516531
}
@@ -1142,10 +1157,32 @@ public void showErrorDialog(String title, String errorMessage) {
11421157
}
11431158

11441159
@Override
1145-
public void showReportsDialog() {
1160+
public void showCurrentThreadMethodsReportsDialog() {
1161+
final TraceContainer currentResultContainer = resultContainer;
1162+
if (currentResultContainer == null) {
1163+
log.d("There is no any opened trace file");
1164+
return;
1165+
}
1166+
hoverInfoPanel.hidePanel();
1167+
1168+
FlatMethodsReportGenerator generator = new FlatMethodsReportGenerator(chart.getCurrentThreadMethods(), chart.getData().markersData);
1169+
ReportsGeneratorDialog reportsGeneratorDialog = new ReportsGeneratorDialog(frame, settings, generator);
1170+
reportsGeneratorDialog.pack();
1171+
1172+
reportsGeneratorDialog.setLocationRelativeTo(frame);
1173+
reportsGeneratorDialog.setVisible(true);
1174+
}
1175+
1176+
@Override
1177+
public void showAllThreadReportsDialog() {
1178+
final TraceContainer currentResultContainer = resultContainer;
1179+
if (currentResultContainer == null) {
1180+
log.d("There is no any opened trace file");
1181+
return;
1182+
}
11461183
hoverInfoPanel.hidePanel();
11471184

1148-
FlatMethodsReportGenerator generator = new FlatMethodsReportGenerator(chart.getData());
1185+
final ReportGenerator generator = new AllThreadsMethodsReportGenerator(currentResultContainer.getResult());
11491186
ReportsGeneratorDialog reportsGeneratorDialog = new ReportsGeneratorDialog(frame, settings, generator);
11501187
reportsGeneratorDialog.pack();
11511188

core/src/main/java/com/github/grishberg/profiler/ui/MenuHistoryItems.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import javax.swing.JMenu
77
import javax.swing.JMenuItem
88

99
private const val MAX_HISTORY_SIZE = 10
10-
private const val FILE_MENU_ITEMS_COUNT_BEFORE_HISTORY = 11
10+
private const val FILE_MENU_ITEMS_COUNT_BEFORE_HISTORY = 14
1111

1212

1313
class MenuHistoryItems(

core/src/main/java/com/github/grishberg/profiler/ui/ShowDialogDelegate.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.grishberg.profiler.ui
33
interface ShowDialogDelegate {
44
fun showOpenFileChooser(inNewWindow: Boolean = false)
55
fun showNewTraceDialog(inNewWindow: Boolean = false)
6-
fun showReportsDialog()
6+
fun showCurrentThreadMethodsReportsDialog()
7+
fun showAllThreadReportsDialog()
78
fun showScaleRangeDialog()
89
}

core/src/main/java/com/github/grishberg/profiler/ui/dialogs/ReportsGeneratorDialog.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.github.grishberg.profiler.ui.dialogs
33
import com.github.grishberg.profiler.analyzer.ReportGenerator
44
import com.github.grishberg.profiler.common.JNumberField
55
import com.github.grishberg.profiler.common.settings.SettingsFacade
6-
import com.github.grishberg.profiler.ui.Main
76
import java.awt.Frame
87
import java.awt.GridBagConstraints
98
import java.awt.GridBagLayout
@@ -58,7 +57,7 @@ class ReportsGeneratorDialog(
5857
durationLimit.value = 0
5958
addLabelAndField(
6059
content, labelConstraints, fieldConstraints,
61-
"minimum duration", durationLimit, "If checked - will be exported only constructors"
60+
"minimum duration", durationLimit, "Minimum global time duration in ms"
6261
)
6362

6463
packageFilter = JTextField(20)
@@ -113,7 +112,12 @@ class ReportsGeneratorDialog(
113112
fileToSave = File(fileToSave.absolutePath + ".txt")
114113
}
115114
settings.reportsFileDialogDir = fileToSave.parent
116-
reportsGeneratorDelegate.generate(fileToSave, constructorsCheckbox.isSelected, durationLimit.value as Int, packageFilter.text.trim())
115+
reportsGeneratorDelegate.generate(
116+
fileToSave,
117+
constructorsCheckbox.isSelected,
118+
durationLimit.value as Int,
119+
packageFilter.text.trim()
120+
)
117121
isVisible = false
118122
}
119123
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ studioCompilePath=/Applications/Android Studio.app/Contents
88

99
pluginGroup = com.github.grishberg
1010
pluginName = android-methods-profiler
11-
yampVersion = 24.02.05
11+
yampVersion = 24.02.06
1212

1313
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1414
# for insight into build numbers and IntelliJ Platform versions.

0 commit comments

Comments
 (0)