mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
From my recent go/gclient-sync-no-ops analysis, I noticed that HostArch() is repeated called within get_builtin_vars() fn. The `platform.architecture()` call made in arm-based systems and some x64 is expensive and adds to gclient sync's runtime when repeatedly called. When caching HostArch(), I noticed 22.4% speed-up in incremental no-op gclient sync when run on arm-based machine. Change-Id: I962c4fb0879d2931268f5bec1678ef782c56e7f2 Bug: 5076224 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5076226 Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com> Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
#!/usr/bin/env vpython3
|
|
# Copyright 2019 The Chromium Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
import os
|
|
import platform
|
|
import sys
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
import detect_host_arch
|
|
|
|
|
|
class DetectHostArchTest(unittest.TestCase):
|
|
def setUp(self):
|
|
super(DetectHostArchTest, self).setUp()
|
|
mock.patch('platform.machine').start()
|
|
mock.patch('platform.processor').start()
|
|
mock.patch('platform.architecture').start()
|
|
self.addCleanup(mock.patch.stopall)
|
|
|
|
def testHostArch(self):
|
|
test_cases = [
|
|
('ia86', '', [''], 'x86'),
|
|
('i86pc', '', [''], 'x86'),
|
|
('x86_64', '', [''], 'x64'),
|
|
('amd64', '', [''], 'x64'),
|
|
('x86_64', '', ['32bit'], 'x86'),
|
|
('amd64', '', ['32bit'], 'x86'),
|
|
('arm', '', [''], 'arm'),
|
|
('aarch64', '', [''], 'arm64'),
|
|
('aarch64', '', ['32bit'], 'arm'),
|
|
('arm64', '', [''], 'arm64'),
|
|
('amd64', 'ARMv8 (64-bit) Family', ['64bit', 'WindowsPE'], 'x64'),
|
|
('arm64', 'ARMv8 (64-bit) Family', ['32bit', 'WindowsPE'], 'x64'),
|
|
('mips64', '', [''], 'mips64'),
|
|
('mips', '', [''], 'mips'),
|
|
('ppc', '', [''], 'ppc'),
|
|
('foo', 'powerpc', [''], 'ppc'),
|
|
('s390', '', [''], 's390'),
|
|
]
|
|
|
|
for machine, processor, arch, expected in test_cases:
|
|
platform.machine.return_value = machine
|
|
platform.processor.return_value = processor
|
|
platform.architecture.return_value = arch
|
|
detect_host_arch.HostArch.cache_clear()
|
|
self.assertEqual(expected, detect_host_arch.HostArch())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|