-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tool to check supported hugepagesize
- Loading branch information
1 parent
6efdb9b
commit 4d1cbac
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
import re | ||
from pathlib import PurePath | ||
from typing import Any, List | ||
|
||
from lisa.executable import Tool | ||
from lisa.operating_system import Posix | ||
from lisa.util import LisaException, constants, find_patterns_in_lines, get_matched_str | ||
|
||
PATTERN_MEM_INFO = re.compile( | ||
r"^(?P<mem_info_key>[^\s]+)\:\s+(?P<mem_info_key_value>.+)", | ||
) | ||
|
||
|
||
class Meminfo(Tool): | ||
@property | ||
def command(self) -> str: | ||
return "cat /proc/meminfo" | ||
|
||
@property | ||
def can_install(self) -> bool: | ||
return False | ||
|
||
def _initialize(self, *args: Any, **kwargs: Any) -> None: | ||
self._command = "cat /proc/meminfo" | ||
self._mem_info_dict = {} | ||
|
||
def _get_memoryinfo(self): | ||
memoryinfo = self.run("", shell=True) | ||
for memory_info_entry in memoryinfo.stdout.splitlines(): | ||
mem_info_content = MeminfoContent(memory_info_entry) | ||
self._mem_info_dict[ | ||
mem_info_content.mem_info_key | ||
] = mem_info_content.mem_info_key_value | ||
return self._mem_info_dict | ||
|
||
def get_hugepagesize(self): | ||
if not "hugepagesize" in self._mem_info_dict: | ||
self._get_memoryinfo() | ||
return self._mem_info_dict.get("Hugepagesize", None) | ||
|
||
|
||
class MeminfoContent: | ||
def __init__(self, memory_info_entry_raw: str) -> None: | ||
self.parse(memory_info_entry_raw) | ||
|
||
def __str__(self) -> str: | ||
return ( | ||
f"MeminfoKey: {self.mem_info_key} " | ||
f"MeminfoKeyValue {self.mem_info_key_value} " | ||
) | ||
|
||
def parse(self, raw_str: str) -> None: | ||
matched_mem_info = PATTERN_MEM_INFO.match(raw_str) | ||
if matched_mem_info: | ||
self.mem_info_key = matched_mem_info.group("mem_info_key") | ||
self.mem_info_key_value = matched_mem_info.group("mem_info_key_value") | ||
else: | ||
raise LisaException("cannot find any matched memory info content") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters