mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-10-30 22:54:18 +00:00 
			
		
		
		
	Adding instrument_is_enabled function
As instrumentation can be enabled/disabled for a specfic workload execution, it is sometimes not enough to verify that an instrument has been installed for the run; one might need to check whether it is currently enabled.
This commit is contained in:
		| @@ -197,6 +197,18 @@ def is_installed(instrument): | ||||
|     return False | ||||
|  | ||||
|  | ||||
| def is_enabled(instrument): | ||||
|     if isinstance(instrument, Instrument) or isinstance(instrument, type): | ||||
|         name = instrument.name | ||||
|     else:  # assume string | ||||
|         name = instrument | ||||
|     try: | ||||
|         installed_instrument = get_instrument(name) | ||||
|         return installed_instrument.is_enabled | ||||
|     except ValueError: | ||||
|         return False | ||||
|  | ||||
|  | ||||
| failures_detected = False | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -23,5 +23,13 @@ def instrument_is_installed(instrument): | ||||
|     return instrumentation.is_installed(instrument) | ||||
|  | ||||
|  | ||||
| def instrument_is_enabled(instrument): | ||||
|     """Returns ``True`` if the specified instrument is installed and is currently | ||||
|     enabled, and ``False`` other wise. The insturment maybe specified either | ||||
|     as a name or a subclass (or instance of subclass) of | ||||
|     :class:`wlauto.core.Instrument`.""" | ||||
|     return instrumentation.is_enabled(instrument) | ||||
|  | ||||
|  | ||||
| def clear_instrumentation(): | ||||
|     instrumentation.installed = [] | ||||
|   | ||||
| @@ -21,7 +21,7 @@ from nose.tools import assert_equal, raises, assert_true, assert_false | ||||
|  | ||||
| from wlauto import Instrument | ||||
| from wlauto.core import signal, instrumentation | ||||
| from wlauto.instrumentation import instrument_is_installed, clear_instrumentation | ||||
| from wlauto.instrumentation import instrument_is_installed, instrument_is_enabled, clear_instrumentation | ||||
|  | ||||
|  | ||||
| class MockInstrument(Instrument): | ||||
| @@ -178,6 +178,16 @@ class InstrumentationTest(TestCase): | ||||
|         assert_equal(instrument2.after, 1) | ||||
|         assert_equal(instrument2.result, 1) | ||||
|  | ||||
|     def test_check_enabled(self): | ||||
|         instrument = _instantiate(MockInstrument) | ||||
|         instrumentation.install(instrument) | ||||
|         instrumentation.enable(instrument) | ||||
|         assert_true(instrument_is_enabled(instrument)) | ||||
|         assert_true(instrument_is_enabled(instrument.name)) | ||||
|         instrumentation.disable(instrument) | ||||
|         assert_false(instrument_is_enabled(instrument)) | ||||
|         assert_false(instrument_is_enabled(instrument.name)) | ||||
|  | ||||
|     def test_local_instrument(self): | ||||
|         global counter | ||||
|         counter = 0 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user