ewmscp  ..
stattest.cpp
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <unistd.h>
4 #include <iostream>
5 #include <chrono>
6 #include <system_error>
7 #include <map>
8 #include <fcntl.h>
9 
10 typedef std::chrono::steady_clock clock_type;
11 
12 
13 int main(int argc, const char *argv[]) {
14  auto lastOutputTime = clock_type::now();
15 
16  if (argc == 2) {
17  struct stat statbuf;
18 
19  unsigned long long attempts = 0;
20  unsigned long long success = 0;
21  unsigned long long fail = 0;
22  std::map<int, unsigned long long> errorCodes;
23 
24  while (true) {
25  attempts++;
26  auto retval = stat(argv[1], &statbuf);
27 
28  if (retval) {
29  errorCodes[errno]++;
30  fail++;
31  } else {
32  success++;
33  }
34 
35  auto now = clock_type::now();
36 
37  if (now > lastOutputTime + std::chrono::seconds(1)) {
38  std::cout << attempts << " " << success << " " << fail << ": ";
39 
40  for (auto& item : errorCodes) {
41  std::cout << std::system_category().default_error_condition(item.first).message();
42  std::cout << ": " << item.second;
43  }
44 
45  std::cout << "\r";
46  std::cout.flush();
47  lastOutputTime = now;
48  }
49  }
50  } else {
51  unsigned long long count = 0;
52 
53  while (true) {
54  count++;
55  mkdir(argv[1], 0755);
56  auto fd = creat(argv[2], 0644);
57  write(fd, argv[1], 16);
58  close(fd);
59  unlink(argv[2]);
60  rmdir(argv[1]);
61  auto now = clock_type::now();
62 
63  if (now > lastOutputTime + std::chrono::seconds(1)) {
64  std::cout << count << "\r";
65  std::cout.flush();
66  lastOutputTime = now;
67  }
68  }
69  }
70 
71  return 0;
72 }
clock_type
std::chrono::steady_clock clock_type
Definition: stattest.cpp:10
main
int main(int argc, const char *argv[])
Definition: stattest.cpp:13