import
csv
import
os
import
time
class
App(
object
):
def
__init__(
self
):
self
.content
=
""
self
.startTime
=
0
def
LaunchApp(
self
):
cmd
=
'adb shell am start -W -n com.expflow.reading/.activity.SplashActivity'
self
.content
=
os.popen(cmd)
def
StopApp(
self
):
cmd
=
'adb shell am force-stop com.expflow.reading'
os.popen(cmd)
def
GetLaunchedTime(
self
):
for
line
in
self
.content.readlines():
if
"ThisTime"
in
line:
self
.startTime
=
line.split(
":"
)[
1
]
break
return
self
.startTime
class
Controller(
object
):
def
__init__(
self
, count):
self
.app
=
App()
self
.counter
=
count
self
.alldata
=
[(
"timestamp"
,
"elapsedtime"
)]
def
testprocess(
self
):
self
.app.LaunchApp()
time.sleep(
5
)
elpasedtime
=
self
.app.GetLaunchedTime()
print
(elpasedtime)
self
.app.StopApp()
time.sleep(
3
)
currenttime
=
self
.getCurrentTime()
self
.alldata.append((currenttime, elpasedtime))
def
run(
self
):
while
self
.counter >
0
:
self
.testprocess()
self
.counter
=
self
.counter
-
1
def
getCurrentTime(
self
):
currentTime
=
time.strftime(
"%Y-%m-%d %H:%M:%S"
, time.localtime())
print
(currentTime)
return
currentTime
def
SaveDataToCSV(
self
):
csvfile
=
open
(
"startTime.csv"
,
'wb'
)
writer
=
csv.writer(csvfile)
writer.writerows(
self
.alldata)
csvfile.close()
if
__name__
=
=
"__main__"
:
controller
=
Controller(
1
)
controller.run()
controller.SaveDataToCSV()