1    	#include <algorithm>
2    	#include <iostream>
3    	#include <fstream>
4    	#include <string>
5    	#include <numeric>
6    	#include <regex>
7    	#include <cmath>
8    	#include <system_error>
9    	
10   	using namespace std;
11   	
12   	int main(int argc, char **argv)
13   	{
14   	  cout << "Mon RSS Usage Test" << endl;
15   	
(1) Event cond_true: Condition "argc != 2", taking true branch.
16   	  if (argc != 2) {
17   	    cout << "Syntax: "
18   	         << "ceph_test_mon_rss_usage <mon-memory-target-bytes>"
19   	         << endl;
20   	    exit(EINVAL);
21   	  }
22   	
23   	  unsigned long maxallowed = stoul(argv[1], nullptr, 10);
24   	  // Set max allowed RSS usage to be 125% of mon-memory-target
25   	  maxallowed *= 1.25;
26   	
27   	  string target_directory("/var/log/ceph/");
28   	  string filePath = target_directory + "ceph-mon-rss-usage.log";
29   	  ifstream buffer(filePath.c_str());
30   	  string line;
31   	  vector<unsigned long> results;
(2) Event cond_true: Condition "std::getline(buffer, line)->operator bool()", taking true branch.
(3) Event cond_false: Condition "!line.empty()", taking false branch.
32   	  while(getline(buffer, line) && !line.empty()) {
33   	    string rssUsage;
34   	    size_t pos = line.find(':');
35   	    if (pos != string::npos) {
36   	      rssUsage = line.substr(0, pos);
37   	    }
38   	    if (!rssUsage.empty()) {
39   	      results.push_back(stoul(rssUsage));
40   	    }
(4) Event loop_end: Reached end of loop.
41   	  }
42   	
43   	  buffer.close();
(5) Event cond_true: Condition "results.empty()", taking true branch.
44   	  if (results.empty()) {
45   	    cout << "Error: No grep results found!" << endl;
46   	    exit(ENOENT);
47   	  }
48   	
49   	  auto maxe = *(max_element(results.begin(), results.end()));
50   	  cout << "Stats for mon RSS Memory Usage:" << endl;
51   	  cout << "Parsed " << results.size() << " entries." << endl;
52   	  cout << "Max: " << maxe << endl;
53   	  cout << "Min: " << *(min_element(results.begin(), results.end())) << endl;
54   	  auto sum = accumulate(results.begin(), results.end(),
55   	                        static_cast<unsigned long long>(0));
56   	  auto mean = sum / results.size();
57   	  cout << "Mean average: " << mean << endl;
58   	  vector<unsigned long> diff(results.size());
59   	  transform(results.begin(), results.end(), diff.begin(),
60   	            [mean](unsigned long x) { return x - mean; });
61   	  auto sump = inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
62   	  auto stdev = sqrt(sump / results.size());
(6) Event format_changed: "fixed" changes the format state of "std::cout" for category floatfield.
Also see events: [end_of_path]
63   	  cout << fixed <<  "Standard deviation: " << stdev << endl;
64   	
(7) Event cond_true: Condition "maxe > maxallowed", taking true branch.
65   	  if (maxe > maxallowed) {
66   	    cout << "Error: Mon RSS memory usage exceeds maximum allowed!" << endl;
67   	    exit(ENOMEM);
68   	  }
69   	
70   	  cout << "Completed successfully" << endl;
(8) Event end_of_path: Changing format state of stream "std::cout" for category floatfield without later restoring it.
Also see events: [format_changed]
71   	  return 0;
72   	}
73