From f6cf1a42453d84e9b5f79c86dfc0fe5d5f79a9de Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 9 Mar 2018 13:31:52 +0100 Subject: [PATCH] GroupMembershipResolver: Improve Benchmark output --- .../Objects/GroupMembershipResolver.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/library/Director/Objects/GroupMembershipResolver.php b/library/Director/Objects/GroupMembershipResolver.php index bd24cafa..d3501714 100644 --- a/library/Director/Objects/GroupMembershipResolver.php +++ b/library/Director/Objects/GroupMembershipResolver.php @@ -387,6 +387,8 @@ abstract class GroupMembershipResolver $objects = & $this->objects; } + $times = array(); + foreach ($objects as $object) { if ($object->shouldBeRemoved()) { continue; @@ -394,6 +396,8 @@ abstract class GroupMembershipResolver if ($object->isTemplate()) { continue; } + $mt = microtime(true); + // TODO: fix this last hard host dependency $resolver = HostApplyMatches::prepare($object); foreach ($groups as $groupId => $filter) { @@ -406,12 +410,33 @@ abstract class GroupMembershipResolver $mappings[$groupId][$id] = $id; } } + + $times[] = (microtime(true) - $mt) * 1000; } + $count = count($times); + $min = $max = $avg = 0; + if ($count > 0) { + $min = min($times); + $max = max($times); + $avg = array_sum($times) / $count; + } + + Benchmark::measure(sprintf( + 'Hostgroup apply recalculated: objects=%d groups=%d min=%d max=%d avg=%d (in ms)', + $count, + count($groups), + $min, + $max, + $avg + )); + foreach ($this->fetchMissingSingleAssignments() as $row) { $mappings[$row->group_id][$row->object_id] = $row->object_id; } + Benchmark::measure('Done with single assignments'); + $this->newMappings = $mappings; }