diff --git a/src/bpftrace.cpp b/src/bpftrace.cpp index f0125452e1c..7854e714dd0 100644 --- a/src/bpftrace.cpp +++ b/src/bpftrace.cpp @@ -890,7 +890,8 @@ int BPFtrace::clear_map(IMap &map) std::vector old_key; try { - if (map.type_.type == Type::hist) + if (map.type_.type == Type::hist || map.type_.type == Type::lhist || + map.type_.type == Type::stats || map.type_.type == Type::avg) // hist maps have 8 extra bytes for the bucket number old_key = find_empty_key(map, map.key_.size() + 8); else diff --git a/tests/runtime/other b/tests/runtime/other index 43017027716..d021b3da26f 100644 --- a/tests/runtime/other +++ b/tests/runtime/other @@ -57,3 +57,23 @@ NAME struct positional string compare - not equal RUN bpftrace -v -e 'BEGIN { if (str($1) != str($2)) { printf("I got %s\n", str($1));} else { printf("not equal\n");} exit();}' "hello" "hello" EXPECT not equal TIMEOUT 5 + +NAME lhist can be cleared +RUN bpftrace -e 'BEGIN{ @[1] = lhist(3,0,10,1); clear(@); exit() }' +EXPECT .* +TIMEOUT 1 + +NAME hist can be cleared +RUN bpftrace -e 'BEGIN{ @[1] = hist(1); clear(@); exit() }' +EXPECT .* +TIMEOUT 1 + +NAME stats can be cleared +RUN bpftrace -e 'BEGIN{ @[1] = stats(1); clear(@); exit() }' +EXPECT .* +TIMEOUT 1 + +NAME avg can be cleared +RUN bpftrace -e 'BEGIN{ @[1] = avg(1); clear(@); exit() }' +EXPECT .* +TIMEOUT 1