summaryrefslogtreecommitdiff
path: root/buildscripts/collect_resource_info.py
diff options
context:
space:
mode:
authorRob Guo <robertguo@me.com>2017-10-04 15:41:52 -0400
committerRob Guo <robertguo@me.com>2017-10-04 15:50:59 -0400
commit381c7fc06c8f97d83ec5e7681004a2c67e4e1299 (patch)
tree74cfac2592d37a4b1bd8cff94d4cc52ebc540992 /buildscripts/collect_resource_info.py
parente329bd234dc00535b36a47ae998cf24a40552968 (diff)
downloadmongo-381c7fc06c8f97d83ec5e7681004a2c67e4e1299.tar.gz
SERVER-30839 prevent buildscripts/combine_reports.py from overwriting report.json
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()