dhat: remove initial count value from access count histogram user requests
[valgrind.git] / dhat / tests / user_histo1.cpp
blob191fde2c5ae2f8c4d0c2268de2db9b4fec600e93
1 #include <vector>
2 #include <cstdint>
3 #include <iostream>
4 #include <random>
5 #include "dhat/dhat.h"
7 int main()
9 std::vector<uint8_t> vec(2000, 0);
10 DHAT_HISTOGRAM_MEMORY(vec.data());
11 std::mt19937 gen(42);;
12 std::uniform_int_distribution<> index_distrib(0, 1999);
13 std::uniform_int_distribution<> val_distrib(0, 255);
15 for (int i = 0; i < 20; ++i)
17 int index = index_distrib(gen);
18 int val = val_distrib(gen);
19 vec[index] = val;
20 //std::cout << "wrote " << val << " to index " << index << "\n";
23 // try to generate some warnings
24 vec.resize(500);
25 vec.shrink_to_fit();
26 DHAT_HISTOGRAM_MEMORY(vec.data());
28 auto old = vec.data();
29 vec.resize(100000);
30 // old should have been deleted
31 DHAT_HISTOGRAM_MEMORY(old);
32 // and this is too big
33 DHAT_HISTOGRAM_MEMORY(vec.data());