Skip to content

Commit a2cf101

Browse files
authored
Warn the user about aliasing effect (#1392)
If the user chooses an even number for the `-e` option of `capture.py`, it may get misleading results if the GCs alternate between two different behaviors, such as nursery GC and full-heap GC. We now warn the user if the value of `-e` is an even number.
1 parent 27b4521 commit a2cf101

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

tools/tracing/timeline/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,23 @@ Suite.
1919
Run the following command with a **normal** user (*not* as `root` or using `sudo`):
2020

2121
```shell
22-
./capture.py -e 50 -m /path/to/libmmtk_openjdk.so --no-root-nodes
22+
./capture.py -e 47 -m /path/to/libmmtk_openjdk.so --no-root-nodes
2323
```
2424

25-
`-e 50` means we only capture one GC in every 50 GCs because otherwise it will have to print too
25+
`-e 47` means we only capture one GC in every 47 GCs because otherwise it will have to print too
2626
much log. (Note: Printing in bpftrace is done via a fixed-size user/kernel space buffer, therefore
2727
excessive printing will overrun the buffer and cause events to be dropped. The `-e` option helps
2828
reducing the volume of log, thereby reducing the likelihood of buffer overrun and the time for
2929
post-processing. If one single GC still produces too much log and overruns the buffer, the user
3030
should consider setting the `BPFTRACE_PERF_RB_PAGES` environment variable. See the man page of
31-
`bpftrace`.)
31+
`bpftrace`.) We choose a large prime number, such as 47, because some GCs may exhibit periodic
32+
behaviors under certain workloads. For example, generational GCs may alternate between nursery and
33+
full-heap GC, making every odd GC a nursey GC, and every even GC a full-heap GC. If we capture
34+
every 50th GC, we will only observe even or odd GCs because 50 is an even number, and it will give
35+
us an illusion of "all GCs are nursery GC" or "all GCs are full-heap GC". This is an instance of
36+
[aliasing effect].
37+
38+
[aliasing effect]: https://en.wikipedia.org/wiki/Aliasing
3239

3340
`--no-root-nodes` skips the `process_root_nodes` USDT which does not exist in `libmmtk_openjdk.so`.
3441

@@ -86,7 +93,7 @@ This means things are working properly. Now re-run `./capture.py` again, but pi
8693
file.
8794

8895
```
89-
./capture.py -m /path/to/libmmtk_openjdk.so --no-root-nodes > mybenchmark.log
96+
./capture.py -e 47 -m /path/to/libmmtk_openjdk.so --no-root-nodes > mybenchmark.log
9097
```
9198

9299
Type the root password if prompted.

tools/tracing/timeline/capture.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def delete_lines_between(lines, begin, end):
5454
raise Exception(f"Cannot find {begin} and {end} in the script. {begin_index} {end_index}")
5555
del lines[begin_index:end_index + 1]
5656

57+
def eprint(*args, **kwargs):
58+
print(*args, **kwargs, file=sys.stderr)
59+
5760
def main():
5861
args = get_args()
5962
here = Path(__file__).parent.resolve()
@@ -84,7 +87,7 @@ def main():
8487
MMTK=mmtk_bin,
8588
TMP_FILE=tmp.name)
8689
if args.print_script:
87-
print(content)
90+
eprint(content)
8891
tmp.write(content)
8992
tmp.flush()
9093

@@ -94,9 +97,14 @@ def main():
9497

9598
command_line = ["sudo", args.bpftrace] + extra_options + ["--unsafe", tmp.name]
9699

100+
if args.every % 2 == 0:
101+
eprint(f"""\
102+
WARNING! The value of the --every option is {args.every} which is an even number.
103+
You may observe misleading results due to aliasing effect. See README.md""")
104+
97105
if args.dry_run:
98-
print("Dry run. Command to execute:")
99-
print(" ".join(f"'{c}'" for c in command_line))
106+
eprint("Dry run. Command to execute:")
107+
eprint(" ".join(f"'{c}'" for c in command_line))
100108
# tempfile will be deleted at the end of `with`.
101109
else:
102110
# We use execvp to replace the current process instead of creating

0 commit comments

Comments
 (0)