| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
"""Tests for the profiler classes.""" |
| 4 |
|
| 5 |
import time |
| 6 |
import unittest |
| 7 |
|
| 8 |
from acstore import profilers |
| 9 |
|
| 10 |
from tests import test_lib |
| 11 |
|
| 12 |
|
| 13 |
class CPUTimeMeasurementTest(test_lib.BaseTestCase): |
| 14 |
"""Tests for the CPU time measurement.""" |
| 15 |
|
| 16 |
def testSampleStartStop(self): |
| 17 |
"""Tests the SampleStart and SampleStop functions.""" |
| 18 |
cpu_measurement = profilers.CPUTimeMeasurement() |
| 19 |
cpu_measurement.SampleStart() |
| 20 |
cpu_measurement.SampleStop() |
| 21 |
|
| 22 |
|
| 23 |
class StorageProfilerTest(test_lib.BaseTestCase): |
| 24 |
"""Tests for the storage profiler.""" |
| 25 |
|
| 26 |
# pylint: disable=protected-access |
| 27 |
|
| 28 |
def testIsSupported(self): |
| 29 |
"""Tests the IsSupported function.""" |
| 30 |
self.assertTrue(profilers.StorageProfiler.IsSupported()) |
| 31 |
|
| 32 |
def testStartStop(self): |
| 33 |
"""Tests the Start and Stop functions.""" |
| 34 |
with test_lib.TempDirectory() as temp_directory: |
| 35 |
test_profiler = profilers.StorageProfiler( |
| 36 |
'test', temp_directory) |
| 37 |
|
| 38 |
setattr(test_profiler, '_FILENAME_PREFIX', 'test') |
| 39 |
setattr(test_profiler, '_FILE_HEADER', 'test') |
| 40 |
|
| 41 |
test_profiler.Start() |
| 42 |
|
| 43 |
test_profiler.Stop() |
| 44 |
|
| 45 |
def testSample(self): |
| 46 |
"""Tests the Sample function.""" |
| 47 |
with test_lib.TempDirectory() as temp_directory: |
| 48 |
test_profiler = profilers.StorageProfiler( |
| 49 |
'test', temp_directory) |
| 50 |
|
| 51 |
test_profiler.Start() |
| 52 |
|
| 53 |
for _ in range(5): |
| 54 |
test_profiler.StartTiming('test_profile') |
| 55 |
time.sleep(0.01) |
| 56 |
test_profiler.StopTiming('test_profile') |
| 57 |
test_profiler.Sample('test_profile', 'read', 'test', 1024, 128) |
| 58 |
|
| 59 |
test_profiler.Stop() |
| 60 |
|
| 61 |
|
| 62 |
if __name__ == '__main__': |
| 63 |
unittest.main() |