-
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.
pfm parsing for perf stat codes per instruction
- Loading branch information
1 parent
8810bad
commit 9f7f103
Showing
14 changed files
with
215 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ bin | |
__pycache__ | ||
dist | ||
phlop.egg-info/ | ||
scope_timer.txt | ||
|
||
*scope_timer.txt | ||
tpp |
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,5 @@ | ||
# | ||
# | ||
# | ||
# | ||
# |
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,48 @@ | ||
# | ||
# | ||
# | ||
# | ||
# | ||
|
||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from phlop.os import pushd | ||
from phlop.proc import run | ||
from phlop.string import decode_bytes | ||
|
||
FILE_DIR = Path(__file__).resolve().parent | ||
|
||
logger = logging.getLogger(__name__) | ||
check_events_start = "Total events:" | ||
|
||
|
||
def parse_check_events_output(lines): | ||
return lines[-1].split(":")[1].strip().replace("0x", "r") | ||
|
||
|
||
def run_check_events(code): | ||
with pushd(FILE_DIR.parent.parent.parent): | ||
return decode_bytes( | ||
run(f"./tpp/pfm/examples/check_events {code}").stdout | ||
).splitlines() | ||
|
||
|
||
def get_evt_perf_code(code): | ||
return parse_check_events_output(run_check_events(code)) | ||
|
||
|
||
if __name__ == "__main__": | ||
from phlop.app.pfm.showevtinfo import get_evt_info | ||
|
||
key, code = "[MULT_FLOPS]", "" | ||
for info in get_evt_info(): | ||
if key in info.umask: | ||
code = f"{info.name}:{info.umask[key].code}" | ||
break | ||
|
||
assert code != "" | ||
|
||
# print("get_evt_perf_code", get_evt_perf_code(code)) | ||
print(run(f"perf stat -e {get_evt_perf_code(code)} sleep 5")) |
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,81 @@ | ||
# | ||
# | ||
# | ||
# | ||
# | ||
|
||
|
||
import logging | ||
from dataclasses import dataclass, field | ||
from pathlib import Path | ||
|
||
from phlop.os import pushd | ||
from phlop.proc import run | ||
from phlop.string import decode_bytes | ||
|
||
FILE_DIR = Path(__file__).resolve().parent | ||
|
||
logger = logging.getLogger(__name__) | ||
EVTINFO_delimiter = "#-----------------------------" | ||
|
||
|
||
@dataclass | ||
class EVTUMask: | ||
id: str | ||
desc: str | ||
code: str | ||
|
||
|
||
@dataclass | ||
class EVTInfo: | ||
idx: str | ||
pmu: str | ||
name: str | ||
umask: dict = field(default_factory=lambda: {}) | ||
ect: dict = field(default_factory=lambda: {}) | ||
|
||
|
||
def _parse_evtinfo(bits_list): | ||
assert len(bits_list) >= 7 | ||
info = EVTInfo( | ||
idx=bits_list[0][1].strip(), | ||
pmu=bits_list[1][1].strip(), | ||
name=bits_list[2][1].strip(), | ||
) | ||
for bits in bits_list[7:]: | ||
if bits[0].strip().startswith("Umask"): | ||
info.umask[bits[3].strip()] = EVTUMask( | ||
id=bits[3].strip(), desc=bits[5].strip(), code=bits[1].strip() | ||
) | ||
return info | ||
|
||
|
||
def parse_evtinfo_output(lines): | ||
start_idx = 0 | ||
for line in lines: | ||
start_idx += 1 | ||
if line.strip() == EVTINFO_delimiter: | ||
break | ||
|
||
bits_list, results = [], [] | ||
for line in lines[start_idx:]: | ||
if line == EVTINFO_delimiter: | ||
results.append(_parse_evtinfo(bits_list)) | ||
bits_list = [] | ||
continue | ||
bits_list.append(line.strip().split(":")) | ||
|
||
return results | ||
|
||
|
||
def run_evtinfo(): | ||
with pushd(FILE_DIR.parent.parent.parent): | ||
return decode_bytes(run("./tpp/pfm/examples/showevtinfo").stdout).splitlines() | ||
|
||
|
||
def get_evt_info(): | ||
return parse_evtinfo_output(run_evtinfo()) | ||
|
||
|
||
if __name__ == "__main__": | ||
print(get_evt_info()) |
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
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,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" && cd "$CWD"/.. | ||
|
||
set -ex | ||
|
||
[ ! -d "tpp/pfm" ] && ( | ||
git clone git://perfmon2.git.sourceforge.net/gitroot/perfmon2/libpfm4 tpp/pfm | ||
cd tpp/pfm | ||
make | ||
) |
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 @@ | ||
# | ||
# | ||
# | ||
|
||
|
||
from phlop.proc import run | ||
from phlop.string import decode_bytes | ||
|
||
if __name__ == "__main__": | ||
from phlop.app.pfm.check_events import get_evt_perf_code | ||
from phlop.app.pfm.showevtinfo import get_evt_info | ||
|
||
code = "" | ||
key0, key1 = "[MULT_FLOPS]", "[ADD_SUB_FLOPS]" | ||
for info in get_evt_info(): | ||
if key0 in info.umask: | ||
for key, umask in info.umask.items(): | ||
code += f"{info.name}:{umask.code} " | ||
break | ||
# if key1 in info.umask: | ||
# code += f"{info.name}:{info.umask[key1].code} " | ||
|
||
code = code.strip() | ||
assert code != "" | ||
|
||
events = " ".join([f"-e {get_evt_perf_code(ev)}" for ev in code.split(" ")]) | ||
print(decode_bytes(run(f"perf stat {events} sleep 5").stderr)) |