]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/mon/test_mon_memory_target.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / test / mon / test_mon_memory_target.cc
1 #include <algorithm>
2 #include <cmath>
3 #include <iostream>
4 #include <string>
5 #include <numeric>
6 #include <regex>
7 #include <system_error>
8
9 #include <boost/process.hpp>
10 #include <boost/tokenizer.hpp>
11
12 namespace bp = boost::process;
13 using namespace std;
14
15 int main(int argc, char** argv)
16 {
17 cout << "Mon Memory Target Test" << endl;
18
19 if (argc != 2) {
20 cout << "Syntax: "
21 << "ceph_test_mon_memory_target <mon-memory-target-bytes>"
22 << endl;
23 exit(EINVAL);
24 }
25
26 string target_directory("/var/log/ceph/");
27 unsigned long maxallowed = stoul(argv[1], nullptr, 10);
28 regex reg(R"(cache_size:(\d*)\s)");
29
30 string grep_command("grep _set_new_cache_sizes " + target_directory
31 + "ceph-mon.a.log");
32 bp::ipstream is;
33 error_code ec;
34 bp::child grep(grep_command, bp::std_out > is, ec);
35 if (ec) {
36 cout << "Error grepping logs! Exiting" << endl;
37 cout << "Error: " << ec.value() << " " << ec.message() << endl;
38 exit(ec.value());
39 }
40
41 string line;
42 vector<unsigned long> results;
43 while (grep.running() && getline(is, line) && !line.empty()) {
44 smatch match;
45 if (regex_search(line, match, reg)) {
46 results.push_back(stoul(match[1].str()));
47 }
48 }
49
50 if (results.empty()) {
51 cout << "Error: No grep results found!" << endl;
52 exit(ENOENT);
53 }
54
55 auto maxe = *(max_element(results.begin(), results.end()));
56 cout << "Results for mon_memory_target:" << endl;
57 cout << "Max: " << maxe << endl;
58 cout << "Min: " << *(min_element(results.begin(), results.end())) << endl;
59 auto sum = accumulate(results.begin(), results.end(),
60 static_cast<unsigned long long>(0));
61 auto mean = sum / results.size();
62 cout << "Mean average: " << mean << endl;
63 vector<unsigned long> diff(results.size());
64 transform(results.begin(), results.end(), diff.begin(),
65 [mean](unsigned long x) { return x - mean; });
66 auto sump = inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
67 auto stdev = sqrt(sump / results.size());
68 cout << "Standard deviation: " << stdev << endl;
69
70 if (maxe > maxallowed) {
71 cout << "Error: Mon memory consumption exceeds maximum allowed!" << endl;
72 exit(ENOMEM);
73 }
74
75 grep.wait();
76
77 cout << "Completed successfully" << endl;
78 return 0;
79 }