Skip to content

Commit 7883c95

Browse files
committed
Added ability to manually specify PID to be traced
1 parent 323f9e7 commit 7883c95

File tree

4 files changed

+87
-50
lines changed

4 files changed

+87
-50
lines changed

EnergyDebugger.py

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ def __init__(self, parent=None):
362362
self.graph = False
363363
self.subgraph = False
364364
self.skip_tracing = False
365+
self.pid = None
365366

366367
# Governor control
367368
self.governorRadioButtons = []
@@ -649,6 +650,9 @@ def buttonrun(self):
649650
try:
650651
self.checkrun()
651652

653+
if self.lineEditAppPID.text() != "":
654+
self.pid = self.lineEditAppPID.text()
655+
652656
self.application_name = self.lineEditApplicationName.text()
653657
self.duration = self.doubleSpinBoxDuration.value()
654658
self.events = []
@@ -682,21 +686,20 @@ def buttonrun(self):
682686
for x in range(test_start_value,
683687
test_start_value + no_of_tests):
684688
try:
685-
buttonrunprocess(
686-
self.application_name,
687-
self.governor,
688-
self.duration,
689-
self.events,
690-
self.events_to_process,
691-
self.preamble,
692-
self.subgraph,
693-
self.graph,
694-
self.skip_tracing,
695-
progress_signal=self.changed_progress,
696-
open_func=self.openallresults,
697-
subdir=self.application_name + "/" +
698-
self.governor + "/" + str(x) + "/",
699-
)
689+
buttonrunprocess(self.application_name,
690+
self.governor,
691+
self.duration,
692+
self.events,
693+
self.events_to_process,
694+
self.preamble,
695+
self.subgraph,
696+
self.graph,
697+
self.skip_tracing,
698+
progress_signal=self.changed_progress,
699+
open_func=self.openallresults,
700+
subdir=self.application_name + "/" +
701+
self.governor + "/" + str(x) + "/",
702+
pid=self.pid)
700703
if self.checkBoxTestAutomationPrompt.isChecked():
701704
QMessageBox.information(
702705
self,
@@ -811,22 +814,22 @@ def buttonrunprocess(
811814
progress_signal=None,
812815
open_func=None,
813816
subdir=None,
817+
pid=None,
814818
):
815819

816820
try:
817-
current_debugger = EnergyDebugger(
818-
application=application_name,
819-
governor=governor,
820-
duration=duration,
821-
events=events,
822-
event_count=events_to_process,
823-
preamble=preamble,
824-
graph=graph,
825-
subgraph=subgraph,
826-
skip_tracing=skip_tracing,
827-
progress_signal=progress_signal,
828-
results_subdir=subdir,
829-
)
821+
current_debugger = EnergyDebugger(application=application_name,
822+
governor=governor,
823+
duration=duration,
824+
events=events,
825+
event_count=events_to_process,
826+
preamble=preamble,
827+
graph=graph,
828+
subgraph=subgraph,
829+
skip_tracing=skip_tracing,
830+
progress_signal=progress_signal,
831+
results_subdir=subdir,
832+
pid=pid)
830833
current_debugger.run()
831834
if open_func is not None:
832835
open_func(subdir)
@@ -895,20 +898,19 @@ def run(self):
895898

896899

897900
class EnergyDebugger:
898-
def __init__(
899-
self,
900-
application,
901-
governor,
902-
duration,
903-
events,
904-
event_count,
905-
preamble,
906-
graph,
907-
subgraph,
908-
skip_tracing,
909-
progress_signal,
910-
results_subdir,
911-
):
901+
def __init__(self,
902+
application,
903+
governor,
904+
duration,
905+
events,
906+
event_count,
907+
preamble,
908+
graph,
909+
subgraph,
910+
skip_tracing,
911+
progress_signal,
912+
results_subdir,
913+
pid=None):
912914
self.adb = ADBInterface()
913915
self.application = application
914916
self.governor = governor
@@ -922,13 +924,14 @@ def __init__(
922924
self.skip_tracing = skip_tracing
923925
self.progress_signal = progress_signal
924926
self.results_subdir = results_subdir
927+
self.pid = pid
925928
""" Required objects for tracking system metrics and interfacing with a target system, connected
926929
via an ADB connection.
927930
"""
928931

929932
start_time = time.time()
930933
try:
931-
self.pid_tool = PIDTool(self.adb, self.application)
934+
self.pid_tool = PIDTool(self.adb, self.application, self.pid)
932935
except Exception, e:
933936
raise Exception("Trace failed: {}".format(e))
934937
print("PIDs gathered --- %s Sec" % (time.time() - start_time))

MainInterface.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def setupUi(self, MainWindow):
3939
self.scrollArea.setWidgetResizable(True)
4040
self.scrollArea.setObjectName("scrollArea")
4141
self.scrollAreaWidgetContents = QtWidgets.QWidget()
42-
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 283, 762))
42+
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 283, 792))
4343
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
4444
self.verticalLayout_2 = QtWidgets.QVBoxLayout(
4545
self.scrollAreaWidgetContents)
@@ -79,6 +79,15 @@ def setupUi(self, MainWindow):
7979
self.lineEditApplicationName.setObjectName("lineEditApplicationName")
8080
self.horizontalLayout_3.addWidget(self.lineEditApplicationName)
8181
self.verticalLayout_5.addLayout(self.horizontalLayout_3)
82+
self.horizontalLayout_14 = QtWidgets.QHBoxLayout()
83+
self.horizontalLayout_14.setObjectName("horizontalLayout_14")
84+
self.label_35 = QtWidgets.QLabel(self.frameTraceOptions)
85+
self.label_35.setObjectName("label_35")
86+
self.horizontalLayout_14.addWidget(self.label_35)
87+
self.lineEditAppPID = QtWidgets.QLineEdit(self.frameTraceOptions)
88+
self.lineEditAppPID.setObjectName("lineEditAppPID")
89+
self.horizontalLayout_14.addWidget(self.lineEditAppPID)
90+
self.verticalLayout_5.addLayout(self.horizontalLayout_14)
8291
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
8392
self.horizontalLayout_4.setSizeConstraint(
8493
QtWidgets.QLayout.SetNoConstraint)
@@ -832,6 +841,9 @@ def retranslateUi(self, MainWindow):
832841
_translate("MainWindow", "Android Energy Debugger"))
833842
self.label_6.setText(_translate("MainWindow", "<b>Trace</b>"))
834843
self.label.setText(_translate("MainWindow", "Application:"))
844+
self.label_35.setText(_translate("MainWindow", "Manual PID"))
845+
self.lineEditAppPID.setPlaceholderText(
846+
_translate("MainWindow", "Input PID for hard-to-find apps"))
835847
self.label_3.setText(_translate("MainWindow", "Trace Duration:"))
836848
self.checkBoxDrawGraph.setText(
837849
_translate("MainWindow", "Draw Graph File (.dot)"))

PIDTool.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ class PIDTool:
2828
""" Probes the target system using ps and grep to extract all relevant threads to bother the target
2929
application, system services and binder threads.
3030
"""
31-
def __init__(self, adb_device, name):
31+
def __init__(self, adb_device, name, pid=None):
3232

3333
try:
3434
self.adb_device = adb_device
3535
self.name = name
36-
main_pid = self._find_main_pid()
36+
37+
main_pid = self._find_main_pid(pid)
38+
3739
if main_pid is None:
3840
print(
3941
"Failed to find main PID for given application: {}".format(
@@ -68,13 +70,15 @@ def _find_all_pid(self):
6870
self._find_binder_pids()
6971
print("---- Found Binder PIDs --- %s Sec" % (time.time() - start_time))
7072

71-
def _find_main_pid(self):
73+
def _find_main_pid(self, pid=None):
7274
""" Will find the parent PID of the target application.
7375
7476
:return: PID object of the main process for the target application
7577
"""
76-
77-
res = self.adb_device.command("ps | grep " + self.name)
78+
if pid is None:
79+
res = self.adb_device.command("ps | grep " + self.name)
80+
else:
81+
res = self.adb_device.command("ps | grep " + pid)
7882
if res == "":
7983
return None
8084

UI/MainInterface.ui

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<x>0</x>
5252
<y>0</y>
5353
<width>283</width>
54-
<height>762</height>
54+
<height>792</height>
5555
</rect>
5656
</property>
5757
<layout class="QVBoxLayout" name="verticalLayout_2">
@@ -100,6 +100,24 @@
100100
</item>
101101
</layout>
102102
</item>
103+
<item>
104+
<layout class="QHBoxLayout" name="horizontalLayout_14">
105+
<item>
106+
<widget class="QLabel" name="label_35">
107+
<property name="text">
108+
<string>Manual PID</string>
109+
</property>
110+
</widget>
111+
</item>
112+
<item>
113+
<widget class="QLineEdit" name="lineEditAppPID">
114+
<property name="placeholderText">
115+
<string>Input PID for hard-to-find apps</string>
116+
</property>
117+
</widget>
118+
</item>
119+
</layout>
120+
</item>
103121
<item>
104122
<layout class="QHBoxLayout" name="horizontalLayout_4">
105123
<property name="sizeConstraint">

0 commit comments

Comments
 (0)