ewmscp  ..
Typedefs | Functions
stattest.cpp File Reference

(v0.19-24-g0617ca1 with changes)

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>
#include <chrono>
#include <system_error>
#include <map>
#include <fcntl.h>
Include dependency graph for stattest.cpp:

Go to the source code of this file.

Typedefs

typedef std::chrono::steady_clock clock_type
 

Functions

int main (int argc, const char *argv[])
 

Typedef Documentation

◆ clock_type

typedef std::chrono::steady_clock clock_type

Definition at line 10 of file stattest.cpp.

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 13 of file stattest.cpp.

13  {
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 }