Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1596)

Unified Diff: appengine/swarming/swarming_bot/api/os_utilities.py

Issue 2911193003: Expose named caches as dimensions. (Closed)
Patch Set: Use state.json instead Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/swarming/local_smoke_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/swarming_bot/api/os_utilities.py
diff --git a/appengine/swarming/swarming_bot/api/os_utilities.py b/appengine/swarming/swarming_bot/api/os_utilities.py
index 28710d916c0135d0bbd602314a48aaca87677906..332b931b180fc2d65ac333327a8cc9cdb897a515 100644
--- a/appengine/swarming/swarming_bot/api/os_utilities.py
+++ b/appengine/swarming/swarming_bot/api/os_utilities.py
@@ -1,3 +1,4 @@
+# coding: utf-8
# Copyright 2014 The LUCI Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
@@ -514,6 +515,31 @@ def get_uptime():
return platforms.linux.get_uptime()
+def get_named_caches():
+ """Returns the list of named caches."""
+ # Strictly speaking, this is a layering violation. This data is managed by
+ # run_isolated.py but this is valuable to expose this as a Swarming bot
+ # dimensions so ¯\_(ツ)_/¯
+ #
+ # Assumptions:
+ # - ../__main__.py calls os.chdir(__file__)
+ # - ../bot_code/bot_main.py specifies
+ # --named-cache-root os.path.join(botobj.base_dir, 'c') to run_isolated.
+ # - ../client/named_cache.py behavior
+ #
+ # A better implementation would require:
+ # - Access to bot.Bot instance to query bot.base_dir
+ # - Access to named_cache.py to load state.json
+ # - Access to --named-cache-root hardcoded in bot_main.py
+ #
+ # but hey, the following code is 5 lines...
+ try:
+ with open(os.path.join(os.getcwd(), u'c', u'state.json'), 'rb') as f:
nodir 2017/05/31 21:03:21 is os.getcwd() needed? wouldn't open() do it for y
M-A Ruel 2017/06/02 22:05:31 Removed, that's true that it was not necessary.
+ return sorted(i[0] for i in json.load(f)['items'])
+ except (IOError, KeyError, OSError):
+ return []
+
+
class AuthenticatedHttpRequestFailure(Exception):
pass
@@ -849,6 +875,9 @@ def get_dimensions():
u'os': [os_name],
u'pool': [u'default'],
}
+ caches = get_named_caches()
+ if caches:
+ dimensions[u'caches'] = caches
if u'avx2' in cpuinfo.get(u'flags', []):
dimensions[u'cpu'].append(cpu_type + u'-' + cpu_bitness + u'-avx2')
if any(u'avx512' in x for x in cpuinfo.get(u'flags', [])):
« no previous file with comments | « appengine/swarming/local_smoke_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698