Skip to content

Commit

Permalink
Compatibility with windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kif committed Jul 3, 2024
1 parent 7479461 commit e64bd99
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
File renamed without changes.
1 change: 0 additions & 1 deletion src/fabio/test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ py.install_sources(
'profile_all.py',
'test_agi_bitfield.py',
'test_all.py',
'test_all_images.py',
'test_compression.py',
'test_densification.py',
'test_fabio.py',
Expand Down
23 changes: 16 additions & 7 deletions src/fabio/test/profile_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,43 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "03/04/2020"
__date__ = "03/07/2024"

import sys
import unittest
import time

from . import test_all

import resource
import logging
profiler = logging.getLogger("memProf")
profiler.setLevel(logging.DEBUG)
profiler.handlers.append(logging.FileHandler("profile.log"))
logger = logging.getLogger(__name__)

WIN32_ERROR = "`profile_all` can only be used under UNIX, Windows is missing memory "

if sys.platform != "win32":
import resource
else:
logger.error(WIN32_ERROR)


class TestResult(unittest.TestResult):

def startTest(self, test):
if sys.platform == "win32":
raise RuntimeError(WIN32_ERROR)
self.__mem_start = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
self.__time_start = time.time()
self.__time_start = time.perf_counter()
unittest.TestResult.startTest(self, test)

def stopTest(self, test):
unittest.TestResult.stopTest(self, test)
params = (time.time() - self.__time_start,
(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss - self.__mem_start) / 1e3,
test.id())
profiler.info("Time: %.3fs \t RAM: %.3f Mb\t%s" % params)
if sys.platform == "win32":
raise RuntimeError(WIN32_ERROR)
mem = (resource.getrusage(resource.RUSAGE_SELF).ru_maxrss - self.__mem_start) / 1e3
profiler.info(f"Time: {time.perf_counter() - self.__time_start:.3f}s \t RAM: {mem:.3f}Mb\t{test.id()}")


class ProfileTestRunner(unittest.TextTestRunner):
Expand Down

0 comments on commit e64bd99

Please sign in to comment.