Commit c7d37970 authored by Caleb Rouleau's avatar Caleb Rouleau Committed by Commit Bot

[Perf] Make trigger script use python3 print function.

Make the unittests exercise this by adding
    args.multiple_dimension_script_verbose = True
which makes verbose be true everywhere so that we
can make sure the print statements work.

Also add in some additional print statements to clarify what is
happening.

Also fix a couple easy formatting issues.

Bug: 984504, 956637
Change-Id: Ib4dc4236e57f47f0c92eba84db5ae4d9cc969309
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1934526
Commit-Queue: Caleb Rouleau <crouleau@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Auto-Submit: Caleb Rouleau <crouleau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718921}
parent 507f4ee8
...@@ -44,6 +44,8 @@ This script is normally called from the swarming recipe module in tools/build. ...@@ -44,6 +44,8 @@ This script is normally called from the swarming recipe module in tools/build.
""" """
from __future__ import print_function
import argparse import argparse
import copy import copy
import json import json
...@@ -56,7 +58,7 @@ import urllib ...@@ -56,7 +58,7 @@ import urllib
import base_test_triggerer import base_test_triggerer
class Bot(object): class Bot(object):
""" Eligible bots to run the task""" """Eligible bots to run the task."""
def __init__(self, bot_id, is_alive): def __init__(self, bot_id, is_alive):
self._bot_id = bot_id self._bot_id = bot_id
self._is_alive = is_alive self._is_alive = is_alive
...@@ -161,7 +163,7 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer): ...@@ -161,7 +163,7 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer):
shard_to_bot_assignment_map[shard_index] = \ shard_to_bot_assignment_map[shard_index] = \
unallocated_healthy_bots.pop() unallocated_healthy_bots.pop()
if verbose: if verbose:
print 'First time shard %d has been triggered' % shard_index print('First time shard %d has been triggered' % shard_index)
elif not bot: elif not bot:
shard_to_bot_assignment_map[shard_index] = unallocated_bad_bots.pop() shard_to_bot_assignment_map[shard_index] = unallocated_bad_bots.pop()
...@@ -172,8 +174,9 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer): ...@@ -172,8 +174,9 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer):
healthy_bot = unallocated_healthy_bots.pop() healthy_bot = unallocated_healthy_bots.pop()
shard_to_bot_assignment_map[shard_index] = healthy_bot shard_to_bot_assignment_map[shard_index] = healthy_bot
if verbose: if verbose:
print ('Device affinity broken for bot %s, new ' print('Device affinity broken for shard #%d. bot %s is dead, new '
'mapping to bot %s' % (dead_bot.id(), healthy_bot.id())) 'mapping to bot %s' % (
shard_index, dead_bot.id(), healthy_bot.id()))
# Now populate the indices into the bot_configs array # Now populate the indices into the bot_configs array
selected_configs = [] selected_configs = []
...@@ -190,17 +193,18 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer): ...@@ -190,17 +193,18 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer):
def _print_device_affinity_info( def _print_device_affinity_info(
self, new_map, existing_map, health_map, num_shards): self, new_map, existing_map, health_map, num_shards):
print()
for shard_index in xrange(num_shards): for shard_index in xrange(num_shards):
existing = existing_map.get(shard_index, None) existing = existing_map.get(shard_index, None)
new = new_map.get(shard_index, None) new = new_map.get(shard_index, None)
existing_id = "" existing_id = ''
if existing: if existing:
existing_id = existing.id() existing_id = existing.id()
new_id = "" new_id = ''
if new: if new:
new_id = new.id() new_id = new.id()
print "Shard %d\n\tprevious: %s\n\tnew: %s" % ( print('Shard %d\n\tprevious: %s\n\tnew: %s' % (
shard_index, existing_id, new_id) shard_index, existing_id, new_id))
healthy_bots = [] healthy_bots = []
dead_bots = [] dead_bots = []
...@@ -209,12 +213,16 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer): ...@@ -209,12 +213,16 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer):
healthy_bots.append(b.id()) healthy_bots.append(b.id())
else: else:
dead_bots.append(b.id()) dead_bots.append(b.id())
print "Healthy bots: %s" % healthy_bots print('Shards needed: %d' % num_shards)
print "Dead Bots: %s" % dead_bots print('Total bots (dead + healthy): %d' % (
len(dead_bots) + len(healthy_bots)))
print('Healthy bots, %d: %s' % (len(healthy_bots), healthy_bots))
print('Dead Bots, %d: %s' % (len(dead_bots), dead_bots))
print()
def _query_swarming_for_eligible_bot_configs(self, dimensions): def _query_swarming_for_eligible_bot_configs(self, dimensions):
""" Query Swarming to figure out which bots are available. """Query Swarming to figure out which bots are available.
Returns: a dictionary in which the keys are the bot id and Returns: a dictionary in which the keys are the bot id and
the values are Bot object that indicate the health status the values are Bot object that indicate the health status
......
...@@ -58,6 +58,7 @@ class UnitTest(unittest.TestCase): ...@@ -58,6 +58,7 @@ class UnitTest(unittest.TestCase):
args = Args() args = Args()
args.shards = len(previous_task_assignment_map) args.shards = len(previous_task_assignment_map)
args.dump_json = 'output.json' args.dump_json = 'output.json'
args.multiple_dimension_script_verbose = True
swarming_args = [ swarming_args = [
'trigger', 'trigger',
'--swarming', '--swarming',
...@@ -275,7 +276,7 @@ class UnitTest(unittest.TestCase): ...@@ -275,7 +276,7 @@ class UnitTest(unittest.TestCase):
self.assertIn(expected_task_assignment.get(1), new_healthy_bots) self.assertIn(expected_task_assignment.get(1), new_healthy_bots)
self.assertIn(expected_task_assignment.get(2), new_healthy_bots) self.assertIn(expected_task_assignment.get(2), new_healthy_bots)
def test_previously_duplicate_task_assignemnts(self): def test_previously_duplicate_task_assignments(self):
triggerer = self.setup_and_trigger( triggerer = self.setup_and_trigger(
previous_task_assignment_map={0: 'build3', 1: 'build3', 2: 'build5', previous_task_assignment_map={0: 'build3', 1: 'build3', 2: 'build5',
3: 'build6'}, 3: 'build6'},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment