Commit ef31c53b authored by Brendan Gregg's avatar Brendan Gregg Committed by GitHub

Merge pull request #348 from iovisor/issue346

hist: split negative, zero, and one into separate buckets
parents 8aeae40d 48c0afbe
......@@ -1758,18 +1758,20 @@ Attaching 1 probe...
^C
@bytes:
[0, 1] 7 |@@@@@@@@@@@@@ |
[2, 4) 3 |@@@@@ |
[4, 8) 8 |@@@@@@@@@@@@@@ |
[8, 16) 9 |@@@@@@@@@@@@@@@@ |
[16, 32) 0 | |
[32, 64) 1 |@ |
[64, 128) 1 |@ |
[128, 256) 0 | |
[256, 512) 3 |@@@@@ |
[512, 1k) 0 | |
[1k, 2k) 12 |@@@@@@@@@@@@@@@@@@@@@@ |
[2k, 4k) 28 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
(..., 0) 117 |@@@@@@@@@@@@ |
[0] 5 | |
[1] 325 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
[2, 4) 6 | |
[4, 8) 3 | |
[8, 16) 495 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[16, 32) 35 |@@@ |
[32, 64) 25 |@@ |
[64, 128) 21 |@@ |
[128, 256) 1 | |
[256, 512) 3 | |
[512, 1K) 2 | |
[1K, 2K) 1 | |
[2K, 4K) 2 | |
```
### 8.2. Power-Of-2 By Key:
......@@ -1786,11 +1788,18 @@ Attaching 1 probe...
[2, 4) 9 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
@bytes[snmpd]:
[0, 1] 1 |@@@@ |
[1] 1 |@@@@ |
[2, 4) 0 | |
[4, 8) 0 | |
[8, 16) 4 |@@@@@@@@@@@@@@@@@@ |
[16, 32) 11 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
@bytes[irqbalance]:
(..., 0) 15 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
[0] 0 | |
[1] 0 | |
[2, 4) 0 | |
[4, 8) 21 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
```
## 9. `lhist()`: Linear Histogram
......@@ -1898,18 +1907,20 @@ Attaching 1 probe...
^C
@bytes:
[0, 1] 7 |@@@@@@@@@@@@@ |
[2, 4) 3 |@@@@@ |
[4, 8) 8 |@@@@@@@@@@@@@@ |
[8, 16) 9 |@@@@@@@@@@@@@@@@ |
[16, 32) 0 | |
[32, 64) 1 |@ |
[64, 128) 1 |@ |
[128, 256) 0 | |
[256, 512) 3 |@@@@@ |
[512, 1k) 0 | |
[1k, 2k) 12 |@@@@@@@@@@@@@@@@@@@@@@ |
[2k, 4k) 28 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
(..., 0) 117 |@@@@@@@@@@@@ |
[0] 5 | |
[1] 325 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
[2, 4) 6 | |
[4, 8) 3 | |
[8, 16) 495 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[16, 32) 35 |@@@ |
[32, 64) 25 |@@ |
[64, 128) 21 |@@ |
[128, 256) 1 | |
[256, 512) 3 | |
[512, 1K) 2 | |
[1K, 2K) 1 | |
[2K, 4K) 2 | |
```
Histograms can also be printed on-demand, using the <tt>print()</tt> function. Eg:
......
......@@ -1372,10 +1372,18 @@ Value *CodegenLLVM::createLogicalOr(Binop &binop)
void CodegenLLVM::createLog2Function()
{
// log2() returns a bucket index for the given value. Index 0 is for
// values less than 0, index 1 is for 0, and indexes 2 onwards is the
// power-of-2 histogram index.
//
// log2(int n)
// {
// int result = 0;
// int shift;
// if (n < 0) return result;
// result++;
// if (n == 0) return result;
// result++;
// for (int i = 4; i >= 0; i--)
// {
// shift = (v >= (1<<(1<<i))) << i;
......@@ -1392,14 +1400,36 @@ void CodegenLLVM::createLog2Function()
BasicBlock *entry = BasicBlock::Create(module_->getContext(), "entry", log2_func);
b_.SetInsertPoint(entry);
// setup n and result registers
Value *arg = log2_func->arg_begin();
Value *n_alloc = b_.CreateAllocaBPF(SizedType(Type::integer, 8));
b_.CreateStore(arg, n_alloc);
Value *result = b_.CreateAllocaBPF(SizedType(Type::integer, 8));
b_.CreateStore(b_.getInt64(0), result);
// test for less than zero
BasicBlock *is_less_than_zero = BasicBlock::Create(module_->getContext(), "hist.is_less_than_zero", log2_func);
BasicBlock *is_not_less_than_zero = BasicBlock::Create(module_->getContext(), "hist.is_not_less_than_zero", log2_func);
b_.CreateCondBr(b_.CreateICmpSLT(b_.CreateLoad(n_alloc), b_.getInt64(0)),
is_less_than_zero,
is_not_less_than_zero);
b_.SetInsertPoint(is_less_than_zero);
b_.CreateRet(b_.CreateLoad(result));
b_.SetInsertPoint(is_not_less_than_zero);
// test for equal to zero
BasicBlock *is_zero = BasicBlock::Create(module_->getContext(), "hist.is_zero", log2_func);
BasicBlock *is_not_zero = BasicBlock::Create(module_->getContext(), "hist.is_not_zero", log2_func);
b_.CreateCondBr(b_.CreateICmpEQ(b_.CreateLoad(n_alloc), b_.getInt64(0)),
is_zero,
is_not_zero);
b_.SetInsertPoint(is_zero);
b_.CreateStore(b_.getInt64(1), result);
b_.CreateRet(b_.CreateLoad(result));
b_.SetInsertPoint(is_not_zero);
// power-of-2 index, offset by +2
b_.CreateStore(b_.getInt64(2), result);
for (int i = 4; i >= 0; i--)
{
Value *n = b_.CreateLoad(n_alloc);
......
......@@ -1123,12 +1123,20 @@ int BPFtrace::print_hist(const std::vector<uint64_t> &values, uint32_t div) cons
std::ostringstream header;
if (i == 0)
{
header << "[0, 1]";
header << "(..., 0)";
}
else if (i == 1)
{
header << "[0]";
}
else if (i == 2)
{
header << "[1]";
}
else
{
header << "[" << hist_index_label(i);
header << ", " << hist_index_label(i+1) << ")";
header << "[" << hist_index_label(i-2);
header << ", " << hist_index_label(i-2+1) << ")";
}
int max_width = 52;
......
......@@ -9,14 +9,6 @@ Tracing block device I/O... Hit Ctrl-C to end.
^C
@usecs:
[0, 1] 0 | |
[2, 4) 0 | |
[4, 8) 0 | |
[8, 16) 0 | |
[16, 32) 0 | |
[32, 64) 0 | |
[64, 128) 0 | |
[128, 256) 0 | |
[256, 512) 2 | |
[512, 1K) 10 |@ |
[1K, 2K) 426 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
......
......@@ -11,55 +11,20 @@ Tracing block device I/O... Hit Ctrl-C to end.
I/O size (bytes) histograms by process name:
@[cleanup]:
[0, 1] 0 | |
[2, 4) 0 | |
[4, 8) 0 | |
[8, 16) 0 | |
[16, 32) 0 | |
[32, 64) 0 | |
[64, 128) 0 | |
[128, 256) 0 | |
[256, 512) 0 | |
[512, 1K) 0 | |
[1K, 2K) 0 | |
[2K, 4K) 0 | |
[4K, 8K) 2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
@[postdrop]:
[0, 1] 0 | |
[2, 4) 0 | |
[4, 8) 0 | |
[8, 16) 0 | |
[16, 32) 0 | |
[32, 64) 0 | |
[64, 128) 0 | |
[128, 256) 0 | |
[256, 512) 0 | |
[512, 1K) 0 | |
[1K, 2K) 0 | |
[2K, 4K) 0 | |
[4K, 8K) 2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
@[jps]:
[0, 1] 0 | |
[2, 4) 0 | |
[4, 8) 0 | |
[8, 16) 0 | |
[16, 32) 0 | |
[32, 64) 0 | |
[64, 128) 0 | |
[128, 256) 0 | |
[256, 512) 0 | |
[512, 1K) 0 | |
[1K, 2K) 0 | |
[2K, 4K) 0 | |
[4K, 8K) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@ |
[8K, 16K) 0 | |
[16K, 32K) 0 | |
[32K, 64K) 2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
@[kworker/2:1H]:
[0, 1] 3 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[0] 3 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[1] 0 | |
[2, 4) 0 | |
[4, 8) 0 | |
[8, 16) 0 | |
......@@ -78,18 +43,6 @@ I/O size (bytes) histograms by process name:
[64K, 128K) 1 |@@@@@@@@@@@@@@@@@ |
@[jbd2/nvme0n1-8]:
[0, 1] 0 | |
[2, 4) 0 | |
[4, 8) 0 | |
[8, 16) 0 | |
[16, 32) 0 | |
[32, 64) 0 | |
[64, 128) 0 | |
[128, 256) 0 | |
[256, 512) 0 | |
[512, 1K) 0 | |
[1K, 2K) 0 | |
[2K, 4K) 0 | |
[4K, 8K) 3 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[8K, 16K) 0 | |
[16K, 32K) 0 | |
......@@ -97,20 +50,6 @@ I/O size (bytes) histograms by process name:
[64K, 128K) 1 |@@@@@@@@@@@@@@@@@ |
@[dd]:
[0, 1] 0 | |
[2, 4) 0 | |
[4, 8) 0 | |
[8, 16) 0 | |
[16, 32) 0 | |
[32, 64) 0 | |
[64, 128) 0 | |
[128, 256) 0 | |
[256, 512) 0 | |
[512, 1K) 0 | |
[1K, 2K) 0 | |
[2K, 4K) 0 | |
[4K, 8K) 0 | |
[8K, 16K) 0 | |
[16K, 32K) 921 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
The most active process while tracing was "dd", which issues 921 I/O between
......
......@@ -13,7 +13,8 @@ Tracing CPU scheduler... Hit Ctrl-C to end.
@usecs:
[0, 1] 12 |@@ |
[0] 1 | |
[1] 11 |@@ |
[2, 4) 16 |@@@ |
[4, 8) 43 |@@@@@@@@@@ |
[8, 16) 134 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
......@@ -57,7 +58,7 @@ Tracing CPU scheduler... Hit Ctrl-C to end.
@usecs:
[0, 1] 6 |@@@ |
[1] 6 |@@@ |
[2, 4) 26 |@@@@@@@@@@@@@ |
[4, 8) 97 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[8, 16) 72 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
......@@ -93,7 +94,8 @@ Tracing CPU scheduler... Hit Ctrl-C to end.
@usecs:
[0, 1] 9 |@@@ |
[0] 1 | |
[1] 8 |@@@ |
[2, 4) 28 |@@@@@@@@@@@@ |
[4, 8) 95 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
[8, 16) 120 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
......@@ -127,7 +129,8 @@ Tracing CPU scheduler... Hit Ctrl-C to end.
@usecs:
[0, 1] 12 |@ |
[0] 2 | |
[1] 10 |@ |
[2, 4) 38 |@@@@ |
[4, 8) 63 |@@@@@@ |
[8, 16) 106 |@@@@@@@@@@@ |
......
......@@ -10,14 +10,11 @@ Tracing XFS operation latency... Hit Ctrl-C to end.
^C
@us[xfs_file_write_iter]:
[0, 1] 0 | |
[2, 4) 0 | |
[4, 8) 0 | |
[8, 16) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@ |
[16, 32) 2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
@us[xfs_file_read_iter]:
[0, 1] 724 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[1] 724 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[2, 4) 137 |@@@@@@@@@ |
[4, 8) 143 |@@@@@@@@@@ |
[8, 16) 37 |@@ |
......@@ -37,7 +34,7 @@ Tracing XFS operation latency... Hit Ctrl-C to end.
[128K, 256K) 6 | |
@us[xfs_file_open]:
[0, 1] 1819 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[1] 1819 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[2, 4) 272 |@@@@@@@ |
[4, 8) 0 | |
[8, 16) 9 | |
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment