Skip to content

Commit 1df2d09

Browse files
committed
s/feature_selection/omp
1 parent 3f83657 commit 1df2d09

12 files changed

+83
-21
lines changed

examples/code_examples.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def test_attr():
528528
return y
529529

530530

531-
def feature_selection(X: np.ndarray, y: np.ndarray):
531+
def omp(X: np.ndarray, y: np.ndarray):
532532
y = np.concatenate(y)
533533
X = (X - X.mean()) / X.std()
534534
X = np.c_[np.ones(X.shape[0]), X]
File renamed without changes.

experiment/feature_selection/instrumented.py renamed to experiment/omp/instrumented.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def run(features: np.ndarray, target: np.ndarray, k: int) -> np.ndarray:
7070

7171

7272
def main(dataset: str, k: int) -> None:
73-
features = np.load(f"experiment/feature_selection/{dataset}_features.npy")
74-
target = np.load(f"experiment/feature_selection/{dataset}_target.npy")
73+
features = np.load(f"experiment/omp/{dataset}_features.npy")
74+
target = np.load(f"experiment/omp/{dataset}_target.npy")
7575
S = run(features, target, k)
7676
print(S)
7777

experiment/feature_selection/main.py renamed to experiment/omp/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def run(features: np.ndarray, target: np.ndarray, k: int) -> np.ndarray:
8282

8383

8484
def main(dataset: str, k: int) -> None:
85-
features = np.load(f"experiment/feature_selection/{dataset}_features.npy")
86-
target = np.load(f"experiment/feature_selection/{dataset}_target.npy")
85+
features = np.load(f"experiment/omp/{dataset}_features.npy")
86+
target = np.load(f"experiment/omp/{dataset}_target.npy")
8787
S = run(features, target, k)
8888
print(S)
8989

experiment/feature_selection/naive.py renamed to experiment/omp/naive.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ def run(features: np.ndarray, target: np.ndarray, k: int) -> np.ndarray:
137137

138138

139139
def main(dataset: str, k: int) -> None:
140-
features = np.load(f"experiment/feature_selection/{dataset}_features.npy")
141-
target = np.load(f"experiment/feature_selection/{dataset}_target.npy")
140+
features = np.load(f"experiment/omp/{dataset}_features.npy")
141+
target = np.load(f"experiment/omp/{dataset}_target.npy")
142142
S = run(features, target, k)
143143
print(S)
144144

experiment/feature_selection/vm.py renamed to experiment/omp/vm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def log(idx: int, k: int) -> None:
2020
def run(features: np.ndarray, target: np.ndarray, k: int) -> np.ndarray:
2121
"""select k features from features using target as the target variable"""
2222
S = np.array([], "int")
23-
with persist.SimpleTcpClient("feature_selection") as client:
23+
with persist.SimpleTcpClient("omp") as client:
2424
for idx in client.iterate(range(k)): # type: int
2525
log(idx, k)
2626
dims = np.unique(S[S >= 0])
@@ -68,8 +68,8 @@ def run(features: np.ndarray, target: np.ndarray, k: int) -> np.ndarray:
6868

6969

7070
def main(dataset: str, k: int) -> None:
71-
features = np.load(f"experiment/feature_selection/{dataset}_features.npy")
72-
target = np.load(f"experiment/feature_selection/{dataset}_target.npy")
71+
features = np.load(f"experiment/omp/{dataset}_features.npy")
72+
target = np.load(f"experiment/omp/{dataset}_target.npy")
7373
S = run(features, target, k)
7474
print(S)
7575

scripts/coredump.c

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <limits.h>
4+
#include <sys/ptrace.h>
5+
#include <sys/wait.h>
6+
7+
#define pageLength 4096
8+
9+
static void dump_memory_region(FILE* pMemFile, unsigned long start_address, long length) {
10+
static unsigned char page[pageLength];
11+
fseeko(pMemFile, start_address, SEEK_SET);
12+
size_t bytes_read=1;
13+
for (unsigned long address=start_address; address < start_address + length; address += bytes_read) {
14+
bytes_read = fread(&page, 1, pageLength, pMemFile);
15+
fwrite(&page, 1, bytes_read, stdout);
16+
if (bytes_read == 0) {
17+
break;
18+
}
19+
}
20+
}
21+
22+
static FILE* open_proc(int pid, const char* basename) {
23+
static char buf[256];
24+
sprintf(buf, "/proc/%d/%s", pid, basename);
25+
return fopen(buf, "r");
26+
}
27+
28+
int main(int argc, char **argv) {
29+
if (argc != 2) {
30+
fprintf(stderr, "Usage:\n");
31+
fprintf(stderr, "%s <pid>\n", argv[0]);
32+
exit(1);
33+
}
34+
const int pid = atoi(argv[1]);
35+
if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
36+
printf("Unable to attach to the pid specified\n");
37+
exit(1);
38+
}
39+
wait(NULL);
40+
41+
FILE* pMapsFile = open_proc(pid, "maps");
42+
FILE* pMemFile = open_proc(pid, "mem");
43+
44+
char line[256];
45+
while (fgets(line, 256, pMapsFile) != NULL) {
46+
unsigned long start_address;
47+
unsigned long end_address;
48+
sscanf(line, "%lx-%lx %*[^\n]\n", &start_address, &end_address);
49+
fprintf(stderr, "%lx-%lx\n", start_address, end_address);
50+
dump_memory_region(pMemFile, start_address, end_address - start_address);
51+
}
52+
fclose(pMapsFile);
53+
fclose(pMemFile);
54+
55+
ptrace(PTRACE_CONT, pid, NULL, NULL);
56+
ptrace(PTRACE_DETACH, pid, NULL, NULL);
57+
return 0;
58+
}

scripts/dump-all-memory-of-pid.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/bash
22
# see https://serverfault.com/a/408929/298972
33

4+
folder="dumps/$1"
5+
mkdir -p "$folder"
6+
47
grep rw-p "/proc/$1/maps" \
58
| sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p' \
69
| while read -r start stop; do \
710
gdb --batch --pid "$1" -ex \
8-
"dump memory $1-$start-$stop.dump 0x$start 0x$stop"; \
11+
"dump memory $folder/$start-$stop.dump 0x$start 0x$stop"; \
912
done

scripts/vm.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ runcmd:
9595
EOF
9696

9797
user_data="${INSTANCE_DIR}/user-data.qcow2"
98-
cloud-localds ${user_data} ${yaml_file} --disk-format=qcow2
98+
cloud-localds "${user_data}" "${yaml_file}" --disk-format=qcow2
9999

100+
# shellcheck disable=SC2054
100101
args=(
101102
-cpu host
102103
-smp 1
@@ -106,16 +107,16 @@ args=(
106107
-enable-kvm
107108
-m 2G
108109
# -serial mon:stdio # use console for monitor
109-
-qmp tcp:localhost:${QMP_PORT},server=on,wait=off
110+
-qmp "tcp:localhost:${QMP_PORT},server=on,wait=off"
110111
# -nic user
111112
-device virtio-net-pci,netdev=n1
112-
-netdev user,id=n1,hostfwd=tcp::10022-:22
113+
-netdev "user,id=n1,hostfwd=tcp::10022-:${TCP_PORT}"
113114
-nographic
114115
# -display none
115116
# -daemonize
116117
)
117118

118-
${QEMU_DIR}qemu-system-x86_64 "${args[@]}"
119+
"${QEMU_DIR}"qemu-system-x86_64 "${args[@]}"
119120
# args=(
120121
# --name nvram-vm
121122
# --cpu host

tests/test_generate.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def naive_transform(filename: pathlib.Path, expected_outfile: pathlib.Path) -> N
2828

2929

3030
@pytest.mark.parametrize(
31-
"experiment_name", ["k_means", "feature_selection", "pivoter", "trivial"]
31+
"experiment_name", ["k_means", "omp", "pivoter", "trivial"]
3232
)
3333
def test_naive_transformation(experiment_name: str) -> None:
3434
exp = pathlib.Path("experiment") / experiment_name
@@ -46,7 +46,7 @@ def tcp_transform(
4646

4747

4848
@pytest.mark.parametrize(
49-
"experiment_name", ["k_means", "feature_selection", "pivoter", "trivial"]
49+
"experiment_name", ["k_means", "omp", "pivoter", "trivial"]
5050
)
5151
def test_tcp_transformation(experiment_name: str) -> None:
5252
exp = pathlib.Path("experiment") / experiment_name
@@ -76,9 +76,9 @@ def analyze_and_transform(
7676

7777

7878
@pytest.mark.parametrize("simplify", [True, False])
79-
def test_analyze_feature_selection(simplify: bool) -> None:
79+
def test_analyze_omp(simplify: bool) -> None:
8080
analyze_and_transform(
81-
experiment_name="feature_selection",
81+
experiment_name="omp",
8282
function_name="run",
8383
simplify=simplify,
8484
)

tests/test_instrument.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def run(fuel: int) -> str:
1616
assert actual == expected
1717

1818

19-
def test_instrument_feature_selection() -> None:
19+
def test_instrument_omp() -> None:
2020
instrument_experiment(
21-
experiment_name="feature_selection",
21+
experiment_name="omp",
2222
args="healthstudy --k 50".split(),
2323
)
2424

0 commit comments

Comments
 (0)