-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
27 changed files
with
370 additions
and
70 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.phlop | ||
massif.phlop | ||
.mkn | ||
bin | ||
__pycache__ | ||
|
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
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,27 @@ | ||
# valgrind.py | ||
# | ||
|
||
from phlop.proc import run | ||
|
||
|
||
def run_massif(cli_args): | ||
outfile = cli_args.outfile if cli_args.outfile else "massif.phlop" | ||
cmd = f"valgrind --tool=massif --massif-out-file={outfile} " + " ".join( | ||
cli_args.remaining | ||
) | ||
run(cmd, capture_output=True) | ||
|
||
|
||
def run_memcheck(cli_args): | ||
cmd = "valgrind " + " ".join(cli_args.remaining) | ||
run(cmd, capture_output=True) | ||
|
||
|
||
def run_valgrind(cli_args): | ||
tool = cli_args.tool | ||
if tool == "massif": | ||
run_massif(cli_args) | ||
elif tool == "memcheck" or not tool: | ||
run_memcheck(cli_args) | ||
elif tool: | ||
raise RuntimeError(f"Phlop ERROR: Unhandled valgrind tool: {tool}") |
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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
# | ||
# | ||
# | ||
# | ||
|
||
|
||
import logging | ||
import os | ||
|
||
LOG_LEVEL = os.environ.get("PHLOP_LOG_LEVEL", "INFO") | ||
log_levels = {"INFO": 20, "WARNING": 30, "ERROR": 40, "DEBUG": 10} | ||
|
||
FORMAT = "[log: %(filename)s:%(lineno)s - %(funcName)30s() ] %(message)s" | ||
logging.basicConfig(format=FORMAT) | ||
# logger.setLevel(log_levels[LOG_LEVEL]) | ||
|
||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
logger = logging.getLogger(__name__) | ||
def getLogger(name, level=LOG_LEVEL): | ||
logger = logging.getLogger(__name__) | ||
level = log_levels[level] if isinstance(level, str) else level | ||
logger.setLevel(level) | ||
return logger |
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
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,40 @@ | ||
# | ||
# | ||
|
||
import logging | ||
import os | ||
import sys | ||
|
||
from phlop.app import perf as p | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
logger = logging.getLogger(__name__) | ||
|
||
MPI_RANK = os.environ.get("OMPI_COMM_WORLD_RANK") | ||
|
||
|
||
def verify_cli_args(cli_args): | ||
try: | ||
cli_args.interval = int(cli_args.interval) | ||
except ValueError: | ||
raise ValueError("Interval must be an integer") from None | ||
if cli_args.yaml: | ||
cli_args.yaml = f"{cli_args.yaml}.{MPI_RANK}.yaml" | ||
cli_args.summary = False | ||
sys.argv = [sys.argv[0]] # drop everything! | ||
return cli_args | ||
|
||
|
||
def main(): | ||
parser = p.cli_args_parser() | ||
# cli_args = verify_cli_args(parser.parse_args()) | ||
try: | ||
... | ||
except (Exception, SystemExit) as e: | ||
logger.exception(e) | ||
parser.print_help() | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,85 @@ | ||
# | ||
# | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
from phlop.app import perf as p | ||
from phlop.logger import getLogger | ||
from phlop.testing import parallel_processor as pp | ||
from phlop.testing import test_cases as tc | ||
|
||
logger = getLogger(__name__) | ||
logpath = Path(".phlop") / "perf" | ||
|
||
""" | ||
if you get an error about js-d3-flamegraph: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=996839 | ||
mkdir /usr/share/d3-flame-graph | ||
wget -O /usr/share/d3-flame-graph/d3-flamegraph-base.html https://cdn.jsdelivr.net/npm/d3-flame-graph@4/dist/templates/d3-flamegraph-base.html | ||
""" | ||
|
||
|
||
def perf_stat_cmd(cli_args, path, line): | ||
file = Path(line.split(" ")[-1]).stem | ||
outpath = logpath / path.stem | ||
outpath.mkdir(parents=True, exist_ok=True) | ||
return p.stat_cmd(line, p.stat_events, outpath / f"{file}.json") | ||
|
||
|
||
def get_from_files(cli_args): | ||
test_batches = {} | ||
file_paths = list(Path(cli_args.dir).glob(cli_args.infiles)) | ||
|
||
if not file_paths: | ||
raise ValueError("No load files found") | ||
|
||
for path in file_paths: | ||
with open(path, "r") as file: | ||
while line := file.readline(): | ||
test_case = tc.determine_cores_for_test_case( | ||
tc.TestCase(cmd=perf_stat_cmd(cli_args, path, line.rstrip())) | ||
) | ||
if test_case.cores not in test_batches: | ||
test_batches[test_case.cores] = [] | ||
test_batches[test_case.cores].append(test_case) | ||
|
||
return [tc.TestBatch(v, k) for k, v in test_batches.items()] | ||
|
||
|
||
def get_remaining(cli_args): | ||
test_batches = {} | ||
path = Path(cli_args.remaining[-1]).parent | ||
test_case = tc.determine_cores_for_test_case( | ||
tc.TestCase(cmd=perf_stat_cmd(cli_args, path, " ".join(cli_args.remaining))) | ||
) | ||
test_batches[test_case.cores] = [test_case] | ||
return [tc.TestBatch(v, k) for k, v in test_batches.items()] | ||
|
||
|
||
def main(): | ||
logpath.mkdir(parents=True, exist_ok=True) | ||
|
||
parser = p.cli_args_parser() | ||
cli_args = p.verify_cli_args(parser.parse_args()) | ||
try: | ||
test_batches = [] | ||
if cli_args.infiles: | ||
test_batches = get_from_files(cli_args) | ||
else: | ||
test_batches = get_remaining(cli_args) | ||
|
||
pp.process( | ||
test_batches, | ||
n_cores=cli_args.cores, | ||
print_only=cli_args.print_only, | ||
logging=cli_args.logging, | ||
) | ||
|
||
except (Exception, SystemExit) as e: | ||
logger.exception(e) | ||
parser.print_help() | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.