| 784 | } |
| 785 | |
| 786 | void getDiskStatistics(std::string const& directory, |
| 787 | uint64_t& currentIOs, |
| 788 | uint64_t& readMilliSecs, |
| 789 | uint64_t& writeMilliSecs, |
| 790 | uint64_t& IOMilliSecs, |
| 791 | uint64_t& reads, |
| 792 | uint64_t& writes, |
| 793 | uint64_t& writeSectors, |
| 794 | uint64_t& readSectors) { |
| 795 | INJECT_FAULT(platform_error, "getDiskStatistics"); // Getting disks statistics failed |
| 796 | currentIOs = 0; |
| 797 | |
| 798 | struct stat buf; |
| 799 | if (stat(directory.c_str(), &buf)) { |
| 800 | TraceEvent(SevError, "GetDiskStatisticsStatError").detail("Directory", directory).GetLastError(); |
| 801 | throw platform_error(); |
| 802 | } |
| 803 | |
| 804 | std::ifstream proc_stream("/proc/diskstats", std::ifstream::in); |
| 805 | while (proc_stream.good()) { |
| 806 | std::string line; |
| 807 | getline(proc_stream, line); |
| 808 | std::istringstream disk_stream(line, std::istringstream::in); |
| 809 | |
| 810 | unsigned int majorId; |
| 811 | unsigned int minorId; |
| 812 | disk_stream >> majorId; |
| 813 | disk_stream >> minorId; |
| 814 | if (majorId == (unsigned int)gnu_dev_major(buf.st_dev) && minorId == (unsigned int)gnu_dev_minor(buf.st_dev)) { |
| 815 | std::string ignore; |
| 816 | uint64_t rd_ios; /* # of reads completed */ |
| 817 | // This is the total number of reads completed successfully. |
| 818 | |
| 819 | uint64_t rd_merges; /* # of reads merged */ |
| 820 | // Reads and writes which are adjacent to each other may be merged for |
| 821 | // efficiency. Thus two 4K reads may become one 8K read before it is |
| 822 | // ultimately handed to the disk, and so it will be counted (and queued) |
| 823 | // as only one I/O. This field lets you know how often this was done. |
| 824 | |
| 825 | uint64_t rd_sectors; /*# of sectors read */ |
| 826 | // This is the total number of sectors read successfully. |
| 827 | |
| 828 | uint64_t rd_ticks; /* # of milliseconds spent reading */ |
| 829 | // This is the total number of milliseconds spent by all reads (as |
| 830 | // measured from __make_request() to end_that_request_last()). |
| 831 | |
| 832 | uint64_t wr_ios; /* # of writes completed */ |
| 833 | // This is the total number of writes completed successfully. |
| 834 | |
| 835 | uint64_t wr_merges; /* # of writes merged */ |
| 836 | // Reads and writes which are adjacent to each other may be merged for |
| 837 | // efficiency. Thus two 4K reads may become one 8K read before it is |
| 838 | // ultimately handed to the disk, and so it will be counted (and queued) |
| 839 | // as only one I/O. This field lets you know how often this was done. |
| 840 | |
| 841 | uint64_t wr_sectors; /* # of sectors written */ |
| 842 | // This is the total number of sectors written successfully. |
| 843 |
no test coverage detected