blob: 461396fd35895e34ce9aa060a370be8509f1de44 [file] [log] [blame]
pvollan@apple.comaedf7fd2019-04-04 17:39:48 +00001# Copyright (C) 2019 Apple Inc. All rights reserved.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are
5# met:
6#
7# * Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.
9# * Redistributions in binary form must reproduce the above
10# copyright notice, this list of conditions and the following disclaimer
11# in the documentation and/or other materials provided with the
12# distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26import os
27import subprocess
28import time
29
30DUMP_PID = 0
31DUMP_START_TIME = 0
32
33while(1):
34 time.sleep(10)
35 CUR_TIME = int(time.time())
36
37 pid_fetch = subprocess.Popen("ps -e | grep \"DumpRenderTree\" | awk '{print $1}'", shell=True, stdout=subprocess.PIPE,)
38 CURRENT_PID = pid_fetch.communicate()[0].split('\n')[0]
39 CHECKED = 1
40 # We only care about doing anything if there is a DumpRenderTree running
41 if (CURRENT_PID):
42 # If the PID has changed, reset the timer and the active pid
43 if (DUMP_PID != CURRENT_PID):
44 DUMP_PID = CURRENT_PID
45 DUMP_START_TIME = time.time()
46 else:
47 # If the active and current PID are the same and an hour has elapsed, kill DumpRenderTree and reset the active PID to 0
48 if (CUR_TIME - DUMP_START_TIME >= 3600):
49 os.system("taskkill /F /IM DumpRenderTree.exe")
50 os.system("taskkill /F /IM ImageDiff.exe")
51 DUMP_PID = 0
52 else:
53 DUMP_PID = 0