summaryrefslogtreecommitdiff
path: root/buildscripts/collect_resource_info.py
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/collect_resource_info.py')
-rwxr-xr-xbuildscripts/collect_resource_info.py29
1 files changed, 6 insertions, 23 deletions
diff --git a/buildscripts/collect_resource_info.py b/buildscripts/collect_resource_info.py
index c6f7b1ac527..5fc6c614afa 100755
--- a/buildscripts/collect_resource_info.py
+++ b/buildscripts/collect_resource_info.py
@@ -7,7 +7,6 @@ Collect system resource information on processes running in Evergreen on a given
from __future__ import absolute_import
from __future__ import print_function
-import contextlib
from datetime import datetime
import optparse
import os
@@ -17,30 +16,13 @@ import time
from bson.json_util import dumps
import requests
-@contextlib.contextmanager
-def open_or_use_stdout(filename):
- """
- Opens the specified file for writing, or returns sys.stdout if filename is "-".
- """
- if filename == "-":
- yield sys.stdout
- return
-
- line_buffered = 1
- try:
- fp = open(filename, "w", line_buffered)
- except IOError:
- print("Could not open file {}".format(filename), file=sys.stderr)
- sys.exit(1)
-
- try:
- yield fp
- finally:
- fp.close()
+# Get relative imports to work when the package is not installed on the PYTHONPATH.
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from buildscripts.resmokelib import utils
+
def main():
-
usage = "usage: %prog [options]"
parser = optparse.OptionParser(description=__doc__, usage=usage)
parser.add_option("-i", "--interval",
@@ -58,7 +40,7 @@ def main():
(options, _) = parser.parse_args()
- with open_or_use_stdout(options.outfile) as fp:
+ with utils.open_or_use_stdout(options.outfile) as fp:
while True:
# Requires the Evergreen agent to be running on port 2285.
response = requests.get("http://localhost:2285/status")
@@ -109,5 +91,6 @@ def main():
os.fsync(fp.fileno())
time.sleep(options.interval)
+
if __name__ == "__main__":
main()