perf: enable compression of record mode trace to save storage space
Subsystems (2)
v5 cover perf: enable compression of record mode trace to save storage space
The patch set implements runtime trace compression (-z option) in record mode and trace auto decompression in report and inject modes. Streaming Zstandard (Zstd) API (zstd) is used for compression and decompression of data that come from kernel mmaped data buffers.
Usage of implemented -z,--compression_level=n option provides ~3-5x avg. trace file size reduction on variety of tested workloads what saves storage space on larger server systems where trace file size can easily reach several tens or even hundreds of GiBs, especially when profiling with dwarf-based stacks and tracing of context switches. Implemented -f,--mmap-flush option can be used to avoid compressing every single byte of data and increase compression ratio at the same time lowering tool runtime overhead. Default option value is 1 what is equal to the current perf record implementation. The option is independent from -z setting and doesn't vary with compression level:
$ tools/perf/perf record -z 1 -e cycles -- matrix.gcc $ tools/perf/perf record --aio=1 -z 1 -e cycles -- matrix.gcc $ tools/perf/perf record -z 1 -f 1024 -e cycles -- matrix.gcc $ tools/perf/perf record --aio=1 -z 1 -f 1024 -e cycles -- matrix.gcc
Runtime compression overhead has been measured for serial and AIO trace writing modes when profiling matrix multiplication workload with the following results:
-------------------------------------------------------------
| SERIAL | AIO-1 |
-----------------------------------------------------------------
|-z | OVH(x) | ratio(x) size(MiB) | OVH(x) | ratio(x) size(MiB) | |---------------------------------------------------------------- | 0 | 1,00 | 1,000 179,424 | 1,00 | 1,000 187,527 | | 1 | 1,04 | 8,427 181,148 | 1,01 | 8,474 188,562 | | 2 | 1,07 | 8,055 186,953 | 1,03 | 7,912 191,773 | | 3 | 1,04 | 8,283 181,908 | 1,03 | 8,220 191,078 | | 5 | 1,09 | 8,101 187,705 | 1,05 | 7,780 190,065 | | 8 | 1,05 | 9,217 179,191 | 1,12 | 6,111 193,024 |
-----------------------------------------------------------------
OVH = (Execution time with -z N) / (Execution time with -z 0)
ratio - compression ratio
size - number of bytes that was compressed
size ~= trace file x ratio
See complete description of measurement conditions with details below.
Introduced compression functionality can be disabled or configured from the command line using NO_LIBZSTD and LIBZSTD_DIR defines:
$ make -C tools/perf NO_LIBZSTD=1 clean all $ make -C tools/perf LIBZSTD_DIR=/path/to/zstd/sources/ clean all
If your system has some version of the zstd package preinstalled then the build system finds and uses it during the build. Auto detection feature status is reported just before compilation starts, as usual. If you still prefer to compile with some version of zstd that is not preinstalled you have capability to refer the compilation to that version using LIBZSTD_DIR define.
See 'perf test' results below for enabled and disabled (NO_LIBZSTD=1) feature configurations.
---
Alexey Budankov (10):
feature: implement libzstd check, LIBZSTD_DIR and NO_LIBZSTD defines perf record: implement -f,--mmap-flush=<threshold> option perf session: define bytes_transferred and bytes_compressed metrics perf record: implement COMPRESSED event record and its attributes perf mmap: implement dedicated memory buffer for data compression perf util: introduce Zstd based streaming compression API perf record: implement -z,--compression_level=n option and compression perf report: implement record trace decompression
perf inject: enable COMPRESSED records decompression
perf tests: implement Zstd comp/decomp integration test
tools/build/Makefile.feature | 6 +- tools/build/feature/Makefile | 6 +- tools/build/feature/test-all.c | 5 + tools/build/feature/test-libzstd.c | 12 ++ tools/perf/Documentation/perf-record.txt | 18 ++ tools/perf/Makefile.config | 20 +++ tools/perf/Makefile.perf | 3 + tools/perf/builtin-inject.c | 4 + tools/perf/builtin-record.c | 159 +++++++++++++++--- tools/perf/builtin-report.c | 5 +- tools/perf/builtin-version.c | 2 + tools/perf/perf.h | 2 + .../tests/shell/record+zstd_comp_decomp.sh | 28 +++ tools/perf/util/Build | 2 + tools/perf/util/compress.h | 22 +++ tools/perf/util/env.h | 11 ++ tools/perf/util/event.c | 1 + tools/perf/util/event.h | 7 + tools/perf/util/evlist.c | 8 +- tools/perf/util/evlist.h | 3 +- tools/perf/util/header.c | 55 +++++- tools/perf/util/header.h | 1 + tools/perf/util/mmap.c | 65 +++++-- tools/perf/util/mmap.h | 18 +- tools/perf/util/session.c | 124 +++++++++++++- tools/perf/util/session.h | 14 ++ tools/perf/util/tool.h | 2 + tools/perf/util/zstd.c | 143 ++++++++++++++++ 28 files changed, 700 insertions(+), 46 deletions(-) create mode 100644 tools/build/feature/test-libzstd.c create mode 100755 tools/perf/tests/shell/record+zstd_comp_decomp.sh create mode 100644 tools/perf/util/zstd.c
---
Changes in v5:
- implemented perf version --build-options extension for aio and zstd - see TESTING below
- adjusted commit message and perf-record.txt content for -f option
- fixed build errors in case of NO_AIO=1 and NO_LIBZSTD=1
Changes in v4:
- implemented integration tests
- adjusted zstd_ stub functions
- rebased on tip of Arnaldo's perf/core
Changes in v3:
- moved -f,--mmap-flush option implementation into a separate patch
- moved definition and printing of bytes_transferred and bytes_compressed into a separate patch
- moved COMPRESSED feature into a separate patch
- added versioning and stored COMPRESSED feature attributes as u32
- implemented dedicated memory buffer for compression in case of serial streaming
- moved low level Zstd based compression functions into util/{compress.h,zstd.c}
- made compress function to be a param of __push(), __aio_push() functions
- enabled perf inject to decompress COMPRESSED records
- measured compression overhead for serial and AIO streaming using
basic matrix multiplication workload on 8 core skylake
Changes in v2:
- moved compression/decompression code to session layer
- enabled allocation aio data buffers for compression
- enabled trace compression for serial trace streaming
---
[1] https://github.com/facebook/zstd
---
OVERHEAD MEASUREMENTS:
uname -a
Linux localhost 4.20.7-200.fc29.x86_64 #1 SMP Wed Feb 6 19:16:42 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
cat /proc/cpuinfo
processor : 7vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
stepping : 3
microcode : 0xc6
cpu MHz : 4021.884
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
apicid : 7
initial apicid : 7
fpu : yesfpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips : 8016.00
clflush size : 64cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
-----------------------------------------------------------------
#!/bin/bash -xv
echo 0 > /proc/sys/kernel/perf_event_paranoid
+ echo 0
cat /proc/sys/kernel/perf_event_paranoid
+ cat /proc/sys/kernel/perf_event_paranoid
0
echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
+ echo performance
+ tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor /sys/devices/system/cpu/cpu5/cpufreq/scaling_governor /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor /sys/devices/system/cpu/cpu7/cpufreq/scaling_governor performance
for i in 0 1 2 3 5 8
do
/usr/bin/time tools/perf/perf record -z $i -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc
done
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record -z 0 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7fe36de5c010
Offs of buf1 = 0x7fe36de5c180
Addr of buf2 = 0x7fe36be5b010
Offs of buf2 = 0x7fe36be5b1c0
Addr of buf3 = 0x7fe369e5a010
Offs of buf3 = 0x7fe369e5a100
Addr of buf4 = 0x7fe367e59010
Offs of buf4 = 0x7fe367e59140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 16.949 seconds
[ perf record: Woken up 309 times to write data ]
[ perf record: Captured and wrote 179.424 MB perf.data ]
133.67user 0.35system 0:17.08elapsed 784%CPU (0avgtext+0avgdata 100580maxresident)k 0inputs+367480outputs (0major+34737minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record -z 1 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7fcaec334010
Offs of buf1 = 0x7fcaec334180
Addr of buf2 = 0x7fcaea333010
Offs of buf2 = 0x7fcaea3331c0
Addr of buf3 = 0x7fcae8332010
Offs of buf3 = 0x7fcae8332100
Addr of buf4 = 0x7fcae6331010
Offs of buf4 = 0x7fcae6331140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 17.608 seconds
[ perf record: Woken up 595 times to write data ]
[ perf record: Compressed 181.148 MB to 21.497 MB, ratio is 8.427 ]
[ perf record: Captured and wrote 21.527 MB perf.data ]
135.69user 0.24system 0:17.73elapsed 766%CPU (0avgtext+0avgdata 100500maxresident)k 0inputs+44112outputs (0major+35033minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record -z 2 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7f1336f8d010
Offs of buf1 = 0x7f1336f8d180
Addr of buf2 = 0x7f1334f8c010
Offs of buf2 = 0x7f1334f8c1c0
Addr of buf3 = 0x7f1332f8b010
Offs of buf3 = 0x7f1332f8b100
Addr of buf4 = 0x7f1330f8a010
Offs of buf4 = 0x7f1330f8a140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 18.175 seconds
[ perf record: Woken up 521 times to write data ]
[ perf record: Compressed 186.953 MB to 23.210 MB, ratio is 8.055 ]
[ perf record: Captured and wrote 23.239 MB perf.data ]
140.21user 0.25system 0:18.32elapsed 766%CPU (0avgtext+0avgdata 100560maxresident)k 0inputs+47608outputs (0major+35263minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record -z 3 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7f97060e3010
Offs of buf1 = 0x7f97060e3180
Addr of buf2 = 0x7f97040e2010
Offs of buf2 = 0x7f97040e21c0
Addr of buf3 = 0x7f97020e1010
Offs of buf3 = 0x7f97020e1100
Addr of buf4 = 0x7f97000e0010
Offs of buf4 = 0x7f97000e0140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 17.688 seconds
[ perf record: Woken up 485 times to write data ]
[ perf record: Compressed 181.908 MB to 21.962 MB, ratio is 8.283 ]
[ perf record: Captured and wrote 21.991 MB perf.data ]
136.87user 0.23system 0:17.81elapsed 769%CPU (0avgtext+0avgdata 100616maxresident)k 0inputs+45064outputs (0major+35773minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record -z 5 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7f477b444010
Offs of buf1 = 0x7f477b444180
Addr of buf2 = 0x7f4779443010
Offs of buf2 = 0x7f47794431c0
Addr of buf3 = 0x7f4777442010
Offs of buf3 = 0x7f4777442100
Addr of buf4 = 0x7f4775441010
Offs of buf4 = 0x7f4775441140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 18.406 seconds
[ perf record: Woken up 416 times to write data ]
[ perf record: Compressed 187.705 MB to 23.170 MB, ratio is 8.101 ]
[ perf record: Captured and wrote 23.200 MB perf.data ]
142.72user 0.26system 0:18.53elapsed 771%CPU (0avgtext+0avgdata 100520maxresident)k 0inputs+47528outputs (0major+36928minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record -z 8 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7fb5bf032010
Offs of buf1 = 0x7fb5bf032180
Addr of buf2 = 0x7fb5bd031010
Offs of buf2 = 0x7fb5bd0311c0
Addr of buf3 = 0x7fb5bb030010
Offs of buf3 = 0x7fb5bb030100
Addr of buf4 = 0x7fb5b902f010
Offs of buf4 = 0x7fb5b902f140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 17.751 seconds
[ perf record: Woken up 391 times to write data ]
[ perf record: Compressed 179.191 MB to 19.441 MB, ratio is 9.217 ]
[ perf record: Captured and wrote 19.502 MB perf.data ]
138.90user 0.29system 0:17.88elapsed 778%CPU (0avgtext+0avgdata 100612maxresident)k 0inputs+39968outputs (0major+37436minor)pagefaults 0swaps
for i in 0 1 2 3 5 8
do
/usr/bin/time tools/perf/perf record --aio=1 -z $i -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc
done
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record --aio=1 -z 0 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7feee4519010
Offs of buf1 = 0x7feee4519180
Addr of buf2 = 0x7feee2518010
Offs of buf2 = 0x7feee25181c0
Addr of buf3 = 0x7feee0517010
Offs of buf3 = 0x7feee0517100
Addr of buf4 = 0x7feede516010
Offs of buf4 = 0x7feede516140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 17.912 seconds
[ perf record: Woken up 390 times to write data ]
[ perf record: Captured and wrote 187.527 MB perf.data ]
139.70user 0.39system 0:18.04elapsed 776%CPU (0avgtext+0avgdata 100624maxresident)k 0inputs+384072outputs (0major+35257minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record --aio=1 -z 1 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7f72b93ac010
Offs of buf1 = 0x7f72b93ac180
Addr of buf2 = 0x7f72b73ab010
Offs of buf2 = 0x7f72b73ab1c0
Addr of buf3 = 0x7f72b53aa010
Offs of buf3 = 0x7f72b53aa100
Addr of buf4 = 0x7f72b33a9010
Offs of buf4 = 0x7f72b33a9140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 18.198 seconds
[ perf record: Woken up 416 times to write data ]
[ perf record: Compressed 188.562 MB to 22.252 MB, ratio is 8.474 ]
[ perf record: Captured and wrote 22.284 MB perf.data ]
141.12user 0.32system 0:18.32elapsed 771%CPU (0avgtext+0avgdata 100576maxresident)k 0inputs+45664outputs (0major+35040minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record --aio=1 -z 2 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7ffb9caf3010
Offs of buf1 = 0x7ffb9caf3180
Addr of buf2 = 0x7ffb9aaf2010
Offs of buf2 = 0x7ffb9aaf21c0
Addr of buf3 = 0x7ffb98af1010
Offs of buf3 = 0x7ffb98af1100
Addr of buf4 = 0x7ffb96af0010
Offs of buf4 = 0x7ffb96af0140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 18.360 seconds
[ perf record: Woken up 442 times to write data ]
[ perf record: Compressed 191.773 MB to 24.238 MB, ratio is 7.912 ]
[ perf record: Captured and wrote 24.290 MB perf.data ]
143.76user 0.49system 0:18.50elapsed 779%CPU (0avgtext+0avgdata 100596maxresident)k 0inputs+49760outputs (0major+35276minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record --aio=1 -z 3 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7f13f2df2010
Offs of buf1 = 0x7f13f2df2180
Addr of buf2 = 0x7f13f0df1010
Offs of buf2 = 0x7f13f0df11c0
Addr of buf3 = 0x7f13eedf0010
Offs of buf3 = 0x7f13eedf0100
Addr of buf4 = 0x7f13ecdef010
Offs of buf4 = 0x7f13ecdef140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 18.383 seconds
[ perf record: Woken up 499 times to write data ]
[ perf record: Compressed 191.078 MB to 23.246 MB, ratio is 8.220 ]
[ perf record: Captured and wrote 23.282 MB perf.data ]
143.72user 0.34system 0:18.51elapsed 778%CPU (0avgtext+0avgdata 100616maxresident)k 0inputs+47704outputs (0major+35783minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record --aio=1 -z 5 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7fca0d091010
Offs of buf1 = 0x7fca0d091180
Addr of buf2 = 0x7fca0b090010
Offs of buf2 = 0x7fca0b0901c0
Addr of buf3 = 0x7fca0908f010
Offs of buf3 = 0x7fca0908f100
Addr of buf4 = 0x7fca0708e010
Offs of buf4 = 0x7fca0708e140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 18.758 seconds
[ perf record: Woken up 535 times to write data ]
[ perf record: Compressed 190.065 MB to 24.430 MB, ratio is 7.780 ]
[ perf record: Captured and wrote 24.519 MB perf.data ]
144.62user 0.66system 0:18.88elapsed 769%CPU (0avgtext+0avgdata 100528maxresident)k 0inputs+50232outputs (0major+36942minor)pagefaults 0swaps
+ for i in 0 1 2 3 5 8
+ /usr/bin/time tools/perf/perf record --aio=1 -z 8 -F 25000 -N -B -T -R -e cycles -- ../../matrix/linux/matrix.gcc Addr of buf1 = 0x7f7e1f449010
Offs of buf1 = 0x7f7e1f449180
Addr of buf2 = 0x7f7e1d448010
Offs of buf2 = 0x7f7e1d4481c0
Addr of buf3 = 0x7f7e1b447010
Offs of buf3 = 0x7f7e1b447100
Addr of buf4 = 0x7f7e19446010
Offs of buf4 = 0x7f7e19446140
Threads #: 8 Pthreads
Matrix size: 2048
Using multiply kernel: multiply1
Execution time = 20.103 seconds
[ perf record: Woken up 260 times to write data ]
[ perf record: Compressed 193.024 MB to 31.588 MB, ratio is 6.111 ]
[ perf record: Captured and wrote 32.139 MB perf.data ]
151.73user 4.21system 0:20.23elapsed 770%CPU (0avgtext+0avgdata 100616maxresident)k 0inputs+65848outputs (0major+37431minor)pagefaults 0swaps
---
TESTING:
$ tools/perf/perf version --build-options
perf version 4.13.rc5.gd8d056b
dwarf: [ on ] # HAVE_DWARF_SUPPORT
dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT
glibc: [ on ] # HAVE_GLIBC_SUPPORT
gtk2: [ on ] # HAVE_GTK2_SUPPORT
syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT
libbfd: [ on ] # HAVE_LIBBFD_SUPPORT
libelf: [ on ] # HAVE_LIBELF_SUPPORT
libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT
numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT
libperl: [ on ] # HAVE_LIBPERL_SUPPORT
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
libslang: [ on ] # HAVE_SLANG_SUPPORT
libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT
libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT
libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT
zlib: [ on ] # HAVE_ZLIB_SUPPORT
lzma: [ on ] # HAVE_LZMA_SUPPORT
get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT
bpf: [ on ] # HAVE_LIBBPF_SUPPORT
aio: [ OFF ] # HAVE_AIO_SUPPORT
zstd: [ OFF ] # HAVE_ZSTD_SUPPORT $ tools/perf/perf version --build-options
perf version 4.13.rc5.gd8d056b
dwarf: [ on ] # HAVE_DWARF_SUPPORT
dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT
glibc: [ on ] # HAVE_GLIBC_SUPPORT
gtk2: [ on ] # HAVE_GTK2_SUPPORT
syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT
libbfd: [ on ] # HAVE_LIBBFD_SUPPORT
libelf: [ on ] # HAVE_LIBELF_SUPPORT
libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT
numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT
libperl: [ on ] # HAVE_LIBPERL_SUPPORT
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
libslang: [ on ] # HAVE_SLANG_SUPPORT
libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT
libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT
libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT
zlib: [ on ] # HAVE_ZLIB_SUPPORT
lzma: [ on ] # HAVE_LZMA_SUPPORT
get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT
bpf: [ on ] # HAVE_LIBBPF_SUPPORT
aio: [ on ] # HAVE_AIO_SUPPORT
zstd: [ on ] # HAVE_ZSTD_SUPPORT$ make -C tools/perf clean all ... $ pushd tools/perf/ && ./perf test && popd ~/abudanko/kernel/acme/tools/perf ~/abudanko/kernel/acme 1: vmlinux symtab matches kallsyms : Skip 2: Detect openat syscall event : Ok 3: Detect openat syscall event on all cpus : Ok 4: Read samples using the mmap interface : Ok 5: Test data source output : Ok 6: Parse event definition strings : Ok 7: Simple expression parser : Ok 8: PERF_RECORD_* events & perf_sample fields : Ok 9: Parse perf pmu format : Ok 10: DSO data read : Ok 11: DSO data cache : Ok 12: DSO data reopen : Ok 13: Roundtrip evsel->name : Ok 14: Parse sched tracepoints fields : Ok 15: syscalls:sys_enter_openat event fields : Ok 16: Setup struct perf_event_attr : Ok 17: Match and link multiple hists : Ok 18: 'import perf' in python : Ok 19: Breakpoint overflow signal handler : Ok 20: Breakpoint overflow sampling : Ok 21: Breakpoint accounting : Ok 22: Watchpoint : 22.1: Read Only Watchpoint : Skip 22.2: Write Only Watchpoint : Ok 22.3: Read / Write Watchpoint : Ok 22.4: Modify Watchpoint : Ok 23: Number of exit events of a simple workload : Ok 24: Software clock events period values : Ok 25: Object code reading : Ok 26: Sample parsing : Ok 27: Use a dummy software event to keep tracking : Ok 28: Parse with no sample_id_all bit set : Ok 29: Filter hist entries : Ok 30: Lookup mmap thread : Ok 31: Share thread mg : Ok 32: Sort output of hist entries : Ok 33: Cumulate child hist entries : Ok 34: Track with sched_switch : Ok 35: Filter fds with revents mask in a fdarray : Ok 36: Add fd to a fdarray, making it autogrow : Ok 37: kmod_path__parse : Ok 38: Thread map : Ok 39: LLVM search and compile : 39.1: Basic BPF llvm compile : Skip 39.2: kbuild searching : Skip 39.3: Compile source for BPF prologue generation : Skip 39.4: Compile source for BPF relocation : Skip 40: Session topology : Ok 41: BPF filter : 41.1: Basic BPF filtering : Skip 41.2: BPF pinning : Skip 41.3: BPF prologue generation : Skip 41.4: BPF relocation checker : Skip 42: Synthesize thread map : Ok 43: Remove thread map : Ok 44: Synthesize cpu map : Ok 45: Synthesize stat config : Ok 46: Synthesize stat : Ok 47: Synthesize stat round : Ok 48: Synthesize attr update : Ok 49: Event times : Ok 50: Read backward ring buffer : Ok 51: Print cpu map : Ok 52: Probe SDT events : Ok 53: is_printable_array : Ok 54: Print bitmap : Ok 55: perf hooks : Ok 56: builtin clang support : Skip (not compiled in) 57: unit_number__scnprintf : Ok 58: mem2node : Ok 59: x86 rdpmc : Ok 60: Convert perf time to TSC : Ok 61: DWARF unwind : Ok 62: x86 instruction decoder - new instructions : Ok 63: x86 bp modify : Ok 64: Check open filename arg using perf trace + vfs_getname: Skip 65: Add vfs_getname probe to get syscall args filenames : Skip 66: probe libc's inet_pton & backtrace it with ping : Ok 67: Use vfs_getname probe to get syscall args filenames : Skip 68: record trace Zstd compression/decompression : Ok ~/abudanko/kernel/acme
$ make -C tools/perf NO_LIBZSTD=1 clean all ... $ pushd tools/perf/ && ./perf test && popd ~/abudanko/kernel/acme/tools/perf ~/abudanko/kernel/acme ... 68: record trace Zstd compression/decompression : Skip ~/abudanko/kernel/acme
PATCH v5 1/10 feature: implement libzstd check, LIBZSTD_DIR and NO_LIBZSTD defines
Implement libzstd feature check, NO_LIBZSTD and LIBZSTD_DIR defines to override Zstd library sources or disable the feature from the command line:
$ make -C tools/perf LIBZSTD_DIR=/path/to/zstd/sources/ clean all $ make -C tools/perf NO_LIBZSTD=1 clean all
Auto detection feature status is reported just before compilation starts. If your system has some version of the zstd library preinstalled then the build system finds and uses it during the build.
If you still prefer to compile with some other version of zstd library that is not preinstalled you have capability to refer the compilation to that version using LIBZSTD_DIR define.
---
Changes in v5:
- implemented perf version --build-options extension for aio and zstd
--- tools/build/Makefile.feature | 6 ++++-- tools/build/feature/Makefile | 6 +++++- tools/build/feature/test-all.c | 5 +++++ tools/build/feature/test-libzstd.c | 12 ++++++++++++ tools/perf/Makefile.config | 20 ++++++++++++++++++++ tools/perf/Makefile.perf | 3 +++ tools/perf/builtin-version.c | 2 ++ 7 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 tools/build/feature/test-libzstd.c
tools/build/Makefile.feature +4 -2
@@ -66,7 +66,8 @@ FEATURE_TESTS_BASIC := \ sched_getcpu \ sdt \ setns \ - libaio + libaio \ + libzstd # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests
@@ -118,7 +119,8 @@ FEATURE_DISPLAY ?= \ lzma \ get_cpuid \ bpf \ - libaio + libaio \ + libzstd # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. # If in the future we need per-feature checks/flags for features not
tools/build/feature/Makefile +5 -1
@@ -62,7 +62,8 @@ FILES= \ test-clang.bin \ test-llvm.bin \ test-llvm-version.bin \ - test-libaio.bin + test-libaio.bin \ + test-libzstd.bin FILES := $(addprefix $(OUTPUT),$(FILES))
@@ -301,6 +302,9 @@ $(OUTPUT)test-clang.bin: $(OUTPUT)test-libaio.bin: $(BUILD) -lrt +$(OUTPUT)test-libzstd.bin: + $(BUILD) -lzstd + ############################### clean:
tools/build/feature/test-all.c +5 -0
@@ -178,6 +178,10 @@# include "test-reallocarray.c" #undef main +#define main main_test_zstd +# include "test-libzstd.c" +#undef main +int main (int argc,char *argv[]) {main_test_libpython ();
@@ -219,6 +223,7 @@ int main(int argc, char *argv[])main_test_setns ();main_test_libaio ();main_test_reallocarray (); +main_test_libzstd ();return 0 ; }
tools/build/feature/test-libzstd.c new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <zstd.h> + +int main (void ) +{ +ZSTD_CStream *cstream; + + cstream =ZSTD_createCStream (); +ZSTD_freeCStream (cstream); + +return 0 ; +}
tools/perf/Makefile.config +20 -0
@@ -152,6 +152,13 @@ endif FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS) FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf +ifdef LIBZSTD_DIR + LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib + LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib +endif +FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS) +FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS) + FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi # include ARCH specific config -include $(src-perf)/arch/$(SRCARCH)/Makefile
@@ -782,6 +789,19 @@ ifndef NO_LZMA endif endif +ifndef NO_LIBZSTD + ifeq ($(feature-libzstd), 1) + CFLAGS += -DHAVE_ZSTD_SUPPORT + CFLAGS += $(LIBZSTD_CFLAGS) + LDFLAGS += $(LIBZSTD_LDFLAGS) + EXTLIBS += -lzstd + $(call detected,CONFIG_ZSTD) + else + msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR); + NO_LIBZSTD := 1 + endif +endif + ifndef NO_BACKTRACE ifeq ($(feature-backtrace), 1) CFLAGS += -DHAVE_BACKTRACE_SUPPORT
tools/perf/Makefile.perf +3 -0
@@ -108,6 +108,9 @@ include ../scripts/utilities.mak # streaming for record mode. Currently Posix AIO trace streaming is # supported only when linking with glibc. # +# Define NO_LIBZSTD if you do not want support of Zstandard based runtime +# trace compression in record mode. +# # As per kernel Makefile, avoid funny character set dependencies unexport LC_ALL
tools/perf/builtin-version.c +2 -0
@@ -78,6 +78,8 @@ static void library_status(void)STATUS (HAVE_LZMA_SUPPORT , lzma);STATUS (HAVE_AUXTRACE_SUPPORT , get_cpuid);STATUS (HAVE_LIBBPF_SUPPORT , bpf); +STATUS (HAVE_AIO_SUPPORT , aio); +STATUS (HAVE_ZSTD_SUPPORT , zstd); }int cmd_version (int argc,const char **argv)
Signature · 1 line
2.20.1
PATCH v5 2/10 perf record: implement -f,--mmap-flush=<threshold> option
In reply to Alexey BudankovImplemented -f,--mmap-flush option that specifies minimal size of data chunk that is extracted from mmaped kernel buffer to store into a trace.
$ tools/perf/perf record -f 1024 -e cycles -- matrix.gcc $ tools/perf/perf record --aio -f 1024 -e cycles -- matrix.gcc
Option can serve two purposes the first one is to increase the compression ratio of a trace data and the second one is to avoid live-lock-like self monitoring in system wide (-a) profiling mode.
The default option value is 1 byte what means that every time trace writing thread finds some new data in the mmaped buffer the data is extracted, possibly compressed and written to a trace. Larger data chunks are compressed more effectively in comparison to smaller chunks so extraction of larger chunks from the kernel buffer is preferable from perspective of trace size reduction. So the implemented option allows specifying minimal data chunk size that is more than 1 byte to influence data compression ratio. Also at some cases executing more write syscalls with smaller data size can take longer than executing less write syscalls with bigger data size due to syscall overhead so extracting bigger data chunks specified by the option value could additionally decrease runtime overhead.
Profiling in system wide mode with compression (-a -z) can additionally induce data into the kernel buffers along with the data from monitored processes. If performance data rate and volume from the monitored processes is high then trace streaming and compression activity in the tool is also high and it can lead to subtle live-lock effect of endless activity when compression of single new byte from some of mmaped kernel buffer leads to eneration of the next single byte at some mmaped buffer so perf tool trace writing thread never stops on polling event file descriptors.
Implemented sync param is the mean to force data move independently from the threshold value. Despite the provided flush value from the command line, the tool needs capability to drain memory buffers, at least in the end of the collection.
--- tools/perf/Documentation/perf-record.txt | 13 ++++++ tools/perf/builtin-record.c | 53 +++++++++++++++++++++--- tools/perf/perf.h | 1 + tools/perf/util/evlist.c | 6 +-- tools/perf/util/evlist.h | 3 +- tools/perf/util/mmap.c | 4 +- tools/perf/util/mmap.h | 3 +- 7 files changed, 71 insertions(+), 12 deletions(-)
tools/perf/Documentation/perf-record.txt +13 -0
@@ -459,6 +459,19 @@ Set affinity mask of trace reading thread according to the policy defined by 'mo node - thread affinity mask is set to NUMA node cpu mask of the processed mmap buffer cpu - thread affinity mask is set to cpu of the processed mmap buffer +-f:: +--mmap-flush=n:: +Specify minimal number of bytes that is extracted from mmap data pages and stored +into a trace. Maximal allowed value is a quarter of the size of mmaped data pages. +The default option value is 1 what means that every time trace writing thread finds +some new data in the mmaped buffer the data is extracted, possibly compressed (-z) +and written to a trace. Larger data chunks are compressed more effectively in +comparison to smaller chunks so extraction of larger chunks from the mmap data pages +is preferable from perspective of trace size reduction. Also at some cases +executing less trace write syscalls with bigger data size can take shorter than +executing more trace write syscalls with smaller data size thus lowering runtime +profiling overhead. + --all-kernel:: Configure all used events to run in kernel space.
tools/perf/builtin-record.c +47 -6
135 lines not on this page · raw message
tools/perf/perf.h +1 -0
@@ -85,6 +85,7 @@ struct record_opts {u64 clockid_res_ns;int nr_cblocks;int affinity; +int mmap_flush; };enum perf_affinity {
tools/perf/util/evlist.c +3 -3
@@ -1022,7 +1022,7 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,*/ int perf_evlist__mmap_ex (struct perf_evlist *evlist,unsigned int pages,unsigned int auxtrace_pages, -bool auxtrace_overwrite,int nr_cblocks,int affinity) +bool auxtrace_overwrite,int nr_cblocks,int affinity,int flush) {struct perf_evsel *evsel;const struct cpu_map *cpus = evlist->cpus;
@@ -1032,7 +1032,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,* Its value is decided by evsel's write_backward. * So &mp should not be passed through const pointer. */ -struct mmap_params mp = { .nr_cblocks = nr_cblocks, .affinity = affinity }; +struct mmap_params mp = { .nr_cblocks = nr_cblocks, .affinity = affinity, .flush = flush };if (!evlist->mmap) evlist->mmap =perf_evlist__alloc_mmap (evlist, false);
@@ -1064,7 +1064,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,int perf_evlist__mmap (struct perf_evlist *evlist,unsigned int pages) { -return perf_evlist__mmap_ex (evlist, pages,0 , false,0 ,PERF_AFFINITY_SYS ); +return perf_evlist__mmap_ex (evlist, pages,0 , false,0 ,PERF_AFFINITY_SYS ,1 ); }int perf_evlist__create_maps (struct perf_evlist *evlist,struct target *target)
tools/perf/util/evlist.h +2 -1
@@ -165,7 +165,8 @@ unsigned long perf_event_mlock_kb_in_pages(void);int perf_evlist__mmap_ex (struct perf_evlist *evlist,unsigned int pages,unsigned int auxtrace_pages, -bool auxtrace_overwrite,int nr_cblocks,int affinity); +bool auxtrace_overwrite,int nr_cblocks, +int affinity,int flush);int perf_evlist__mmap (struct perf_evlist *evlist,unsigned int pages);void perf_evlist__munmap (struct perf_evlist *evlist);
tools/perf/util/mmap.c +3 -1
@@ -440,6 +440,8 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int cperf_mmap__setup_affinity_mask (map, mp); + map->flush = mp->flush; +if (auxtrace_mmap__mmap (&map->auxtrace_mmap, &mp->auxtrace_mp, map->base, fd))return -1 ;
@@ -492,7 +494,7 @@ static int __perf_mmap__read_init(struct perf_mmap *md) md->start = md->overwrite ? head : old; md->end = md->overwrite ? old : head; -if (md->start == md->end) +if ((md->end - md->start) < md->flush)return -EAGAIN ; size = md->end - md->start;
tools/perf/util/mmap.h +2 -1
@@ -39,6 +39,7 @@ struct perf_mmap { } aio;#endif cpu_set_t affinity_mask; +u64 flush; };/*
@@ -70,7 +71,7 @@ enum bkw_mmap_state { };struct mmap_params { -int prot, mask, nr_cblocks, affinity; +int prot, mask, nr_cblocks, affinity, flush;struct auxtrace_mmap_params auxtrace_mp; };
Signature · 1 line
2.20.1
Re: [PATCH v5 02/10] perf record: implement -f,--mmap-flush=<threshold> option
On Fri, Mar 01, 2019 at 06:41:44PM +0300, Alexey Budankov wrote:
SNIP
Quoted 18 lines
tools/perf/builtin-record.c +10
-0@@ -334,6 +334,29 @@ static int record__aio_enabled(struct record *rec)return rec->opts.nr_cblocks >0 ; } +#define MMAP_FLUSH_DEFAULT 1 +static int record__mmap_flush_parse (const struct option *opt, +const char *str, +int unset) +{ +int mmap_len; +struct record_opts *opts = (struct record_opts *)opt->value; + +if (unset) +return 0 ;
tools/perf/builtin-record.c static int record__aio_enabled(struct record *rec) · line 356
Quoted 10 lines
tools/perf/builtin-record.c +10
-0+ +if (str) + opts->mmap_flush =strtol (str,NULL ,0 ); +if (!opts->mmap_flush) + opts->mmap_flush =MMAP_FLUSH_DEFAULT ; + + mmap_len =perf_evlist__mmap_size (opts->mmap_pages); +if (opts->mmap_flush > mmap_len /4 ) + opts->mmap_flush = mmap_len /4 ; +
if there's point in this config option, pelase make it configurable as the other size options we have with the B/K/M suffixes
jirka
Re: [PATCH v5 02/10] perf record: implement -f,--mmap-flush=<threshold> option
Quoted 28 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:41:44PM +0300, Alexey Budankov wrote:
SNIP
Quoted 24 lines
tools/perf/builtin-record.c +16
-0@@ -334,6 +334,29 @@ static int record__aio_enabled(struct record *rec)return rec->opts.nr_cblocks >0 ; } +#define MMAP_FLUSH_DEFAULT 1 +static int record__mmap_flush_parse (const struct option *opt, +const char *str, +int unset) +{ +int mmap_len; +struct record_opts *opts = (struct record_opts *)opt->value; + +if (unset) +return 0 ; + +if (str) + opts->mmap_flush =strtol (str,NULL ,0 ); +if (!opts->mmap_flush) + opts->mmap_flush =MMAP_FLUSH_DEFAULT ; +
Quoted 8 lines
tools/perf/builtin-record.c static int record__aio_enabled(struct record *rec) · line 356
Quoted 4 lines
tools/perf/builtin-record.c +4
-0+ mmap_len =perf_evlist__mmap_size (opts->mmap_pages); +if (opts->mmap_flush > mmap_len /4 ) + opts->mmap_flush = mmap_len /4 ; +if there's point in this config option, pelase make it configurable as the other size options we have with the B/K/M suffixes
in v7.
~Alexey
Quoted 3 lines
jirka
Re: [PATCH v5 02/10] perf record: implement -f,--mmap-flush=<threshold> option
In reply to Alexey BudankovOn Fri, Mar 01, 2019 at 06:41:44PM +0300, Alexey Budankov wrote:
SNIP
Quoted 23 lines
static int process_synthesized_event(struct
perf_tool*tool,tools/perf/builtin-record.c +3
-2union perf_event *event, struct perf_sample *sample __maybe_unused,@@ -543,7 +566,8 @@ static int record__mmap_evlist(struct record *rec,if (perf_evlist__mmap_ex (evlist, opts->mmap_pages, opts->auxtrace_mmap_pages, opts->auxtrace_snapshot_mode, - opts->nr_cblocks, opts->affinity) <0 ) { + opts->nr_cblocks, opts->affinity, + opts->mmap_flush) <0 ) {if (errno ==EPERM ) {pr_err ("Permission error mapping pages.\n" "Consider increasing "@@ -733,7 +757,7 @@ static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) }static int record__mmap_read_evlist (struct record *rec,struct perf_evlist *evlist, -bool overwrite) +bool overwrite,bool sync) {u64 bytes_written = rec->bytes_written;int i;
tools/perf/builtin-record.c static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli · line 783
Quoted 4 lines
tools/perf/builtin-record.c +1
-0@@ -756,12 +780,19 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli off =record__aio_get_pos (trace_fd);for (i =0 ; i < evlist->nr_mmaps; i++) { +u64 flush =MMAP_FLUSH_DEFAULT ;
hum, why does this need the initial value?
Quoted 17 lines
tools/perf/builtin-record.c +6
-0struct perf_mmap *map = &maps[i];if (map->base) {record__adjust_affinity (rec, map); +if (sync) { + flush = map->flush; + map->flush =MMAP_FLUSH_DEFAULT ; + }if (!record__aio_enabled (rec)) {if (perf_mmap__push (map, rec, record__pushfn) !=0 ) { +if (sync) + map->flush = flush; rc =-1 ; goto out; }@@ -774,10 +805,14 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli idx =record__aio_sync (map, false);
tools/perf/builtin-record.c static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli · line 815
Quoted 10 lines
tools/perf/builtin-record.c +4
-0if (perf_mmap__aio_push (map, rec, idx, record__aio_pushfn, &off) !=0 ) {record__aio_set_pos (trace_fd, off); +if (sync) + map->flush = flush; rc =-1 ; goto out; } } +if (sync) + map->flush = flush;
is there a point to set this back in case of sync == true? we are going out at this point, right?
jirka
Re: [PATCH v5 02/10] perf record: implement -f,--mmap-flush=<threshold> option
Quoted 29 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:41:44PM +0300, Alexey Budankov wrote:
SNIP
Quoted 25 lines
static int process_synthesized_event(struct
perf_tool*tool,tools/perf/builtin-record.c +3
-2union perf_event *event, struct perf_sample *sample __maybe_unused,@@ -543,7 +566,8 @@ static int record__mmap_evlist(struct record *rec,if (perf_evlist__mmap_ex (evlist, opts->mmap_pages, opts->auxtrace_mmap_pages, opts->auxtrace_snapshot_mode, - opts->nr_cblocks, opts->affinity) <0 ) { + opts->nr_cblocks, opts->affinity, + opts->mmap_flush) <0 ) {if (errno ==EPERM ) {pr_err ("Permission error mapping pages.\n" "Consider increasing "@@ -733,7 +757,7 @@ static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) }static int record__mmap_read_evlist (struct record *rec,struct perf_evlist *evlist, -bool overwrite) +bool overwrite,bool sync) {u64 bytes_written = rec->bytes_written;int i;@@ -756,12 +780,19 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli off =record__aio_get_pos (trace_fd);
Quoted 4 lines
tools/perf/builtin-record.c static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli · line 783
Quoted 2 lines
tools/perf/builtin-record.c +1
-0for (i =0 ; i < evlist->nr_mmaps; i++) { +u64 flush =MMAP_FLUSH_DEFAULT ;hum, why does this need the initial value?
Compiler reported some warning or even error so staying on the safe side.
Quoted 23 lines
Quoted 23 lines
tools/perf/builtin-record.c +8
-0struct perf_mmap *map = &maps[i];if (map->base) {record__adjust_affinity (rec, map); +if (sync) { + flush = map->flush; + map->flush =MMAP_FLUSH_DEFAULT ; + }if (!record__aio_enabled (rec)) {if (perf_mmap__push (map, rec, record__pushfn) !=0 ) { +if (sync) + map->flush = flush; rc =-1 ; goto out; }@@ -774,10 +805,14 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli idx =record__aio_sync (map, false);if (perf_mmap__aio_push (map, rec, idx, record__aio_pushfn, &off) !=0 ) {record__aio_set_pos (trace_fd, off); +if (sync) + map->flush = flush; rc =-1 ;
Quoted 8 lines
tools/perf/builtin-record.c static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli · line 815
Quoted 5 lines
tools/perf/builtin-record.c +2
-0goto out; } } +if (sync) + map->flush = flush;is there a point to set this back in case of sync == true? we are going out at this point, right?
Right, but function should work independently of any external assumption.
~Alexey
Quoted 3 lines
jirka
Re: [PATCH v5 02/10] perf record: implement -f,--mmap-flush=<threshold> option
In reply to Alexey BudankovQuoted 59 lines · Alexey Budankov
Implemented -f,--mmap-flush option that specifies minimal size of data chunk that is extracted from mmaped kernel buffer to store into a trace.
$ tools/perf/perf record -f 1024 -e cycles -- matrix.gcc $ tools/perf/perf record --aio -f 1024 -e cycles -- matrix.gccOption can serve two purposes the first one is to increase the compression ratio of a trace data and the second one is to avoid live-lock-like self monitoring in system wide (-a) profiling mode.
The default option value is 1 byte what means that every time trace writing thread finds some new data in the mmaped buffer the data is extracted, possibly compressed and written to a trace. Larger data chunks are compressed more effectively in comparison to smaller chunks so extraction of larger chunks from the kernel buffer is preferable from perspective of trace size reduction. So the implemented option allows specifying minimal data chunk size that is more than 1 byte to influence data compression ratio. Also at some cases executing more write syscalls with smaller data size can take longer than executing less write syscalls with bigger data size due to syscall overhead so extracting bigger data chunks specified by the option value could additionally decrease runtime overhead.
Profiling in system wide mode with compression (-a -z) can additionally induce data into the kernel buffers along with the data from monitored processes. If performance data rate and volume from the monitored processes is high then trace streaming and compression activity in the tool is also high and it can lead to subtle live-lock effect of endless activity when compression of single new byte from some of mmaped kernel buffer leads to eneration of the next single byte at some mmaped buffer so perf tool trace writing thread never stops on polling event file descriptors.
Implemented sync param is the mean to force data move independently from the threshold value. Despite the provided flush value from the command line, the tool needs capability to drain memory buffers, at least in the end of the collection.
Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/Documentation/perf-record.txt | 13 ++++++ tools/perf/builtin-record.c | 53 +++++++++++++++++++++--- tools/perf/perf.h | 1 + tools/perf/util/evlist.c | 6 +-- tools/perf/util/evlist.h | 3 +- tools/perf/util/mmap.c | 4 +- tools/perf/util/mmap.h | 3 +- 7 files changed, 71 insertions(+), 12 deletions(-)tools/perf/Documentation/perf-record.txt +2
-0@@ -459,6 +459,19 @@ Set affinity mask of trace reading thread according to the policy defined by 'mo node - thread affinity mask is set to NUMA node cpu mask of the processed mmap buffer cpu - thread affinity mask is set to cpu of the processed mmap buffer +-f:: +--mmap-flush=n::
tools/perf/Documentation/perf-record.txt Set affinity mask of trace reading thread according to the policy defined by 'mo · line 473
Quoted 10 lines
tools/perf/Documentation/perf-record.txt +10
-0+Specify minimal number of bytes that is extracted from mmap data pages and stored +into a trace. Maximal allowed value is a quarter of the size of mmaped data pages. +The default option value is 1 what means that every time trace writing thread finds +some new data in the mmaped buffer the data is extracted, possibly compressed (-z) +and written to a trace. Larger data chunks are compressed more effectively in +comparison to smaller chunks so extraction of larger chunks from the mmap data pages +is preferable from perspective of trace size reduction. Also at some cases +executing less trace write syscalls with bigger data size can take shorter than +executing more trace write syscalls with smaller data size thus lowering runtime +profiling overhead.
I was wondering if that's the same we would achieve with ring buffer watermak config on kernel side.. but I guess it does not hurt to have something on user side.. I'm just not sure it makes sense to have a config option for that
I'd understand if we configure some sane value when compression is enabled.. if it makes sense to have this option, I'd allow it only when compression is enabled
jirka
Re: [PATCH v5 02/10] perf record: implement -f,--mmap-flush=<threshold> option
Quoted 67 lines · Jiri Olsa
Quoted 66 lines · Alexey Budankov
Implemented -f,--mmap-flush option that specifies minimal size of data chunk that is extracted from mmaped kernel buffer to store into a trace.
$ tools/perf/perf record -f 1024 -e cycles -- matrix.gcc $ tools/perf/perf record --aio -f 1024 -e cycles -- matrix.gccOption can serve two purposes the first one is to increase the compression ratio of a trace data and the second one is to avoid live-lock-like self monitoring in system wide (-a) profiling mode.
The default option value is 1 byte what means that every time trace writing thread finds some new data in the mmaped buffer the data is extracted, possibly compressed and written to a trace. Larger data chunks are compressed more effectively in comparison to smaller chunks so extraction of larger chunks from the kernel buffer is preferable from perspective of trace size reduction. So the implemented option allows specifying minimal data chunk size that is more than 1 byte to influence data compression ratio. Also at some cases executing more write syscalls with smaller data size can take longer than executing less write syscalls with bigger data size due to syscall overhead so extracting bigger data chunks specified by the option value could additionally decrease runtime overhead.
Profiling in system wide mode with compression (-a -z) can additionally induce data into the kernel buffers along with the data from monitored processes. If performance data rate and volume from the monitored processes is high then trace streaming and compression activity in the tool is also high and it can lead to subtle live-lock effect of endless activity when compression of single new byte from some of mmaped kernel buffer leads to eneration of the next single byte at some mmaped buffer so perf tool trace writing thread never stops on polling event file descriptors.
Implemented sync param is the mean to force data move independently from the threshold value. Despite the provided flush value from the command line, the tool needs capability to drain memory buffers, at least in the end of the collection.
Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/Documentation/perf-record.txt | 13 ++++++ tools/perf/builtin-record.c | 53 +++++++++++++++++++++--- tools/perf/perf.h | 1 + tools/perf/util/evlist.c | 6 +-- tools/perf/util/evlist.h | 3 +- tools/perf/util/mmap.c | 4 +- tools/perf/util/mmap.h | 3 +- 7 files changed, 71 insertions(+), 12 deletions(-)tools/perf/Documentation/perf-record.txt +9
-0@@ -459,6 +459,19 @@ Set affinity mask of trace reading thread according to the policy defined by 'mo node - thread affinity mask is set to NUMA node cpu mask of the processed mmap buffer cpu - thread affinity mask is set to cpu of the processed mmap buffer +-f:: +--mmap-flush=n:: +Specify minimal number of bytes that is extracted from mmap data pages and stored +into a trace. Maximal allowed value is a quarter of the size of mmaped data pages. +The default option value is 1 what means that every time trace writing thread finds +some new data in the mmaped buffer the data is extracted, possibly compressed (-z) +and written to a trace. Larger data chunks are compressed more effectively in +comparison to smaller chunks so extraction of larger chunks from the mmap data pages +is preferable from perspective of trace size reduction. Also at some cases
Quoted 8 lines
tools/perf/Documentation/perf-record.txt Set affinity mask of trace reading thread according to the policy defined by 'mo · line 473
Quoted 3 lines
tools/perf/Documentation/perf-record.txt +3
-0+executing less trace write syscalls with bigger data size can take shorter than +executing more trace write syscalls with smaller data size thus lowering runtime +profiling overhead.I was wondering if that's the same we would achieve with ring buffer watermak config on kernel side.. but I guess it does not hurt to have something on user side.. I'm just not sure it makes sense to have a config option for that
Watermark acts similar but not the same as this option. Watermark signals tool thread that blocks on poll() and it is not the HPC case of high data rate and volume when the thread mostly checks mmaped buffer content in CPU busy loop almost never blocking on poll().
~Alexey
Quoted 7 lines
I'd understand if we configure some sane value when compression is enabled.. if it makes sense to have this option, I'd allow it only when compression is enabled
jirka
Re: [PATCH v5 02/10] perf record: implement -f,--mmap-flush=<threshold> option
In reply to Jiri OlsaQuoted 76 lines · Jiri Olsa
Quoted 59 lines · Alexey Budankov
Implemented -f,--mmap-flush option that specifies minimal size of data chunk that is extracted from mmaped kernel buffer to store into a trace.
$ tools/perf/perf record -f 1024 -e cycles -- matrix.gcc $ tools/perf/perf record --aio -f 1024 -e cycles -- matrix.gccOption can serve two purposes the first one is to increase the compression ratio of a trace data and the second one is to avoid live-lock-like self monitoring in system wide (-a) profiling mode.
The default option value is 1 byte what means that every time trace writing thread finds some new data in the mmaped buffer the data is extracted, possibly compressed and written to a trace. Larger data chunks are compressed more effectively in comparison to smaller chunks so extraction of larger chunks from the kernel buffer is preferable from perspective of trace size reduction. So the implemented option allows specifying minimal data chunk size that is more than 1 byte to influence data compression ratio. Also at some cases executing more write syscalls with smaller data size can take longer than executing less write syscalls with bigger data size due to syscall overhead so extracting bigger data chunks specified by the option value could additionally decrease runtime overhead.
Profiling in system wide mode with compression (-a -z) can additionally induce data into the kernel buffers along with the data from monitored processes. If performance data rate and volume from the monitored processes is high then trace streaming and compression activity in the tool is also high and it can lead to subtle live-lock effect of endless activity when compression of single new byte from some of mmaped kernel buffer leads to eneration of the next single byte at some mmaped buffer so perf tool trace writing thread never stops on polling event file descriptors.
Implemented sync param is the mean to force data move independently from the threshold value. Despite the provided flush value from the command line, the tool needs capability to drain memory buffers, at least in the end of the collection.
Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/Documentation/perf-record.txt | 13 ++++++ tools/perf/builtin-record.c | 53 +++++++++++++++++++++--- tools/perf/perf.h | 1 + tools/perf/util/evlist.c | 6 +-- tools/perf/util/evlist.h | 3 +- tools/perf/util/mmap.c | 4 +- tools/perf/util/mmap.h | 3 +- 7 files changed, 71 insertions(+), 12 deletions(-)tools/perf/Documentation/perf-record.txt +2
-0@@ -459,6 +459,19 @@ Set affinity mask of trace reading thread according to the policy defined by 'mo node - thread affinity mask is set to NUMA node cpu mask of the processed mmap buffer cpu - thread affinity mask is set to cpu of the processed mmap buffer +-f:: +--mmap-flush=n::tools/perf/Documentation/perf-record.txt Set affinity mask of trace reading thread according to the policy defined by 'mo · line 473
Quoted 10 lines
tools/perf/Documentation/perf-record.txt +10
-0+Specify minimal number of bytes that is extracted from mmap data pages and stored +into a trace. Maximal allowed value is a quarter of the size of mmaped data pages. +The default option value is 1 what means that every time trace writing thread finds +some new data in the mmaped buffer the data is extracted, possibly compressed (-z) +and written to a trace. Larger data chunks are compressed more effectively in +comparison to smaller chunks so extraction of larger chunks from the mmap data pages +is preferable from perspective of trace size reduction. Also at some cases +executing less trace write syscalls with bigger data size can take shorter than +executing more trace write syscalls with smaller data size thus lowering runtime +profiling overhead.I was wondering if that's the same we would achieve with ring buffer watermak config on kernel side.. but I guess it does not hurt to have something on user side.. I'm just not sure it makes sense to have a config option for that
Quoted 3 lines
I'd understand if we configure some sane value when compression is enabled.. if it makes sense to have this option, I'd allow it only when compression is enabled
This threshold already exists in the code with default value of 1 byte. New option provides configuration capability for the threshold keeping default the same.
The option is the mean to get around the live lock issue in the tool in case of intensive system wide profiling and the issue is not specific to the compression.
The option gives benefit jointly with compression. The bigger chink is compressed the higher compression ratio it has, limit exists, of course.
~Alexey
Quoted 3 lines
jirka
PATCH v5 3/10 perf session: define bytes_transferred and bytes_compressed metrics
In reply to Alexey BudankovDefine bytes_transferred and bytes_compressed metrics to calculate comp_ratio=transferred/compressed in the end of the data collection.
bytes_transferred accumulates the amount of bytes that was extracted from the mmaped kernel buffers for compression. bytes_compressed accumulates the amount of bytes that was received after applying compression to move to a storage.
--- tools/perf/builtin-record.c | 8 ++++++++ tools/perf/util/env.h | 1 + tools/perf/util/session.h | 2 ++ 3 files changed, 11 insertions(+)
tools/perf/builtin-record.c +8 -0
@@ -1449,6 +1449,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)record__mmap_read_all (rec, true);record__aio_mmap_read_sync (rec); +if (!quiet && rec->session->bytes_transferred && rec->session->bytes_compressed) { +float ratio = (float )rec->session->bytes_transferred/(float )rec->session->bytes_compressed; + + session->header.env.comp_ratio = ratio +0.5 ; +fprintf (stderr,"[ perf record: Compressed %.3f MB to %.3f MB, ratio is %.3f ]\n" , + rec->session->bytes_transferred /1024.0 /1024.0 , rec->session->bytes_compressed /1024.0 /1024.0 , ratio); + } +if (forks) {int exit_status;
tools/perf/util/env.h +1 -0
@@ -64,6 +64,7 @@ struct perf_env {struct memory_node *memory_nodes;unsigned long long memory_bsize;u64 clockid_res_ns; +u32 comp_ratio; };extern struct perf_env perf_env;
tools/perf/util/session.h +2 -0
@@ -35,6 +35,8 @@ struct perf_session {struct ordered_events ordered_events;struct perf_data *data;struct perf_tool *tool; +u64 bytes_transferred; +u64 bytes_compressed; };struct perf_tool ;
Signature · 1 line
2.20.1
Re: [PATCH v5 03/10] perf session: define bytes_transferred and bytes_compressed metrics
Quoted 21 lines · Alexey Budankov
Define
bytes_transferredandbytes_compressedmetrics to calculate comp_ratio=transferred/compressed in the end of the data collection.
bytes_transferredaccumulates the amount of bytes that was extracted from the mmaped kernel buffers for compression.bytes_compressedaccumulates the amount of bytes that was received after applying compression to move to a storage.Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/builtin-record.c | 8 ++++++++ tools/perf/util/env.h | 1 + tools/perf/util/session.h | 2 ++ 3 files changed, 11 insertions(+)tools/perf/builtin-record.c +0
-0
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1455
Quoted 7 lines
tools/perf/builtin-record.c +4
-0@@ -1449,6 +1449,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)record__mmap_read_all (rec, true);record__aio_mmap_read_sync (rec); +if (!quiet && rec->session->bytes_transferred && rec->session->bytes_compressed) { +float ratio = (float )rec->session->bytes_transferred/(float )rec->session->bytes_compressed; + + session->header.env.comp_ratio = ratio +0.5 ;
what's the + 0.5 for?
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1459
Quoted 4 lines
tools/perf/builtin-record.c +4
-0+fprintf (stderr,"[ perf record: Compressed %.3f MB to %.3f MB, ratio is %.3f ]\n" , + rec->session->bytes_transferred /1024.0 /1024.0 , rec->session->bytes_compressed /1024.0 /1024.0 , ratio); + } +
could this be below together with the current:
fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n",
thanks,
jirka
Quoted 31 lines
tools/perf/builtin-record.c +0
-0if (forks) {int exit_status;tools/perf/util/env.h +1
-0@@ -64,6 +64,7 @@ struct perf_env {struct memory_node *memory_nodes;unsigned long long memory_bsize;u64 clockid_res_ns; +u32 comp_ratio; };extern struct perf_env perf_env;tools/perf/util/session.h +2
-0@@ -35,6 +35,8 @@ struct perf_session {struct ordered_events ordered_events;struct perf_data *data;struct perf_tool *tool; +u64 bytes_transferred; +u64 bytes_compressed; };struct perf_tool ;Signature · 1 line
2.20.1
Re: [PATCH v5 03/10] perf session: define bytes_transferred and bytes_compressed metrics
Quoted 25 lines · Jiri Olsa
Quoted 24 lines · Alexey Budankov
Define
bytes_transferredandbytes_compressedmetrics to calculate comp_ratio=transferred/compressed in the end of the data collection.
bytes_transferredaccumulates the amount of bytes that was extracted from the mmaped kernel buffers for compression.bytes_compressedaccumulates the amount of bytes that was received after applying compression to move to a storage.Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/builtin-record.c | 8 ++++++++ tools/perf/util/env.h | 1 + tools/perf/util/session.h | 2 ++ 3 files changed, 11 insertions(+)tools/perf/builtin-record.c +0
-0@@ -1449,6 +1449,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)record__mmap_read_all (rec, true);record__aio_mmap_read_sync (rec);
Quoted 6 lines
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1455
Quoted 4 lines
tools/perf/builtin-record.c +4
-0+if (!quiet && rec->session->bytes_transferred && rec->session->bytes_compressed) { +float ratio = (float )rec->session->bytes_transferred/(float )rec->session->bytes_compressed; + + session->header.env.comp_ratio = ratio +0.5 ;what's the + 0.5 for?
Arithmetic rounding before type cast.
Quoted 9 lines
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1459
Quoted 5 lines
tools/perf/builtin-record.c +4
-0+fprintf (stderr,"[ perf record: Compressed %.3f MB to %.3f MB, ratio is %.3f ]\n" , + rec->session->bytes_transferred /1024.0 /1024.0 , rec->session->bytes_compressed /1024.0 /1024.0 , ratio); + } +could this be below together with the current:
fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n",
Please provide an example of what you exactly mean.
~Alexey
Quoted 36 lines
thanks,
jirkaQuoted 31 lines
tools/perf/builtin-record.c +0
-0if (forks) {int exit_status;tools/perf/util/env.h +1
-0@@ -64,6 +64,7 @@ struct perf_env {struct memory_node *memory_nodes;unsigned long long memory_bsize;u64 clockid_res_ns; +u32 comp_ratio; };extern struct perf_env perf_env;tools/perf/util/session.h +2
-0@@ -35,6 +35,8 @@ struct perf_session {struct ordered_events ordered_events;struct perf_data *data;struct perf_tool *tool; +u64 bytes_transferred; +u64 bytes_compressed; };struct perf_tool ;Signature · 1 line
2.20.1
Re: [PATCH v5 03/10] perf session: define bytes_transferred and bytes_compressed metrics
Quoted 44 lines · Alexey Budankov
Quoted 25 lines · Jiri Olsa
Quoted 24 lines · Alexey Budankov
Define
bytes_transferredandbytes_compressedmetrics to calculate comp_ratio=transferred/compressed in the end of the data collection.
bytes_transferredaccumulates the amount of bytes that was extracted from the mmaped kernel buffers for compression.bytes_compressedaccumulates the amount of bytes that was received after applying compression to move to a storage.Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/builtin-record.c | 8 ++++++++ tools/perf/util/env.h | 1 + tools/perf/util/session.h | 2 ++ 3 files changed, 11 insertions(+)tools/perf/builtin-record.c +0
-0@@ -1449,6 +1449,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)record__mmap_read_all (rec, true);record__aio_mmap_read_sync (rec);Quoted 6 lines
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1455
Quoted 4 lines
tools/perf/builtin-record.c +4
-0+if (!quiet && rec->session->bytes_transferred && rec->session->bytes_compressed) { +float ratio = (float )rec->session->bytes_transferred/(float )rec->session->bytes_compressed; + + session->header.env.comp_ratio = ratio +0.5 ;what's the + 0.5 for?
Arithmetic rounding before type cast.
Quoted 8 lines
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1459
Quoted 5 lines
tools/perf/builtin-record.c +4
-0+fprintf (stderr,"[ perf record: Compressed %.3f MB to %.3f MB, ratio is %.3f ]\n" , + rec->session->bytes_transferred /1024.0 /1024.0 , rec->session->bytes_compressed /1024.0 /1024.0 , ratio); + } +could this be below together with the current:
Quoted 3 lines
Quoted 1 line
fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n",
Please provide an example of what you exactly mean.
It could look like this:
[ perf record: Woken up 101 times to write data ]
[ perf record: Captured and wrote 5.173 MB perf.data (714077 samples), compressed 27.241 MB to 5.160 MB, ratio is 5.279 ]
Any comments?
~Alexey
Quoted 40 lines
~Alexey
Quoted 36 lines
thanks,
jirkaQuoted 31 lines
tools/perf/builtin-record.c +0
-0if (forks) {int exit_status;tools/perf/util/env.h +1
-0@@ -64,6 +64,7 @@ struct perf_env {struct memory_node *memory_nodes;unsigned long long memory_bsize;u64 clockid_res_ns; +u32 comp_ratio; };extern struct perf_env perf_env;tools/perf/util/session.h +2
-0@@ -35,6 +35,8 @@ struct perf_session {struct ordered_events ordered_events;struct perf_data *data;struct perf_tool *tool; +u64 bytes_transferred; +u64 bytes_compressed; };struct perf_tool ;Signature · 1 line
2.20.1
Re: [PATCH v5 03/10] perf session: define bytes_transferred and bytes_compressed metrics
Quoted 45 lines · Alexey Budankov
Quoted 44 lines · Alexey Budankov
Quoted 25 lines · Jiri Olsa
Quoted 24 lines · Alexey Budankov
Define
bytes_transferredandbytes_compressedmetrics to calculate comp_ratio=transferred/compressed in the end of the data collection.
bytes_transferredaccumulates the amount of bytes that was extracted from the mmaped kernel buffers for compression.bytes_compressedaccumulates the amount of bytes that was received after applying compression to move to a storage.Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/builtin-record.c | 8 ++++++++ tools/perf/util/env.h | 1 + tools/perf/util/session.h | 2 ++ 3 files changed, 11 insertions(+)tools/perf/builtin-record.c +0
-0@@ -1449,6 +1449,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)record__mmap_read_all (rec, true);record__aio_mmap_read_sync (rec);Quoted 6 lines
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1455
Quoted 4 lines
tools/perf/builtin-record.c +4
-0+if (!quiet && rec->session->bytes_transferred && rec->session->bytes_compressed) { +float ratio = (float )rec->session->bytes_transferred/(float )rec->session->bytes_compressed; + + session->header.env.comp_ratio = ratio +0.5 ;what's the + 0.5 for?
Arithmetic rounding before type cast.
Quoted 8 lines
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1459
Quoted 5 lines
tools/perf/builtin-record.c +4
-0+fprintf (stderr,"[ perf record: Compressed %.3f MB to %.3f MB, ratio is %.3f ]\n" , + rec->session->bytes_transferred /1024.0 /1024.0 , rec->session->bytes_compressed /1024.0 /1024.0 , ratio); + } +could this be below together with the current:
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n",
Please provide an example of what you exactly mean.
It could look like this:
[ perf record: Woken up 101 times to write data ]
[ perf record: Captured and wrote 5.173 MB perf.data (714077 samples), compressed 27.241 MB to 5.160 MB, ratio is 5.279 ]
yes, maybe we don't need to repeat the original size twice:
[ perf record: Captured and wrote 5.173 MB perf.data (714077 samples), compressed (original 27.241 MB, ratio 5.279) ]
jirka
Re: [PATCH v5 03/10] perf session: define bytes_transferred and bytes_compressed metrics
Quoted 50 lines · Jiri Olsa
Quoted 49 lines · Alexey Budankov
Quoted 47 lines · Alexey Budankov
Quoted 25 lines · Jiri Olsa
Quoted 24 lines · Alexey Budankov
Define
bytes_transferredandbytes_compressedmetrics to calculate comp_ratio=transferred/compressed in the end of the data collection.
bytes_transferredaccumulates the amount of bytes that was extracted from the mmaped kernel buffers for compression.bytes_compressedaccumulates the amount of bytes that was received after applying compression to move to a storage.Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/builtin-record.c | 8 ++++++++ tools/perf/util/env.h | 1 + tools/perf/util/session.h | 2 ++ 3 files changed, 11 insertions(+)tools/perf/builtin-record.c +0
-0@@ -1449,6 +1449,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)record__mmap_read_all (rec, true);record__aio_mmap_read_sync (rec);Quoted 6 lines
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1455
Quoted 4 lines
tools/perf/builtin-record.c +4
-0+if (!quiet && rec->session->bytes_transferred && rec->session->bytes_compressed) { +float ratio = (float )rec->session->bytes_transferred/(float )rec->session->bytes_compressed; + + session->header.env.comp_ratio = ratio +0.5 ;what's the + 0.5 for?
Arithmetic rounding before type cast.
Quoted 9 lines
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 1459
Quoted 5 lines
tools/perf/builtin-record.c +4
-0+fprintf (stderr,"[ perf record: Compressed %.3f MB to %.3f MB, ratio is %.3f ]\n" , + rec->session->bytes_transferred /1024.0 /1024.0 , rec->session->bytes_compressed /1024.0 /1024.0 , ratio); + } +could this be below together with the current:
fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n",
Please provide an example of what you exactly mean.
Quoted 8 lines
Quoted 4 lines
It could look like this:
[ perf record: Woken up 101 times to write data ]
[ perf record: Captured and wrote 5.173 MB perf.data (714077 samples), compressed 27.241 MB to 5.160 MB, ratio is 5.279 ]yes, maybe we don't need to repeat the original size twice:
[ perf record: Captured and wrote 5.173 MB perf.data (714077 samples), compressed (original 27.241 MB, ratio 5.279) ]
Ok, lets have it like this.
~Alexey
Quoted 3 lines
jirka
PATCH v5 4/10 perf record: implement COMPRESSED event record and its attributes
In reply to Alexey BudankovImplemented PERF_RECORD_COMPRESSED event, related data types, header feature and functions to write, read and print feature attributes from the trace header section.
comp_mmap_len preserves the size of mmaped kernel buffer that was used during collection. comp_mmap_len size is used on loading stage as the size of decomp buffer for decompression of COMPRESSED events content.
--- tools/perf/builtin-record.c | 9 ++++++ tools/perf/perf.h | 1 + tools/perf/util/env.h | 10 +++++++ tools/perf/util/event.c | 1 + tools/perf/util/event.h | 7 +++++ tools/perf/util/header.c | 55 ++++++++++++++++++++++++++++++++++++- tools/perf/util/header.h | 1 + 7 files changed, 83 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +9 -0
@@ -357,6 +357,11 @@ static int record__mmap_flush_parse(const struct option *opt,return 0 ; } +static int record__comp_enabled (struct record *rec) +{ +return rec->opts.comp_level >0 ; +} + static int process_synthesized_event(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused,
@@ -872,6 +877,9 @@ static void record__init_features(struct record *rec)if (!(rec->opts.use_clockid && rec->opts.clockid_res_ns))perf_header__clear_feat (&session->header,HEADER_CLOCKID ); +if (!record__comp_enabled (rec)) +perf_header__clear_feat (&session->header,HEADER_COMPRESSED ); +perf_header__clear_feat (&session->header,HEADER_STAT ); }
@@ -1210,6 +1218,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) err =-1 ; goto out_child; } + session->header.env.comp_mmap_len = session->evlist->mmap_len; err =bpf__apply_obj_config ();if (err) {
tools/perf/perf.h +1 -0
@@ -86,6 +86,7 @@ struct record_opts {int nr_cblocks;int affinity;int mmap_flush; +unsigned int comp_level; };enum perf_affinity {
tools/perf/util/env.h +10 -0
@@ -65,6 +65,16 @@ struct perf_env {unsigned long long memory_bsize;u64 clockid_res_ns;u32 comp_ratio; +u32 comp_ver; +u32 comp_type; +u32 comp_level; +u32 comp_mmap_len; +}; + +enum perf_compress_type { +PERF_COMP_NONE =0 , +PERF_COMP_ZSTD , +PERF_COMP_MAX };extern struct perf_env perf_env;
tools/perf/util/event.c +1 -0
@@ -68,6 +68,7 @@ static const char *perf_event__names[] = { [PERF_RECORD_EVENT_UPDATE] = "EVENT_UPDATE", [PERF_RECORD_TIME_CONV] = "TIME_CONV", [PERF_RECORD_HEADER_FEATURE] = "FEATURE", + [PERF_RECORD_COMPRESSED] = "COMPRESSED", };static const char *perf_ns__names[] = {
tools/perf/util/event.h +7 -0
@@ -254,6 +254,7 @@ enum perf_user_event_type { /* above any possible kernel type */PERF_RECORD_EVENT_UPDATE =78 ,PERF_RECORD_TIME_CONV =79 ,PERF_RECORD_HEADER_FEATURE =80 , +PERF_RECORD_COMPRESSED =81 , PERF_RECORD_HEADER_MAX };
@@ -626,6 +627,11 @@ struct feature_event {char data[]; }; +struct compressed_event { +struct perf_event_header header; +char data[]; +}; +union perf_event {struct perf_event_header header;struct mmap_event mmap;
@@ -659,6 +665,7 @@ union perf_event {struct feature_event feat;struct ksymbol_event ksymbol_event;struct bpf_event bpf_event; +struct compressed_event pack; };void perf_event__print_totals (void );
tools/perf/util/header.c +54 -1
79 lines not on this page · raw message
tools/perf/util/header.h +1 -0
@@ -39,6 +39,7 @@ enum {HEADER_SAMPLE_TIME ,HEADER_MEM_TOPOLOGY ,HEADER_CLOCKID , +HEADER_COMPRESSED ,HEADER_LAST_FEATURE , HEADER_FEAT_BITS = 256, };
Signature · 1 line
2.20.1
PATCH v5 5/10 perf mmap: implement dedicated memory buffer for data compression
In reply to Alexey BudankovImplemented mmap data buffer that is used as the memory to operate on when compressing sampling data in case of serial trace streaming.
In case of AIO trace streaming AIO buffers are used to implement sampling data compression.
--- tools/perf/builtin-record.c | 6 +++++- tools/perf/util/evlist.c | 8 +++++--- tools/perf/util/evlist.h | 2 +- tools/perf/util/mmap.c | 30 ++++++++++++++++++++++++++++-- tools/perf/util/mmap.h | 4 +++- 5 files changed, 42 insertions(+), 8 deletions(-)
tools/perf/builtin-record.c +5 -1
@@ -572,7 +572,7 @@ static int record__mmap_evlist(struct record *rec, opts->auxtrace_mmap_pages, opts->auxtrace_snapshot_mode, opts->nr_cblocks, opts->affinity, - opts->mmap_flush) < 0) { + opts->mmap_flush, opts->comp_level) < 0) {if (errno ==EPERM ) {pr_err ("Permission error mapping pages.\n" "Consider increasing "
@@ -2241,6 +2241,10 @@ int cmd_record(int argc, const char **argv)pr_debug ("affinity: %s\n" , affinity_tags[rec->opts.affinity]);pr_debug ("mmap flush: %d\n" , rec->opts.mmap_flush); +if (rec->opts.comp_level >22 ) + rec->opts.comp_level =0 ; +pr_debug ("comp level: %d\n" , rec->opts.comp_level); + err =__cmd_record (&record, argc, argv); out:perf_evlist__delete (rec->evlist);
tools/perf/util/evlist.c +5 -3
@@ -1022,7 +1022,8 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,*/ int perf_evlist__mmap_ex (struct perf_evlist *evlist,unsigned int pages,unsigned int auxtrace_pages, -bool auxtrace_overwrite,int nr_cblocks,int affinity,int flush) +bool auxtrace_overwrite,int nr_cblocks,int affinity,int flush, +int comp_level) {struct perf_evsel *evsel;const struct cpu_map *cpus = evlist->cpus;
@@ -1032,7 +1033,8 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,* Its value is decided by evsel's write_backward. * So &mp should not be passed through const pointer. */ -struct mmap_params mp = { .nr_cblocks = nr_cblocks, .affinity = affinity, .flush = flush }; +struct mmap_params mp = { .nr_cblocks = nr_cblocks, .affinity = affinity, .flush = flush, + .comp_level = comp_level };if (!evlist->mmap) evlist->mmap =perf_evlist__alloc_mmap (evlist, false);
@@ -1064,7 +1066,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,int perf_evlist__mmap (struct perf_evlist *evlist,unsigned int pages) { -return perf_evlist__mmap_ex (evlist, pages,0 , false,0 ,PERF_AFFINITY_SYS ,1 ); +return perf_evlist__mmap_ex (evlist, pages,0 , false,0 ,PERF_AFFINITY_SYS ,1 ,0 ); }int perf_evlist__create_maps (struct perf_evlist *evlist,struct target *target)
tools/perf/util/evlist.h +1 -1
@@ -166,7 +166,7 @@ unsigned long perf_event_mlock_kb_in_pages(void);int perf_evlist__mmap_ex (struct perf_evlist *evlist,unsigned int pages,unsigned int auxtrace_pages,bool auxtrace_overwrite,int nr_cblocks, -int affinity,int flush); +int affinity,int flush,int comp_level);int perf_evlist__mmap (struct perf_evlist *evlist,unsigned int pages);void perf_evlist__munmap (struct perf_evlist *evlist);
tools/perf/util/mmap.c +28 -2
@@ -157,6 +157,10 @@ void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __mayb }#ifdef HAVE_AIO_SUPPORT +static int perf_mmap__aio_enabled (struct perf_mmap *map) +{ +return map->aio.nr_cblocks >0 ; +}#ifdef HAVE_LIBNUMA_SUPPORT static int perf_mmap__aio_alloc (struct perf_mmap *map,int idx)
@@ -198,7 +202,7 @@ static int perf_mmap__aio_bind(struct perf_mmap *map, int idx, int cpu, int affi return 0; } -#else +#else /* !HAVE_LIBNUMA_SUPPORT */ static int perf_mmap__aio_alloc (struct perf_mmap *map,int idx) { map->aio.data[idx] =malloc (perf_mmap__mmap_len (map));
@@ -359,7 +363,12 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, return rc; } -#else +#else /* !HAVE_AIO_SUPPORT */ +static int perf_mmap__aio_enabled (struct perf_mmap *map__maybe_unused ) +{ +return 0 ; +} +static int perf_mmap__aio_mmap (struct perf_mmap *map__maybe_unused ,struct mmap_params *mp__maybe_unused ) {
@@ -374,6 +383,10 @@ static void perf_mmap__aio_munmap(struct perf_mmap *map __maybe_unused)void perf_mmap__munmap (struct perf_mmap *map) {perf_mmap__aio_munmap (map); +if (map->data !=NULL ) { +munmap (map->data,perf_mmap__mmap_len (map)); + map->data =NULL ; + }if (map->base !=NULL ) {munmap (map->base,perf_mmap__mmap_len (map)); map->base =NULL ;
@@ -442,6 +455,19 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int c map->flush = mp->flush; + map->comp_level = mp->comp_level; + +if (map->comp_level && !perf_mmap__aio_enabled (map)) { + map->data =mmap (NULL ,perf_mmap__mmap_len (map),PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); +if (map->data ==MAP_FAILED ) { +pr_debug2 ("failed to mmap data buffer, error %d\n" , + errno); + map->data =NULL ; +return -1 ; + } + } +if (auxtrace_mmap__mmap (&map->auxtrace_mmap, &mp->auxtrace_mp, map->base, fd))return -1 ;
tools/perf/util/mmap.h +3 -1
@@ -40,6 +40,8 @@ struct perf_mmap {#endif cpu_set_t affinity_mask;u64 flush; +void *data; +int comp_level; };/*
@@ -71,7 +73,7 @@ enum bkw_mmap_state { };struct mmap_params { -int prot, mask, nr_cblocks, affinity, flush; +int prot, mask, nr_cblocks, affinity, flush, comp_level;struct auxtrace_mmap_params auxtrace_mp; };
Signature · 1 line
2.20.1
PATCH v5 6/10 perf util: introduce Zstd based streaming compression API
In reply to Alexey BudankovImplemented functions are based on Zstd streaming compression API. The functions are used in runtime to compress data that come from mmaped kernel buffer data and then stored into a trace.
--- tools/perf/util/Build | 2 + tools/perf/util/compress.h | 18 ++++++++ tools/perf/util/zstd.c | 95 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 tools/perf/util/zstd.c
tools/perf/util/Build +2 -0
@@ -145,6 +145,8 @@ perf-y += scripting-engines/ perf-$(CONFIG_ZLIB) += zlib.o perf-$(CONFIG_LZMA) += lzma.o +perf-y += zstd.o + perf-y += demangle-java.o perf-y += demangle-rust.o
tools/perf/util/compress.h +18 -0
@@ -2,6 +2,11 @@#ifndef PERF_COMPRESS_H #define PERF_COMPRESS_H +#include <stdbool.h> +#ifdef HAVE_ZSTD_SUPPORT +#include <zstd.h> +#endif +#ifdef HAVE_ZLIB_SUPPORT int gzip_decompress_to_file (const char *input,int output_fd);bool gzip_is_compressed (const char *input);
@@ -12,4 +17,17 @@ int lzma_decompress_to_file(const char *input, int output_fd);bool lzma_is_compressed (const char *input);#endif +struct zstd_data { +#ifdef HAVE_ZSTD_SUPPORT +ZSTD_CStream *cstream; +#endif +}; + +int zstd_init (struct zstd_data *data,int level); +int zstd_fini (struct zstd_data *data); + +size_t zstd_compress_stream_to_records (struct zstd_data *data, +void *dst,size_t dst_size,void *src,size_t src_size,size_t max_record_size, +size_t process_header (void *record,size_t increment)); +#endif /* PERF_COMPRESS_H */
tools/perf/util/zstd.c new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v5 06/10] perf util: introduce Zstd based streaming compression API
Quoted 4 lines · Alexey Budankov
Implemented functions are based on Zstd streaming compression API. The functions are used in runtime to compress data that come from mmaped kernel buffer data and then stored into a trace.
please describe the usage of the api in the changelog
thanks,
jirka
Quoted 160 lines
Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/util/Build | 2 + tools/perf/util/compress.h | 18 ++++++++ tools/perf/util/zstd.c | 95 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 tools/perf/util/zstd.ctools/perf/util/Build +2
-0@@ -145,6 +145,8 @@ perf-y += scripting-engines/ perf-$(CONFIG_ZLIB) += zlib.o perf-$(CONFIG_LZMA) += lzma.o +perf-y += zstd.o + perf-y += demangle-java.o perf-y += demangle-rust.otools/perf/util/compress.h +18
-0@@ -2,6 +2,11 @@#ifndef PERF_COMPRESS_H #define PERF_COMPRESS_H +#include <stdbool.h> +#ifdef HAVE_ZSTD_SUPPORT +#include <zstd.h> +#endif +#ifdef HAVE_ZLIB_SUPPORT int gzip_decompress_to_file (const char *input,int output_fd);bool gzip_is_compressed (const char *input);@@ -12,4 +17,17 @@ int lzma_decompress_to_file(const char *input, int output_fd);bool lzma_is_compressed (const char *input);#endif +struct zstd_data { +#ifdef HAVE_ZSTD_SUPPORT +ZSTD_CStream *cstream; +#endif +}; + +int zstd_init (struct zstd_data *data,int level); +int zstd_fini (struct zstd_data *data); + +size_t zstd_compress_stream_to_records (struct zstd_data *data, +void *dst,size_t dst_size,void *src,size_t src_size,size_t max_record_size, +size_t process_header (void *record,size_t increment)); +#endif /* PERF_COMPRESS_H */ tools/perf/util/zstd.c new file +95
-0@@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <string.h> + +#include "util/compress.h" +#include "util/debug.h" + +#ifdef HAVE_ZSTD_SUPPORT + +int zstd_init (struct zstd_data *data,int level) +{ +size_t ret; + + data->cstream =ZSTD_createCStream (); +if (data->cstream ==NULL ) { +pr_err ("Couldn't create compression stream.\n" ); +return -1 ; + } + + ret =ZSTD_initCStream (data->cstream, level); +if (ZSTD_isError (ret)) { +pr_err ("Failed to initialize compression stream: %s\n" ,ZSTD_getErrorName (ret)); +return -1 ; + } + +return 0 ; +} + +int zstd_fini (struct zstd_data *data) +{ +if (data->cstream) { +ZSTD_freeCStream (data->cstream); + data->cstream =NULL ; + } + +return 0 ; +} + +size_t zstd_compress_stream_to_records (struct zstd_data *data, +void *dst,size_t dst_size,void *src,size_t src_size,size_t max_record_size, +size_t process_header (void *record,size_t increment)) +{ +size_t ret, size, compressed =0 ; +ZSTD_inBuffer input = { src, src_size,0 }; +ZSTD_outBuffer output; +void *record; + +while (input.pos < input.size) { + record = dst; + size =process_header (record,0 ); + compressed += size; + dst += size; + dst_size -= size; + output = (ZSTD_outBuffer ){ dst, (dst_size > max_record_size) ? + max_record_size : dst_size,0 }; + ret =ZSTD_compressStream (data->cstream, &output, &input); +ZSTD_flushStream (data->cstream, &output); +if (ZSTD_isError (ret)) { +pr_err ("failed to compress %ld bytes: %s\n" , + (long )src_size,ZSTD_getErrorName (ret)); +memcpy (dst, src, src_size); +return src_size; + } + size = output.pos; + size =process_header (record, size); + compressed += size; + dst += size; + dst_size -= size; + } + +return compressed; +} + +#else /* !HAVE_ZSTD_SUPPORT */ + +int zstd_init (struct zstd_data *data__maybe_unused ,int level__maybe_unused ) +{ +return 0 ; +} + +int zstd_fini (struct zstd_data *data__maybe_unused ) +{ +return 0 ; +} + +size_t zstd_compress_stream_to_records (struct zstd_data *data__maybe_unused , +void *dst__maybe_unused ,size_t dst_size__maybe_unused , +void *src__maybe_unused ,size_t src_size__maybe_unused , +size_t max_record_size__maybe_unused , +size_t process_header (void *record,size_t increment)__maybe_unused ) +{ +return 0 ; +} + +#endif Signature · 1 line
2.20.1
Re: [PATCH v5 06/10] perf util: introduce Zstd based streaming compression API
Quoted 7 lines · Jiri Olsa
Quoted 4 lines · Alexey Budankov
Implemented functions are based on Zstd streaming compression API. The functions are used in runtime to compress data that come from mmaped kernel buffer data and then stored into a trace.
please describe the usage of the api in the changelog
in v7.
zstd_init(), zstd_fini() are used for initialization and finalization of API usage to allocate and deallocate zstd objects.
zstd_compress_stream_to_records() is used to convert parts of mmaped kernel buffer into an array of PERF_EVENT_COMPRESSED records.
~Alexey
Quoted 165 lines
thanks,
jirkaQuoted 160 lines
Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/util/Build | 2 + tools/perf/util/compress.h | 18 ++++++++ tools/perf/util/zstd.c | 95 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 tools/perf/util/zstd.ctools/perf/util/Build +2
-0@@ -145,6 +145,8 @@ perf-y += scripting-engines/ perf-$(CONFIG_ZLIB) += zlib.o perf-$(CONFIG_LZMA) += lzma.o +perf-y += zstd.o + perf-y += demangle-java.o perf-y += demangle-rust.otools/perf/util/compress.h +18
-0@@ -2,6 +2,11 @@#ifndef PERF_COMPRESS_H #define PERF_COMPRESS_H +#include <stdbool.h> +#ifdef HAVE_ZSTD_SUPPORT +#include <zstd.h> +#endif +#ifdef HAVE_ZLIB_SUPPORT int gzip_decompress_to_file (const char *input,int output_fd);bool gzip_is_compressed (const char *input);@@ -12,4 +17,17 @@ int lzma_decompress_to_file(const char *input, int output_fd);bool lzma_is_compressed (const char *input);#endif +struct zstd_data { +#ifdef HAVE_ZSTD_SUPPORT +ZSTD_CStream *cstream; +#endif +}; + +int zstd_init (struct zstd_data *data,int level); +int zstd_fini (struct zstd_data *data); + +size_t zstd_compress_stream_to_records (struct zstd_data *data, +void *dst,size_t dst_size,void *src,size_t src_size,size_t max_record_size, +size_t process_header (void *record,size_t increment)); +#endif /* PERF_COMPRESS_H */ tools/perf/util/zstd.c new file +95
-0@@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <string.h> + +#include "util/compress.h" +#include "util/debug.h" + +#ifdef HAVE_ZSTD_SUPPORT + +int zstd_init (struct zstd_data *data,int level) +{ +size_t ret; + + data->cstream =ZSTD_createCStream (); +if (data->cstream ==NULL ) { +pr_err ("Couldn't create compression stream.\n" ); +return -1 ; + } + + ret =ZSTD_initCStream (data->cstream, level); +if (ZSTD_isError (ret)) { +pr_err ("Failed to initialize compression stream: %s\n" ,ZSTD_getErrorName (ret)); +return -1 ; + } + +return 0 ; +} + +int zstd_fini (struct zstd_data *data) +{ +if (data->cstream) { +ZSTD_freeCStream (data->cstream); + data->cstream =NULL ; + } + +return 0 ; +} + +size_t zstd_compress_stream_to_records (struct zstd_data *data, +void *dst,size_t dst_size,void *src,size_t src_size,size_t max_record_size, +size_t process_header (void *record,size_t increment)) +{ +size_t ret, size, compressed =0 ; +ZSTD_inBuffer input = { src, src_size,0 }; +ZSTD_outBuffer output; +void *record; + +while (input.pos < input.size) { + record = dst; + size =process_header (record,0 ); + compressed += size; + dst += size; + dst_size -= size; + output = (ZSTD_outBuffer ){ dst, (dst_size > max_record_size) ? + max_record_size : dst_size,0 }; + ret =ZSTD_compressStream (data->cstream, &output, &input); +ZSTD_flushStream (data->cstream, &output); +if (ZSTD_isError (ret)) { +pr_err ("failed to compress %ld bytes: %s\n" , + (long )src_size,ZSTD_getErrorName (ret)); +memcpy (dst, src, src_size); +return src_size; + } + size = output.pos; + size =process_header (record, size); + compressed += size; + dst += size; + dst_size -= size; + } + +return compressed; +} + +#else /* !HAVE_ZSTD_SUPPORT */ + +int zstd_init (struct zstd_data *data__maybe_unused ,int level__maybe_unused ) +{ +return 0 ; +} + +int zstd_fini (struct zstd_data *data__maybe_unused ) +{ +return 0 ; +} + +size_t zstd_compress_stream_to_records (struct zstd_data *data__maybe_unused , +void *dst__maybe_unused ,size_t dst_size__maybe_unused , +void *src__maybe_unused ,size_t src_size__maybe_unused , +size_t max_record_size__maybe_unused , +size_t process_header (void *record,size_t increment)__maybe_unused ) +{ +return 0 ; +} + +#endif Signature · 1 line
2.20.1
PATCH v5 7/10 perf record: implement -z,--compression_level=n option and compression
In reply to Alexey BudankovImplemented -z,--compression_level=n option that enables compression of mmaped kernel data buffers content in runtime during perf record sampling collection.
Compression is implemented using the functions from zstd.c. As the memory to operate on the compression employs mmap->data buffer in case of serial trace writing and mmap AIO buffers in case of AIO trace writing. If Zstd streaming compression API fails for some reason the data to be compressed are just copied into the memory buffers using memcpy().
Compressed trace frame consists of an array of PERF_RECORD_COMPRESSED records. Each element of the array is not longer that 64KiB because of u16 size limitation and comprised of perf_event_header followed by the compressed chunk that is decompressed on the loading stage. --mmap-flush option value can be used to avoid compression of every single byte of data and possibly increase compression ratio.
Compression overhead has been measured for serial and AIO trace writing when profiling matrix multiplication workload:
-------------------------------------------------------------
| SERIAL | AIO-1 |
-----------------------------------------------------------------
|-z | OVH(x) | ratio(x) size(MiB) | OVH(x) | ratio(x) size(MiB) | |---------------------------------------------------------------- | 0 | 1,00 | 1,000 179,424 | 1,00 | 1,000 187,527 | | 1 | 1,04 | 8,427 181,148 | 1,01 | 8,474 188,562 | | 2 | 1,07 | 8,055 186,953 | 1,03 | 7,912 191,773 | | 3 | 1,04 | 8,283 181,908 | 1,03 | 8,220 191,078 | | 5 | 1,09 | 8,101 187,705 | 1,05 | 7,780 190,065 | | 8 | 1,05 | 9,217 179,191 | 1,12 | 6,111 193,024 |
-----------------------------------------------------------------
OVH = (Execution time with -z N) / (Execution time with -z 0)
ratio - compression ratio
size - number of bytes that was compressed
size ~= trace size x ratio
--- tools/perf/Documentation/perf-record.txt | 5 ++ tools/perf/builtin-record.c | 85 ++++++++++++++++++++---- tools/perf/util/mmap.c | 31 ++++++--- tools/perf/util/mmap.h | 13 ++-- tools/perf/util/session.h | 2 + 5 files changed, 110 insertions(+), 26 deletions(-)
tools/perf/Documentation/perf-record.txt +5 -0
@@ -472,6 +472,11 @@ executing less trace write syscalls with bigger data sets can take shorter than executing more trace write syscalls with smaller data sets thus lowering runtime profiling overhead. +-z:: +--compression-level=n:: +Produce compressed trace using specified compression level n (no compression: 0 - default, +fastest compression: 1, smallest trace: 22) + --all-kernel:: Configure all used events to run in kernel space.
tools/perf/builtin-record.c +72 -13
171 lines not on this page · raw message
tools/perf/util/mmap.c +23 -8
@@ -291,14 +291,15 @@ static void perf_mmap__aio_munmap(struct perf_mmap *map) }int perf_mmap__aio_push (struct perf_mmap *md,void *to,int idx, -int push (void *to,struct aiocb *cblock,void *buf,size_t size,off_t off), -off_t *off) +int push (void *to,void *buf,size_t size,off_t off,struct aiocb *cblock), +off_t *off,perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size, size0 =0 ;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )
@@ -327,14 +328,20 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, buf = &data[md->start & md->mask]; size = md->mask +1 - (md->start & md->mask); md->start += size; -memcpy (md->aio.data[idx], buf, size); size0 = size; +if (!compress) +memcpy (md->aio.data[idx], buf, size); +else + size0 =compress (comp_data, md->aio.data[idx], mmap_len, buf, size); } buf = &data[md->start & md->mask]; size = md->end - md->start; md->start += size; -memcpy (md->aio.data[idx] + size0, buf, size); +if (!compress) +memcpy (md->aio.data[idx] + size0, buf, size); +else + size =compress (comp_data, md->aio.data[idx] + size0, mmap_len - size0, buf, size);/* * Increment md->refcount to guard md->data[idx] buffer
@@ -350,7 +357,7 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, md->prev = head;perf_mmap__consume (md); - rc =push (to, &md->aio.cblocks[idx], md->aio.data[idx], size0 + size, *off); + rc =push (to, md->aio.data[idx], size0 + size, *off, &md->aio.cblocks[idx]);if (!rc) { *off += size0 + size; }else {
@@ -556,13 +563,15 @@ int perf_mmap__read_init(struct perf_mmap *map) }int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)) +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )
@@ -574,7 +583,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask]; size = md->mask +1 - (md->start & md->mask); md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;
@@ -584,7 +596,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask]; size = md->end - md->start; md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;
tools/perf/util/mmap.h +8 -5
@@ -99,16 +99,19 @@ union perf_event *perf_mmap__read_forward(struct perf_mmap *map);union perf_event *perf_mmap__read_event (struct perf_mmap *map); +typedef size_t (*perf_mmap__compress_fn_t )(void *data,void *dst,size_t dst_size, +void *src,size_t src_size);int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)); +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *compress_data);#ifdef HAVE_AIO_SUPPORT int perf_mmap__aio_push (struct perf_mmap *md,void *to,int idx, -int push (void *to,struct aiocb *cblock,void *buf,size_t size,off_t off), -off_t *off); +int push (void *to,void *buf,size_t size,off_t off,struct aiocb *cblock), +off_t *off,perf_mmap__compress_fn_t compress,void *compress_data);#else static inline int perf_mmap__aio_push (struct perf_mmap *md__maybe_unused ,void *to__maybe_unused ,int idx__maybe_unused , -int push (void *to,struct aiocb *cblock,void *buf,size_t size,off_t off)__maybe_unused , -off_t *off__maybe_unused ) +int push (void *to,void *buf,size_t size,off_t off,struct aiocb *cblock)__maybe_unused , +off_t *off__maybe_unused ,perf_mmap__compress_fn_t compress__maybe_unused ,void *compress_data__maybe_unused ) {return 0 ; }
tools/perf/util/session.h +2 -0
@@ -8,6 +8,7 @@#include "machine.h" #include "data.h" #include "ordered-events.h" +#include "util/compress.h" #include <linux/kernel.h> #include <linux/rbtree.h> #include <linux/perf_event.h>
@@ -37,6 +38,7 @@ struct perf_session {struct perf_tool *tool;u64 bytes_transferred;u64 bytes_compressed; +struct zstd_data zstd_data; };struct perf_tool ;
Signature · 1 line
2.20.1
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
Could do this as a follow up patch, but at some point the new records need to be documented in Documentation/perf.data-file-format.txt
-Andi
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 4 lines · Andi Kleen
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
Could do this as a follow up patch, but at some point the new records need to be documented in
Documentation/perf.data-file-format.txt
Well, let's have it as a part of v6 04/10.
Thanks,
Alexey
Quoted 3 lines
-Andi
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
In reply to Alexey BudankovOn Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 31 lines
tools/perf/util/mmap.c +4
-2/* * Increment md->refcount to guard md->data[idx] buffer @@ -350,7 +357,7 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, md->prev = head;perf_mmap__consume (md); - rc =push (to, &md->aio.cblocks[idx], md->aio.data[idx], size0 + size, *off); + rc =push (to, md->aio.data[idx], size0 + size, *off, &md->aio.cblocks[idx]);if (!rc) { *off += size0 + size; }else {@@ -556,13 +563,15 @@ int perf_mmap__read_init(struct perf_mmap *map) }int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)) +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )@@ -574,7 +583,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask];
tools/perf/util/mmap.c int perf_mmap__push(struct perf_mmap *md, void *to, · line 592
Quoted 10 lines
tools/perf/util/mmap.c +4
-1size = md->mask +1 - (md->start & md->mask); md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;
when we discussed the compress callback should be another layer in perf_mmap__push I was thinking more of the layered/fifo design, like:
normaly we call:
perf_mmap__push(... push = record__pushfn ...) -> reads mmap data and calls push(data), which translates as: record__pushfn(data); - which stores the data
for compressed it'd be:
perf_mmap__push(... push = compressed_push ...) -> reads mmap data and calls push(data), which translates as: compressed_push(data) -> reads data, compresses them and calls, next push callback in line: record__pushfn(data) - which stores the data
there'd need to be the logic for compressed_push to remember the 'next push' function
but I think this was the original idea behind the perf_mmap__push -> it gets the data and pushes them for the next processing.. it should stay as simple as that
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 72 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 31 lines
tools/perf/util/mmap.c +4
-2/* * Increment md->refcount to guard md->data[idx] buffer @@ -350,7 +357,7 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, md->prev = head;perf_mmap__consume (md); - rc =push (to, &md->aio.cblocks[idx], md->aio.data[idx], size0 + size, *off); + rc =push (to, md->aio.data[idx], size0 + size, *off, &md->aio.cblocks[idx]);if (!rc) { *off += size0 + size; }else {@@ -556,13 +563,15 @@ int perf_mmap__read_init(struct perf_mmap *map) }int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)) +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )@@ -574,7 +583,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask];tools/perf/util/mmap.c int perf_mmap__push(struct perf_mmap *md, void *to, · line 592
Quoted 10 lines
tools/perf/util/mmap.c +4
-1size = md->mask +1 - (md->start & md->mask); md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;when we discussed the compress callback should be another layer in
perf_mmap__pushI was thinking more of the layered/fifo design, like:normaly we call:
perf_mmap__push(... push = record__pushfn ...) -> reads mmap data and calls push(data), which translates as: record__pushfn(data); - which stores the datafor compressed it'd be:
perf_mmap__push(... push = compressed_push ...) -> reads mmap data and calls push(data), which translates as: compressed_push(data) -> reads data, compresses them and calls, next push callback in line: record__pushfn(data) - which stores the data
Quoted 2 lines
there'd need to be the logic for
compressed_pushto remember the 'next push' function
That is suboptimal for AIO. Also compression is an independent operation that could be applied on any of push stages you mean.
Quoted 4 lines
but I think this was the original idea behind the
perf_mmap__push-> it gets the data and pushes them for the next processing.. it should stay as simple as that
Agree on keeping simplicity and, at the moment, there is no any push to the next processing in the code so provided implementation fits as for serial as for AIO at the same time sticking to simplicity as much as possibly. If you see something that would fit better please speak up and share.
~Alexey
Quoted 3 lines
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 74 lines · Alexey Budankov
Quoted 72 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 31 lines
tools/perf/util/mmap.c +4
-2/* * Increment md->refcount to guard md->data[idx] buffer @@ -350,7 +357,7 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, md->prev = head;perf_mmap__consume (md); - rc =push (to, &md->aio.cblocks[idx], md->aio.data[idx], size0 + size, *off); + rc =push (to, md->aio.data[idx], size0 + size, *off, &md->aio.cblocks[idx]);if (!rc) { *off += size0 + size; }else {@@ -556,13 +563,15 @@ int perf_mmap__read_init(struct perf_mmap *map) }int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)) +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )@@ -574,7 +583,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask];tools/perf/util/mmap.c int perf_mmap__push(struct perf_mmap *md, void *to, · line 592
Quoted 10 lines
tools/perf/util/mmap.c +4
-1size = md->mask +1 - (md->start & md->mask); md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;when we discussed the compress callback should be another layer in
perf_mmap__pushI was thinking more of the layered/fifo design, like:normaly we call:
perf_mmap__push(... push = record__pushfn ...) -> reads mmap data and calls push(data), which translates as: record__pushfn(data); - which stores the datafor compressed it'd be:
perf_mmap__push(... push = compressed_push ...) -> reads mmap data and calls push(data), which translates as: compressed_push(data) -> reads data, compresses them and calls, next push callback in line: record__pushfn(data) - which stores the data
Quoted 5 lines
Quoted 2 lines
there'd need to be the logic for
compressed_pushto remember the 'next push' functionThat is suboptimal for AIO. Also compression is an independent operation that could be applied on any of push stages you mean.
not sure what you mean by suboptimal, but I think that it can still happen in subsequent push callback
Quoted 10 lines
Quoted 5 lines
but I think this was the original idea behind the
perf_mmap__push-> it gets the data and pushes them for the next processing.. it should stay as simple as thatAgree on keeping simplicity and, at the moment, there is no any push to the next processing in the code so provided implementation fits as for serial as for AIO at the same time sticking to simplicity as much as possibly. If you see something that would fit better please speak up and share.
I have to insist that perf_mmap__push stays untouched and we do other processing in the push callbacks
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 90 lines · Jiri Olsa
Quoted 74 lines · Alexey Budankov
Quoted 72 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 31 lines
tools/perf/util/mmap.c +4
-2/* * Increment md->refcount to guard md->data[idx] buffer @@ -350,7 +357,7 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, md->prev = head;perf_mmap__consume (md); - rc =push (to, &md->aio.cblocks[idx], md->aio.data[idx], size0 + size, *off); + rc =push (to, md->aio.data[idx], size0 + size, *off, &md->aio.cblocks[idx]);if (!rc) { *off += size0 + size; }else {@@ -556,13 +563,15 @@ int perf_mmap__read_init(struct perf_mmap *map) }int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)) +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )@@ -574,7 +583,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask];tools/perf/util/mmap.c int perf_mmap__push(struct perf_mmap *md, void *to, · line 592
Quoted 10 lines
tools/perf/util/mmap.c +4
-1size = md->mask +1 - (md->start & md->mask); md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;when we discussed the compress callback should be another layer in
perf_mmap__pushI was thinking more of the layered/fifo design, like:normaly we call:
perf_mmap__push(... push = record__pushfn ...) -> reads mmap data and calls push(data), which translates as: record__pushfn(data); - which stores the datafor compressed it'd be:
perf_mmap__push(... push = compressed_push ...) -> reads mmap data and calls push(data), which translates as: compressed_push(data) -> reads data, compresses them and calls, next push callback in line: record__pushfn(data) - which stores the dataQuoted 5 lines
Quoted 2 lines
there'd need to be the logic for
compressed_pushto remember the 'next push' functionThat is suboptimal for AIO. Also compression is an independent operation that could be applied on any of push stages you mean.
not sure what you mean by suboptimal, but I think that it can still happen in subsequent push callback
Quoted 6 lines
Quoted 5 lines
but I think this was the original idea behind the
perf_mmap__push-> it gets the data and pushes them for the next processing.. it should stay as simple as that
Quoted 7 lines
Quoted 4 lines
Agree on keeping simplicity and, at the moment, there is no any push to the next processing in the code so provided implementation fits as for serial as for AIO at the same time sticking to simplicity as much as possibly. If you see something that would fit better please speak up and share.
I have to insist that
perf_mmap__pushstays untouched and we do other processing in the push callbacks
What is about perf_mmap__aio_push()?
Without compression it does
memcpy(), memcpy(), aio_push()
With compression its does
memcpy_with_compression(), memcpy_with_compression(), aio_push()
and deviation that increases amount of copy operations i.e. implementing three or more is suboptimal in terms of runtime overhead and data loss decrease
Compression for serial streaming can be implemented in push() callback. AIO case would go with compression over a parameter in aio_push(). So the both trace writing schemas could be optimally extended.
~Alexey
Quoted 3 lines
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 105 lines · Alexey Budankov
Quoted 90 lines · Jiri Olsa
Quoted 74 lines · Alexey Budankov
Quoted 72 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 31 lines
tools/perf/util/mmap.c +4
-2/* * Increment md->refcount to guard md->data[idx] buffer @@ -350,7 +357,7 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, md->prev = head;perf_mmap__consume (md); - rc =push (to, &md->aio.cblocks[idx], md->aio.data[idx], size0 + size, *off); + rc =push (to, md->aio.data[idx], size0 + size, *off, &md->aio.cblocks[idx]);if (!rc) { *off += size0 + size; }else {@@ -556,13 +563,15 @@ int perf_mmap__read_init(struct perf_mmap *map) }int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)) +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )@@ -574,7 +583,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask];tools/perf/util/mmap.c int perf_mmap__push(struct perf_mmap *md, void *to, · line 592
Quoted 10 lines
tools/perf/util/mmap.c +4
-1size = md->mask +1 - (md->start & md->mask); md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;when we discussed the compress callback should be another layer in
perf_mmap__pushI was thinking more of the layered/fifo design, like:normaly we call:
perf_mmap__push(... push = record__pushfn ...) -> reads mmap data and calls push(data), which translates as: record__pushfn(data); - which stores the datafor compressed it'd be:
perf_mmap__push(... push = compressed_push ...) -> reads mmap data and calls push(data), which translates as: compressed_push(data) -> reads data, compresses them and calls, next push callback in line: record__pushfn(data) - which stores the dataQuoted 5 lines
Quoted 2 lines
there'd need to be the logic for
compressed_pushto remember the 'next push' functionThat is suboptimal for AIO. Also compression is an independent operation that could be applied on any of push stages you mean.
not sure what you mean by suboptimal, but I think that it can still happen in subsequent push callback
Quoted 6 lines
Quoted 5 lines
but I think this was the original idea behind the
perf_mmap__push-> it gets the data and pushes them for the next processing.. it should stay as simple as thatQuoted 7 lines
Quoted 4 lines
Agree on keeping simplicity and, at the moment, there is no any push to the next processing in the code so provided implementation fits as for serial as for AIO at the same time sticking to simplicity as much as possibly. If you see something that would fit better please speak up and share.
I have to insist that
perf_mmap__pushstays untouched and we do other processing in the push callbacksWhat is about
perf_mmap__aio_push()?Without compression it does
memcpy(), memcpy(), aio_push()
Quoted 8 lines
With compression its does
memcpy_with_compression(),memcpy_with_compression(),aio_push()and deviation that increases amount of copy operations i.e. implementing three or more is suboptimal in terms of runtime overhead and data loss decrease
Compression for serial streaming can be implemented in
push()callback. AIO case would go with compression over a parameter inaio_push().
I meant compress_fn and comp_data parameters _for_ aio_push().
Quoted 8 lines
So the both trace writing schemas could be optimally extended.
~Alexey
Quoted 3 lines
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
In reply to Alexey BudankovQuoted 100 lines · Alexey Budankov
Quoted 90 lines · Jiri Olsa
Quoted 74 lines · Alexey Budankov
Quoted 72 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 31 lines
tools/perf/util/mmap.c +4
-2/* * Increment md->refcount to guard md->data[idx] buffer @@ -350,7 +357,7 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, md->prev = head;perf_mmap__consume (md); - rc =push (to, &md->aio.cblocks[idx], md->aio.data[idx], size0 + size, *off); + rc =push (to, md->aio.data[idx], size0 + size, *off, &md->aio.cblocks[idx]);if (!rc) { *off += size0 + size; }else {@@ -556,13 +563,15 @@ int perf_mmap__read_init(struct perf_mmap *map) }int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)) +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )@@ -574,7 +583,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask];tools/perf/util/mmap.c int perf_mmap__push(struct perf_mmap *md, void *to, · line 592
Quoted 10 lines
tools/perf/util/mmap.c +4
-1size = md->mask +1 - (md->start & md->mask); md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;when we discussed the compress callback should be another layer in
perf_mmap__pushI was thinking more of the layered/fifo design, like:normaly we call:
perf_mmap__push(... push = record__pushfn ...) -> reads mmap data and calls push(data), which translates as: record__pushfn(data); - which stores the datafor compressed it'd be:
perf_mmap__push(... push = compressed_push ...) -> reads mmap data and calls push(data), which translates as: compressed_push(data) -> reads data, compresses them and calls, next push callback in line: record__pushfn(data) - which stores the dataQuoted 5 lines
Quoted 2 lines
there'd need to be the logic for
compressed_pushto remember the 'next push' functionThat is suboptimal for AIO. Also compression is an independent operation that could be applied on any of push stages you mean.
not sure what you mean by suboptimal, but I think that it can still happen in subsequent push callback
Quoted 6 lines
Quoted 5 lines
but I think this was the original idea behind the
perf_mmap__push-> it gets the data and pushes them for the next processing.. it should stay as simple as thatQuoted 7 lines
Quoted 4 lines
Agree on keeping simplicity and, at the moment, there is no any push to the next processing in the code so provided implementation fits as for serial as for AIO at the same time sticking to simplicity as much as possibly. If you see something that would fit better please speak up and share.
I have to insist that
perf_mmap__pushstays untouched and we do other processing in the push callbacks
Quoted 7 lines
What is about
perf_mmap__aio_push()?Without compression it does
memcpy(), memcpy(), aio_push()With compression its does
memcpy_with_compression(),memcpy_with_compression(),aio_push()
so to be on the same page.. normal processing without compression is:
perf_mmap__push does:
push(mmap buf)
record__pushfn
record__write
write(buf)
perf_mmap__aio_push does:
memcpy(aio buf, mmap buf)
push(aio buf)
record__aio_pushfn
record__aio_write
aio_write(aio buf)
and for compression it would be:
perf_mmap__push does:
push(mmap buf)
compress_push
memcpy(compress buffer, mmapbuf) EXTRA copy
record__pushfn
record__write
write(buf)
perf_mmap__aio_push does:
memcpy(aio buf, mmap buf)
memcpy(compress buffer, mmapbuf) EXTRA copy
push(aio buf)
record__aio_pushfn
record__aio_write
aio_write(aio buf)
side note: that actualy makes me think why do we even have perf_mmap__aio_push, it looks like we could copy the buf in the callback push function with no harm?
so.. there's one extra memcpy for compression, is it right? I might miss some part which makes this scheme unusable..
thanks,
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 144 lines · Jiri Olsa
Quoted 100 lines · Alexey Budankov
Quoted 90 lines · Jiri Olsa
Quoted 74 lines · Alexey Budankov
Quoted 72 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 31 lines
tools/perf/util/mmap.c +4
-2/* * Increment md->refcount to guard md->data[idx] buffer @@ -350,7 +357,7 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, md->prev = head;perf_mmap__consume (md); - rc =push (to, &md->aio.cblocks[idx], md->aio.data[idx], size0 + size, *off); + rc =push (to, md->aio.data[idx], size0 + size, *off, &md->aio.cblocks[idx]);if (!rc) { *off += size0 + size; }else {@@ -556,13 +563,15 @@ int perf_mmap__read_init(struct perf_mmap *map) }int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)) +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )@@ -574,7 +583,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask];tools/perf/util/mmap.c int perf_mmap__push(struct perf_mmap *md, void *to, · line 592
Quoted 10 lines
tools/perf/util/mmap.c +4
-1size = md->mask +1 - (md->start & md->mask); md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;when we discussed the compress callback should be another layer in
perf_mmap__pushI was thinking more of the layered/fifo design, like:normaly we call:
perf_mmap__push(... push = record__pushfn ...) -> reads mmap data and calls push(data), which translates as: record__pushfn(data); - which stores the datafor compressed it'd be:
perf_mmap__push(... push = compressed_push ...) -> reads mmap data and calls push(data), which translates as: compressed_push(data) -> reads data, compresses them and calls, next push callback in line: record__pushfn(data) - which stores the dataQuoted 5 lines
Quoted 2 lines
there'd need to be the logic for
compressed_pushto remember the 'next push' functionThat is suboptimal for AIO. Also compression is an independent operation that could be applied on any of push stages you mean.
not sure what you mean by suboptimal, but I think that it can still happen in subsequent push callback
Quoted 6 lines
Quoted 5 lines
but I think this was the original idea behind the
perf_mmap__push-> it gets the data and pushes them for the next processing.. it should stay as simple as thatQuoted 7 lines
Quoted 4 lines
Agree on keeping simplicity and, at the moment, there is no any push to the next processing in the code so provided implementation fits as for serial as for AIO at the same time sticking to simplicity as much as possibly. If you see something that would fit better please speak up and share.
I have to insist that
perf_mmap__pushstays untouched and we do other processing in the push callbacksQuoted 7 lines
What is about
perf_mmap__aio_push()?Without compression it does
memcpy(), memcpy(), aio_push()With compression its does
memcpy_with_compression(),memcpy_with_compression(),aio_push()so to be on the same page.. normal processing without compression is:
perf_mmap__pushdoes:
push(mmap buf)
record__pushfn
record__write
write(buf)
perf_mmap__aio_pushdoes:
memcpy(aio buf, mmap buf)
push(aio buf)
record__aio_pushfn
record__aio_write
aio_write(aio buf)and for compression it would be:
perf_mmap__pushdoes:
push(mmap buf)
compress_push
memcpy(compress buffer, mmapbuf)EXTRA copy
record__pushfn
record__write
write(buf)
perf_mmap__aio_pushdoes:
memcpy(aio buf, mmap buf)
memcpy(compress buffer, mmapbuf)EXTRA copy
push(aio buf)
record__aio_pushfn
record__aio_write
aio_write(aio buf)
Quoted 4 lines
side note: that actualy makes me think why do we even have
perf_mmap__aio_push, it looks like we could copy the buf in the callback push function with no harm?so.. there's one extra memcpy for compression, is it right?
It is right for serial trace streaming.
For AIO there is no extra memcpy().
Plain memcpy() is replaced by the compressing one.
~Alexey
Quoted 5 lines
I might miss some part which makes this scheme unusable..
thanks,
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
In reply to Jiri OlsaQuoted 144 lines · Jiri Olsa
Quoted 100 lines · Alexey Budankov
Quoted 90 lines · Jiri Olsa
Quoted 74 lines · Alexey Budankov
Quoted 72 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 31 lines
tools/perf/util/mmap.c +4
-2/* * Increment md->refcount to guard md->data[idx] buffer @@ -350,7 +357,7 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx, md->prev = head;perf_mmap__consume (md); - rc =push (to, &md->aio.cblocks[idx], md->aio.data[idx], size0 + size, *off); + rc =push (to, md->aio.data[idx], size0 + size, *off, &md->aio.cblocks[idx]);if (!rc) { *off += size0 + size; }else {@@ -556,13 +563,15 @@ int perf_mmap__read_init(struct perf_mmap *map) }int perf_mmap__push (struct perf_mmap *md,void *to, -int push (struct perf_mmap *map,void *to,void *buf,size_t size)) +int push (struct perf_mmap *map,void *to,void *buf,size_t size), +perf_mmap__compress_fn_t compress,void *comp_data) {u64 head =perf_mmap__read_head (md);unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; +size_t mmap_len =perf_mmap__mmap_len (md); rc =perf_mmap__read_init (md);if (rc <0 )@@ -574,7 +583,10 @@ int perf_mmap__push(struct perf_mmap *md, void *to, buf = &data[md->start & md->mask];tools/perf/util/mmap.c int perf_mmap__push(struct perf_mmap *md, void *to, · line 592
Quoted 10 lines
tools/perf/util/mmap.c +4
-1size = md->mask +1 - (md->start & md->mask); md->start += size; - +if (compress) { + size =compress (comp_data, md->data, mmap_len, buf, size); + buf = md->data; + }if (push (md, to, buf, size) <0 ) { rc =-1 ; goto out;when we discussed the compress callback should be another layer in
perf_mmap__pushI was thinking more of the layered/fifo design, like:normaly we call:
perf_mmap__push(... push = record__pushfn ...) -> reads mmap data and calls push(data), which translates as: record__pushfn(data); - which stores the datafor compressed it'd be:
perf_mmap__push(... push = compressed_push ...) -> reads mmap data and calls push(data), which translates as: compressed_push(data) -> reads data, compresses them and calls, next push callback in line: record__pushfn(data) - which stores the dataQuoted 5 lines
Quoted 2 lines
there'd need to be the logic for
compressed_pushto remember the 'next push' functionThat is suboptimal for AIO. Also compression is an independent operation that could be applied on any of push stages you mean.
not sure what you mean by suboptimal, but I think that it can still happen in subsequent push callback
Quoted 6 lines
Quoted 5 lines
but I think this was the original idea behind the
perf_mmap__push-> it gets the data and pushes them for the next processing.. it should stay as simple as thatQuoted 7 lines
Quoted 4 lines
Agree on keeping simplicity and, at the moment, there is no any push to the next processing in the code so provided implementation fits as for serial as for AIO at the same time sticking to simplicity as much as possibly. If you see something that would fit better please speak up and share.
I have to insist that
perf_mmap__pushstays untouched and we do other processing in the push callbacksQuoted 7 lines
What is about
perf_mmap__aio_push()?Without compression it does
memcpy(), memcpy(), aio_push()With compression its does
memcpy_with_compression(),memcpy_with_compression(),aio_push()so to be on the same page.. normal processing without compression is:
perf_mmap__pushdoes:
push(mmap buf)
record__pushfn
record__write
write(buf)
perf_mmap__aio_pushdoes:
memcpy(aio buf, mmap buf)
push(aio buf)
record__aio_pushfn
record__aio_write
aio_write(aio buf)and for compression it would be:
perf_mmap__pushdoes:
push(mmap buf)
compress_push
memcpy(compress buffer, mmapbuf)EXTRA copy
record__pushfn
record__write
write(buf)
perf_mmap__aio_pushdoes:
memcpy(aio buf, mmap buf)
memcpy(compress buffer, mmapbuf)EXTRA copy
push(aio buf)
record__aio_pushfn
record__aio_write
aio_write(aio buf)
Quoted 2 lines
side note: that actualy makes me think why do we even have
perf_mmap__aio_push, it looks like we could copy the buf in the callback push function with no harm?
Well, yes, perf_mmap__aio_push() can be avoided and perf_mmap__push() can be used as for serial as for AIO, moving all the specifics to record code from mmap.c, like this:
Serial
perf_mmap__push(, record__pushfn)
push(), possibly two times
record__pushfn()
if (-z) zstd_compress(map->base => map->data) <-- compressing memcpy()
record__write(-z ? map->data, map->base)
AIO
record__aio_push()
perf_mmap__push(, record__aio_pushfn())
push(), possibly two times
record__aio_pushfn()
if (-z) zstd_compress(map->base => map->aio.data[i]) <--- compressing memcpy()
else memcpy(map->base => map->aio.data[i]) <--- plain memcpy()
record__aio_write(map->aio.data[i]) So now it looks optimal as from performance and data loss reduction perspective as from design perspective. What do you think?
~Alexey
Quoted 7 lines
so.. there's one extra memcpy for compression, is it right? I might miss some part which makes this scheme unusable..
thanks,
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
On Sun, Mar 10, 2019 at 07:17:08PM +0300, Alexey Budankov wrote:
SNIP
Quoted 57 lines
Quoted 35 lines
so to be on the same page.. normal processing without compression is:
perf_mmap__pushdoes:
push(mmap buf)
record__pushfn
record__write
write(buf)
perf_mmap__aio_pushdoes:
memcpy(aio buf, mmap buf)
push(aio buf)
record__aio_pushfn
record__aio_write
aio_write(aio buf)and for compression it would be:
perf_mmap__pushdoes:
push(mmap buf)
compress_push
memcpy(compress buffer, mmapbuf)EXTRA copy
record__pushfn
record__write
write(buf)
perf_mmap__aio_pushdoes:
memcpy(aio buf, mmap buf)
memcpy(compress buffer, mmapbuf)EXTRA copy
push(aio buf)
record__aio_pushfn
record__aio_write
aio_write(aio buf)Quoted 2 lines
side note: that actualy makes me think why do we even have
perf_mmap__aio_push, it looks like we could copy the buf in the callback push function with no harm?Well, yes,
perf_mmap__aio_push()can be avoided andperf_mmap__push()can be used as for serial as for AIO, moving all the specifics to record code frommmap.c, like this:Serial
perf_mmap__push(, record__pushfn)
push(), possibly two timesrecord__pushfn() if (-z) zstd_compress(map->base => map->data) <-- compressing memcpy() record__write(-z ? map->data, map->base) AIO record__aio_push() perf_mmap__push(, record__aio_pushfn()) push(), possibly two times record__aio_pushfn() if (-z) zstd_compress(map->base => map->aio.data[i]) <--- compressing memcpy() else memcpy(map->base => map->aio.data[i]) <--- plain memcpy() record__aio_write(map->aio.data[i])
Quoted 2 lines
So now it looks optimal as from performance and data loss reduction perspective as from design perspective. What do you think?
yes, that looks much better.. so we'd have record__pushfn for standard (serial) and record__aio_pushfn for AIO
thanks,
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
In reply to Alexey BudankovOn Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
tools/perf/builtin-record.c static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) · line 792
Quoted 7 lines
tools/perf/builtin-record.c +7
-0+static size_t record__zstd_compress (void *data,void *dst,size_t dst_size, +void *src,size_t src_size) +{ +size_t compressed; +struct perf_session *session = data; +/* maximum size of record data size (2^16 - 1 - header) */ + const size_t max_record_size = (1 << 8 * sizeof(u16)) -
I dont follow this calculation, could you just use PERF_SAMPLE_MAX_SIZE?
jirka
Quoted 2 lines
(quoted diff) +2
-0+ 1 - sizeof(struct compressed_event); +
SNIP
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 4 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 9 lines
tools/perf/builtin-record.c static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) · line 792
Quoted 7 lines
tools/perf/builtin-record.c +7
-0+static size_t record__zstd_compress (void *data,void *dst,size_t dst_size, +void *src,size_t src_size) +{ +size_t compressed; +struct perf_session *session = data; +/* maximum size of record data size (2^16 - 1 - header) */ + const size_t max_record_size = (1 << 8 * sizeof(u16)) -I dont follow this calculation, could you just use
PERF_SAMPLE_MAX_SIZE?
in v7.
~Alexey
Quoted 8 lines
jirka
Quoted 2 lines
(quoted diff) +2
-0+ 1 - sizeof(struct compressed_event); +SNIP
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
In reply to Alexey BudankovOn Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
tools/perf/builtin-record.c static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) · line 783
Quoted 13 lines
tools/perf/builtin-record.c +13
-0+static size_t record__process_comp_header (void *record,size_t increment) +{ +struct compressed_event *event = record; +size_t size =sizeof (struct compressed_event ); + +if (increment) { + event->header.size += increment; +return increment; + }else { + event->header.type =PERF_RECORD_COMPRESSED ; + event->header.size = size; +return size; + }
so zstd_compress_stream_to_records calls this in the loop:
while (input.pos < input.size) {
...
size = process_header(record, 0);
...
size = process_header(record, size);
}the header.size will get overwritten with every new iteration, no?
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 20 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
tools/perf/builtin-record.c static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) · line 783
Quoted 13 lines
tools/perf/builtin-record.c +13
-0+static size_t record__process_comp_header (void *record,size_t increment) +{ +struct compressed_event *event = record; +size_t size =sizeof (struct compressed_event ); + +if (increment) { + event->header.size += increment; +return increment; + }else { + event->header.type =PERF_RECORD_COMPRESSED ; + event->header.size = size; +return size; + }so
zstd_compress_stream_to_recordscalls this in the loop:
Quoted 8 lines
while (input.pos < input.size) { ... size = process_header(record, 0); ... size = process_header(record, size); }the header.size will get overwritten with every new iteration, no?
Every new record is headed by PERF_RECORD_COMPRESSED header an updated with resulted compressed frame size after compression.
process_header(, 0) puts header, then compression puts compressed frame, then process_header(, N) updates header.size value (+=).
~Alexey
Quoted 3 lines
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 29 lines · Alexey Budankov
Quoted 27 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
tools/perf/builtin-record.c static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) · line 783
Quoted 13 lines
tools/perf/builtin-record.c +13
-0+static size_t record__process_comp_header (void *record,size_t increment) +{ +struct compressed_event *event = record; +size_t size =sizeof (struct compressed_event ); + +if (increment) { + event->header.size += increment; +return increment; + }else { + event->header.type =PERF_RECORD_COMPRESSED ; + event->header.size = size; +return size; + }so
zstd_compress_stream_to_recordscalls this in the loop:while (input.pos < input.size) { ... size = process_header(record, 0); ... size = process_header(record, size); }
Quoted 8 lines
Quoted 1 line
the header.size will get overwritten with every new iteration, no?
Every new record is headed by
PERF_RECORD_COMPRESSEDheader an updated with resulted compressed frame size after compression.
process_header(, 0)puts header, then compression puts compressed frame, thenprocess_header(, N)updates header.size value (+=).
and then process_header(, 0) is called again no?
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 32 lines · Jiri Olsa
Quoted 31 lines · Alexey Budankov
Quoted 28 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
tools/perf/builtin-record.c static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) · line 783
Quoted 13 lines
tools/perf/builtin-record.c +13
-0+static size_t record__process_comp_header (void *record,size_t increment) +{ +struct compressed_event *event = record; +size_t size =sizeof (struct compressed_event ); + +if (increment) { + event->header.size += increment; +return increment; + }else { + event->header.type =PERF_RECORD_COMPRESSED ; + event->header.size = size; +return size; + }so
zstd_compress_stream_to_recordscalls this in the loop:while (input.pos < input.size) { ... size = process_header(record, 0); ... size = process_header(record, size); }the header.size will get overwritten with every new iteration, no?
Quoted 8 lines
Quoted 6 lines
Every new record is headed by
PERF_RECORD_COMPRESSEDheader an updated with resulted compressed frame size after compression.
process_header(, 0)puts header, then compression puts compressed frame, thenprocess_header(, N)updates header.size value (+=).and then
process_header(, 0)is called again no?
Yes, in the next iteration these three steps repeat for the next record.
~Alexey
Quoted 3 lines
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
In reply to Alexey BudankovOn Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 7 lines
tools/perf/builtin-record.c +6
-0+static size_t record__process_comp_header (void *record,size_t increment) +{ +struct compressed_event *event = record; +size_t size =sizeof (struct compressed_event ); + +if (increment) {
tools/perf/builtin-record.c static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) · line 786
Quoted 10 lines
tools/perf/builtin-record.c +10
-0+ event->header.size += increment; +return increment; + }else { + event->header.type =PERF_RECORD_COMPRESSED ; + event->header.size = size; +return size; + } +} + +static size_t record__zstd_compress(void *data, void *dst, size_t dst_size,
we use the <name>__ to mark 'struct' related function, which supposed to be the first argument.. IMO zstd_compress will be fine in here
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 17 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 13 lines
tools/perf/builtin-record.c +12
-0+static size_t record__process_comp_header (void *record,size_t increment) +{ +struct compressed_event *event = record; +size_t size =sizeof (struct compressed_event ); + +if (increment) { + event->header.size += increment; +return increment; + }else { + event->header.type =PERF_RECORD_COMPRESSED ; + event->header.size = size; +return size;
Quoted 8 lines
tools/perf/builtin-record.c static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) · line 786
Quoted 4 lines
tools/perf/builtin-record.c +4
-0+ } +} + +static size_t record__zstd_compress(void *data, void *dst, size_t dst_size,we use the <name>__ to mark 'struct' related function, which supposed to be the first argument.. IMO
zstd_compresswill be fine in here
in v7.
~Alexey
Quoted 3 lines
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
In reply to Alexey BudankovOn Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 24 lines
tools/perf/builtin-record.c +4
-6+static int record__aio_enabled (struct record *rec); +static void record__aio_mmap_read_sync (struct record *rec) {int i;struct perf_evlist *evlist = rec->evlist;struct perf_mmap *maps = evlist->mmap; -if (!rec->opts.nr_cblocks) +if (!record__aio_enabled (rec))return ;for (i =0 ; i < evlist->nr_mmaps; i++) {@@ -292,13 +294,17 @@ static int record__aio_parse(const struct option *opt,if (unset) { opts->nr_cblocks =0 ; - }else { -if (str) - opts->nr_cblocks =strtol (str,NULL ,0 ); -if (!opts->nr_cblocks) - opts->nr_cblocks = nr_cblocks_default; +return 0 ; }
tools/perf/builtin-record.c static int record__aio_parse(const struct option *opt, · line 308
Quoted 10 lines
tools/perf/builtin-record.c +8
-0+if (str) + opts->nr_cblocks =strtol (str,NULL ,0 ); +if (!opts->nr_cblocks) + opts->nr_cblocks = nr_cblocks_default; + +if (opts->nr_cblocks > nr_cblocks_max) + opts->nr_cblocks = nr_cblocks_max; +return 0 ;
does not seem to be related to the patch, if that's the case please separate
jirka
Re: [PATCH v5 07/10] perf record: implement -z,--compression_level=n option and compression
Quoted 29 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 06:58:32PM +0300, Alexey Budankov wrote:
SNIP
Quoted 25 lines
tools/perf/builtin-record.c +4
-6+static int record__aio_enabled (struct record *rec); +static void record__aio_mmap_read_sync (struct record *rec) {int i;struct perf_evlist *evlist = rec->evlist;struct perf_mmap *maps = evlist->mmap; -if (!rec->opts.nr_cblocks) +if (!record__aio_enabled (rec))return ;for (i =0 ; i < evlist->nr_mmaps; i++) {@@ -292,13 +294,17 @@ static int record__aio_parse(const struct option *opt,if (unset) { opts->nr_cblocks =0 ; - }else { -if (str) - opts->nr_cblocks =strtol (str,NULL ,0 ); -if (!opts->nr_cblocks) - opts->nr_cblocks = nr_cblocks_default; +return 0 ; }
Quoted 11 lines
tools/perf/builtin-record.c static int record__aio_parse(const struct option *opt, · line 308
Quoted 9 lines
tools/perf/builtin-record.c +8
-0+if (str) + opts->nr_cblocks =strtol (str,NULL ,0 ); +if (!opts->nr_cblocks) + opts->nr_cblocks = nr_cblocks_default; + +if (opts->nr_cblocks > nr_cblocks_max) + opts->nr_cblocks = nr_cblocks_max; +return 0 ;does not seem to be related to the patch, if that's the case please separate
in v7.
~Alexey
Quoted 3 lines
jirka
PATCH v5 8/10 perf report: implement record trace decompression
In reply to Alexey BudankovTrace frames containing PERF_RECORD_COMPRESSED records are decompressed using functions from zstd.c into a linked list of mmaped memory regions of mmap_comp_len size (struct decomp).
After decompression of one COMPRESSED record its content is iterated and fetched for usual processing. The mmaped memory regions with decompressed events are kept till the tool process termination.
When dumping raw trace (e.g., perf report -D --header) file offsets of events from compressed records are printed as zero.
--- tools/perf/builtin-report.c | 5 +- tools/perf/util/compress.h | 4 ++ tools/perf/util/session.c | 124 +++++++++++++++++++++++++++++++++++- tools/perf/util/session.h | 10 +++ tools/perf/util/tool.h | 2 + tools/perf/util/zstd.c | 48 ++++++++++++++ 6 files changed, 191 insertions(+), 2 deletions(-)
tools/perf/builtin-report.c +4 -1
@@ -1215,6 +1215,9 @@ int cmd_report(int argc, const char **argv)if (session ==NULL )return -1 ; +if (zstd_init (&(session->zstd_data),0 ) <0 ) +pr_warning ("Decompression initialization failed. Reported data may be incomplete.\n" ); +if (report.queue_size) {ordered_events__set_alloc_size (&session->ordered_events, report.queue_size);
@@ -1427,7 +1430,7 @@ int cmd_report(int argc, const char **argv) error:zfree (&report.ptime_range); - +zstd_fini (&(session->zstd_data));perf_session__delete (session);return ret; }
tools/perf/util/compress.h +4 -0
@@ -20,6 +20,7 @@ bool lzma_is_compressed(const char *input);struct zstd_data {#ifdef HAVE_ZSTD_SUPPORT ZSTD_CStream *cstream; +ZSTD_DStream *dstream;#endif };
@@ -30,4 +31,7 @@ size_t zstd_compress_stream_to_records(struct zstd_data *data, void *dst, size_t dst_size, void *src, size_t src_size, size_t max_record_size, size_t process_header(void *record, size_t increment)); +size_t zstd_decompress_stream (struct zstd_data *data, +void *src,size_t src_size,void *dst,size_t dst_size); +#endif /* PERF_COMPRESS_H */
tools/perf/util/session.c +123 -1
184 lines not on this page · raw message
tools/perf/util/session.h +10 -0
@@ -39,6 +39,16 @@ struct perf_session {u64 bytes_transferred;u64 bytes_compressed;struct zstd_data zstd_data; +struct decomp *decomp; +struct decomp *decomp_last; +}; + +struct decomp { +struct decomp *next; +u64 file_pos; +u64 head; +size_t size; +char data[]; };struct perf_tool ;
tools/perf/util/tool.h +2 -0
@@ -28,6 +28,7 @@ typedef int (*event_attr_op)(struct perf_tool *tool,typedef int (*event_op2 )(struct perf_session *session,union perf_event *event);typedef s64 (*event_op3 )(struct perf_session *session,union perf_event *event); +typedef int (*event_op4 )(struct perf_session *session,union perf_event *event,u64 data);typedef int (*event_oe )(struct perf_tool *tool,union perf_event *event,struct ordered_events *oe);
@@ -72,6 +73,7 @@ struct perf_tool { stat, stat_round, feature; +event_op4 compressed;event_op3 auxtrace;bool ordered_events;bool ordering_requires_timestamps;
tools/perf/util/zstd.c +48 -0
70 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v5 08/10] perf report: implement record trace decompression
On Fri, Mar 01, 2019 at 07:06:23PM +0300, Alexey Budankov wrote:
SNIP
Quoted 36 lines
tools/perf/util/session.c +32
-0+static int __perf_session__process_decomp_events (struct perf_session *session) +{ +s64 skip; +u64 size, file_pos =0 ; +union perf_event *event; +struct decomp *decomp = session->decomp_last; + +if (!decomp) +return 0 ; + +while (decomp->head < decomp->size && !session_done ()) { + event =fetch_mmaped_event (session, decomp->head, decomp->size, decomp->data); +if (!event) +break ; + + size = event->header.size; +if (size <sizeof (struct perf_event_header ) || + (skip =perf_session__process_event (session, event, file_pos)) <0 ) { +pr_err ("%#" PRIx64" [%#x]: failed to process type: %d\n" , + decomp->file_pos + decomp->head, event->header.size, event->header.type); +return -EINVAL ; + } + +if (skip) + size += skip; + + decomp->head += size; + } + +return 0 ; +} +/* * On 64bit we can mmap the data file in one go. No need for tiny mmap * slices. On 32bit we use 32MB.
tools/perf/util/session.c reader__process_events(struct reader *rd, struct perf_session *session, · line 2056
Quoted 6 lines
tools/perf/util/session.c +3
-0@@ -1933,6 +2051,10 @@ reader__process_events(struct reader *rd, struct perf_session *session, head += size; file_pos += size; + err =__perf_session__process_decomp_events (session); +if (err) + goto out;
why don't we process decompressed events directly from the perf_session__process_compressed_event callback?
there would be no need for 'struct decomp' list logic
jirka
Re: [PATCH v5 08/10] perf report: implement record trace decompression
Quoted 43 lines · Jiri Olsa
On Fri, Mar 01, 2019 at 07:06:23PM +0300, Alexey Budankov wrote:
SNIP
Quoted 39 lines
tools/perf/util/session.c +32
-0+static int __perf_session__process_decomp_events (struct perf_session *session) +{ +s64 skip; +u64 size, file_pos =0 ; +union perf_event *event; +struct decomp *decomp = session->decomp_last; + +if (!decomp) +return 0 ; + +while (decomp->head < decomp->size && !session_done ()) { + event =fetch_mmaped_event (session, decomp->head, decomp->size, decomp->data); +if (!event) +break ; + + size = event->header.size; +if (size <sizeof (struct perf_event_header ) || + (skip =perf_session__process_event (session, event, file_pos)) <0 ) { +pr_err ("%#" PRIx64" [%#x]: failed to process type: %d\n" , + decomp->file_pos + decomp->head, event->header.size, event->header.type); +return -EINVAL ; + } + +if (skip) + size += skip; + + decomp->head += size; + } + +return 0 ; +} +/* * On 64bit we can mmap the data file in one go. No need for tiny mmap * slices. On 32bit we use 32MB. @@ -1933,6 +2051,10 @@ reader__process_events(struct reader *rd, struct perf_session *session, head += size; file_pos += size;
Quoted 8 lines
tools/perf/util/session.c reader__process_events(struct reader *rd, struct perf_session *session, · line 2056
Quoted 3 lines
tools/perf/util/session.c +3
-0+ err =__perf_session__process_decomp_events (session); +if (err) + goto out;why don't we process decompressed events directly from the
perf_session__process_compressed_eventcallback?there would be no need for 'struct decomp' list logic
It would, because events need to stay in memory after decompression. It looks reasonable to keep new processing code at the same place where the processing is implemented currently.
~Alexey
Quoted 3 lines
jirka
PATCH v5 9/10 perf inject: enable COMPRESSED records decompression
In reply to Alexey BudankovInitialized decompression API so COMPRESSED record would be decompressed into the resulting output data file.
--- tools/perf/builtin-inject.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/builtin-inject.c +4 -0
@@ -837,6 +837,9 @@ int cmd_inject(int argc, const char **argv)if (inject.session ==NULL )return -1 ; +if (zstd_init (&(inject.session->zstd_data),0 ) <0 ) +pr_warning ("Decompression initialization failed.\n" ); +if (inject.build_ids) {/* * to make sure the mmap records are ordered correctly
@@ -867,6 +870,7 @@ int cmd_inject(int argc, const char **argv) ret =__cmd_inject (&inject); out_delete: +zstd_fini (&(inject.session->zstd_data));perf_session__delete (inject.session);return ret; }
Signature · 1 line
2.20.1
Re: [PATCH v5 09/10] perf inject: enable COMPRESSED records decompression
Quoted 14 lines · Alexey Budankov
Initialized decompression API so COMPRESSED record would be decompressed into the resulting output data file.
Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/builtin-inject.c | 4 ++++ 1 file changed, 4 insertions(+)tools/perf/builtin-inject.c +0
-0
tools/perf/builtin-inject.c int cmd_inject(int argc, const char **argv) · line 841
Quoted 5 lines
tools/perf/builtin-inject.c +2
-0@@ -837,6 +837,9 @@ int cmd_inject(int argc, const char **argv)if (inject.session ==NULL )return -1 ; +if (zstd_init (&(inject.session->zstd_data),0 ) <0 ) +pr_warning ("Decompression initialization failed.\n" );
hum, I wonder we should put this inside perf_session__new/perf_session__delete
jirka
Quoted 15 lines
tools/perf/builtin-inject.c +2
-0+if (inject.build_ids) {/* * to make sure the mmap records are ordered correctly @@ -867,6 +870,7 @@ int cmd_inject(int argc, const char **argv) ret =__cmd_inject (&inject); out_delete: +zstd_fini (&(inject.session->zstd_data));perf_session__delete (inject.session);return ret; }Signature · 1 line
2.20.1
Re: [PATCH v5 09/10] perf inject: enable COMPRESSED records decompression
Quoted 18 lines · Jiri Olsa
Quoted 17 lines · Alexey Budankov
Initialized decompression API so COMPRESSED record would be decompressed into the resulting output data file.
Signed-off-by Alexey Budankov <[email protected]>--- tools/perf/builtin-inject.c | 4 ++++ 1 file changed, 4 insertions(+)tools/perf/builtin-inject.c +0
-0@@ -837,6 +837,9 @@ int cmd_inject(int argc, const char **argv)if (inject.session ==NULL )return -1 ;
Quoted 4 lines
tools/perf/builtin-inject.c int cmd_inject(int argc, const char **argv) · line 841
Quoted 2 lines
tools/perf/builtin-inject.c +2
-0+if (zstd_init (&(inject.session->zstd_data),0 ) <0 ) +pr_warning ("Decompression initialization failed.\n" );hum, I wonder we should put this inside perf_session__new/perf_session__delete
comp_level parameter passing would extend the signature of __new()
struct perf_session *perf_session__new(struct perf_data *data,
bool repipe, struct perf_tool *tool, int comp_level)
~Alexey
Quoted 19 lines
jirka
Quoted 15 lines
tools/perf/builtin-inject.c +2
-0+if (inject.build_ids) {/* * to make sure the mmap records are ordered correctly @@ -867,6 +870,7 @@ int cmd_inject(int argc, const char **argv) ret =__cmd_inject (&inject); out_delete: +zstd_fini (&(inject.session->zstd_data));perf_session__delete (inject.session);return ret; }Signature · 1 line
2.20.1
PATCH v5 10/10 perf tests: implement Zstd comp/decomp integration test
In reply to Alexey BudankovImplemented basic integration test for Zstd based trace compression/decompression in record and report modes.
--- .../tests/shell/record+zstd_comp_decomp.sh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tools/perf/tests/shell/record+zstd_comp_decomp.sh
tools/perf/tests/shell/record+zstd_comp_decomp.sh new file +28 -0
@@ -0,0 +1,28 @@ +#!/bin/sh +# record trace Zstd compression/decompression + +trace_file=$(mktemp /tmp/perf.data.XXX) +perf_tool=perf +output=/dev/null + +skip_if_no_z_record() { + $perf_tool record -h 2>&1 | grep '\-z, \-\-compression\-level <n>' +} + +collect_z_record() { + echo "Collecting compressed record trace file:" + $perf_tool record -o $trace_file -a -z 1 -F 25000 -e cycles -- \ + dd count=2000 if=/dev/random of=/dev/null > $output 2>&1 +} + +check_compressed_stats() { + echo "Checking compressed events stats:" + $perf_tool report -i $trace_file --header --stats | \ + grep -E "(# compressed : Zstd,)|(COMPRESSED events:)" > $output 2>&1 +} + +skip_if_no_z_record || exit 2 +collect_z_record && check_compressed_stats +err=$? +rm -f $trace_file +exit $err
Signature · 1 line
2.20.1
Re: [PATCH v5 10/10] perf tests: implement Zstd comp/decomp integration test
Quoted 28 lines · Alexey Budankov
Implemented basic integration test for Zstd based trace compression/decompression in record and report modes.
Signed-off-by Alexey Budankov <[email protected]>--- .../tests/shell/record+zstd_comp_decomp.sh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tools/perf/tests/shell/record+zstd_comp_decomp.shtools/perf/tests/shell/record+zstd_comp_decomp.sh new file +12
-0@@ -0,0 +1,28 @@ +#!/bin/sh +# record trace Zstd compression/decompression + +trace_file=$(mktemp /tmp/perf.data.XXX) +perf_tool=perf +output=/dev/null + +skip_if_no_z_record() { + $perf_tool record -h 2>&1 | grep '\-z, \-\-compression\-level <n>' +} + +collect_z_record() {
tools/perf/tests/shell/record+zstd_comp_decomp.sh line 22
Quoted 10 lines
tools/perf/tests/shell/record+zstd_comp_decomp.sh new file +10
-0+ echo "Collecting compressed record trace file:" + $perf_tool record -o $trace_file -a -z 1 -F 25000 -e cycles -- \ + dd count=2000 if=/dev/random of=/dev/null > $output 2>&1 +} + +check_compressed_stats() { + echo "Checking compressed events stats:" + $perf_tool report -i $trace_file --header --stats | \ + grep -E "(# compressed : Zstd,)|(COMPRESSED events:)" > $output 2>&1 +}
so perf inject can decompress the perf.data and store uncompressed one, right? would be great to 'uncompress' the perf data and compare 'perf report --stdio > out.X' outputs
thanks a lot for adding tests!
jirka
Re: [PATCH v5 10/10] perf tests: implement Zstd comp/decomp integration test
Quoted 34 lines · Jiri Olsa
Quoted 33 lines · Alexey Budankov
Implemented basic integration test for Zstd based trace compression/decompression in record and report modes.
Signed-off-by Alexey Budankov <[email protected]>--- .../tests/shell/record+zstd_comp_decomp.sh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tools/perf/tests/shell/record+zstd_comp_decomp.shtools/perf/tests/shell/record+zstd_comp_decomp.sh new file +17
-0@@ -0,0 +1,28 @@ +#!/bin/sh +# record trace Zstd compression/decompression + +trace_file=$(mktemp /tmp/perf.data.XXX) +perf_tool=perf +output=/dev/null + +skip_if_no_z_record() { + $perf_tool record -h 2>&1 | grep '\-z, \-\-compression\-level <n>' +} + +collect_z_record() { + echo "Collecting compressed record trace file:" + $perf_tool record -o $trace_file -a -z 1 -F 25000 -e cycles -- \ + dd count=2000 if=/dev/random of=/dev/null > $output 2>&1 +} +
Quoted 8 lines
tools/perf/tests/shell/record+zstd_comp_decomp.sh line 22
Quoted 5 lines
tools/perf/tests/shell/record+zstd_comp_decomp.sh new file +5
-0+check_compressed_stats() { + echo "Checking compressed events stats:" + $perf_tool report -i $trace_file --header --stats | \ + grep -E "(# compressed : Zstd,)|(COMPRESSED events:)" > $output 2>&1 +}so perf inject can decompress the perf.data and store uncompressed one, right? would be great to 'uncompress'
Right.
Quoted 4 lines
the perf data and compare 'perf report --stdio > out.X' outputs
thanks a lot for adding tests!
You are welcome.
Implemented test performs some level of sanity testing for the feature and it is all that I can provide in this patch set.
~Alexey
Quoted 3 lines
jirka