Public bug reported:

Each one second, my program reads /sys/block/$DEVICE/stat.

It substracts previously saved values, then saves current values, so I know the 
hdd activity.
But sometimes (once in 7 days) I've got too big values for sda (between last 
and current ones) (for example 5GB/second, 19GB/second, etc...).

sudo lshw -class disk
 *-disk
       description: ATA Disk
       product: SPCC Solid State
       physical id: 0.0.0
       bus info: scsi@2:0.0.0
       logical name: /dev/sda
       version: 08.2
       serial: EB84075517B200427436
       size: 111GiB (120GB)
       capabilities: partitioned partitioned:dos
       configuration: ansiversion=5 logicalsectorsize=512 sectorsize=512 
signature=d01f3b8e

Also I've written the script for monitoring the statistics

#!/bin/bash

while (true) do
 str=`date`" $(cat /sys/block/sda/stat)"
 echo $str >> log.txt
 sleep 10;
done

And got this values

Fr Jul 28 07:39:38 MSK 2017 2368466 475339 105223134 1362848 5753154 7692148 
661424840 31319540 0 4790052 32687100
Fr Jul 28 07:39:48 MSK 2017 2368466 475339 105223134 1362848 5753170 7692160 
661425104 31319548 0 4790060 32687108
Fr Jul 28 07:39:58 MSK 2017 2368466 475339 105223134 1362848 5753174 7692162 
661425152 31319556 0 4790068 32687116
Fr Jul 28 07:40:08 MSK 2017 2369133 475339 105228750 1363380 5771079 7694395 
706209560 31324696 0 4795572 32692780
Fr Jul 28 07:40:18 MSK 2017 2369133 475339 105228750 1363380 5771087 7694431 
706209960 31324708 0 4795584 32692792
Fr Jul 28 07:40:28 MSK 2017 2369133 475339 105228750 1363380 5771091 7694433 
706210008 31324716 0 4795592 32692800
Fr Jul 28 07:40:38 MSK 2017 2369133 475339 105228750 1363380 5771244 7694714 
706213528 31325052 0 4795604 32693136

You can see that the difference (3,4 lines) is very big between
706209560 and 661425152, my ssd can read 250 Mb/sec, but not 5 Gb/sec.

Also you can use this program for monitoring (g++ -std=c++14 name.cpp)

#include <iostream>
#include <fstream>
#include <regex>
#include <tuple>
#include <chrono>
#include <thread>
#include <cstdint>

const int HDD_READ_POS     = 2;
const int HDD_WRITE_POS    = 6;
const int UNIX_SECTOR_SIZE = 512;
uint64_t prevRead  = static_cast<uint64_t>(0);
uint64_t prevWrite = static_cast<uint64_t>(0);

std::tuple<uint64_t, uint64_t> hddStatus(const std::string &name="sda")
{
    std::ifstream in("/sys/block/"+name+"/stat");

    auto readVal_ = static_cast<uint64_t>(0);
    auto writeVal_= static_cast<uint64_t>(0);

    if ( ! in.is_open() ) {
        return std::tuple<uint64_t, uint64_t> (readVal_, writeVal_);
    }

    std::string line;
    std::regex rgx ( "\\d+" );
    std::regex_token_iterator<std::string::iterator> end;

    while (std::getline(in, line) ){

        std::regex_token_iterator<std::string::iterator> iter( line.begin(), 
line.end(), rgx, 0 );
        int pos_ = 0 ;

        while ( iter != end ) {

            if ( pos_ == HDD_READ_POS){
                readVal_ = std::stoul( *iter ) ;
            }

            if ( pos_ == HDD_WRITE_POS){
                writeVal_ = std::stoul( *iter ) ;
            }

            ++iter;
            ++pos_;
        }
    }

    return std::tuple<uint64_t, uint64_t> (readVal_, writeVal_);

}

void init()
{

        auto values = hddStatus();
        prevRead  = std::get<0>( values ) * UNIX_SECTOR_SIZE;
        prevWrite = std::get<1>( values ) * UNIX_SECTOR_SIZE;

}

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

        while(true){

            std::ofstream stat("statistics.txt", std::fstream::out | 
std::fstream::app);
            if ( stat.is_open() ){

            auto values = hddStatus();
            auto read  = std::get<0>( values ) * UNIX_SECTOR_SIZE;
            auto write = std::get<1>( values ) * UNIX_SECTOR_SIZE;

             // stat<<"Current Read: "<< read<<" Write: "<<write<<'\n';
            if (read > prevRead){
                stat<<"Diff Read: "<< read - prevRead <<'\n';
                std::cout<<"Diff Read: "<< read - prevRead <<'\n';
            }

            if ( write > prevWrite){
                stat<<"Diff Write: "<<write - prevWrite <<'\n';
                std::cout<<"Diff Write: "<<write - prevWrite <<'\n';
            }

            prevRead  = read;
            prevWrite = write;

            std::this_thread::sleep_for(std::chrono::seconds(1));

        }
    }

    return 0;

}

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: linux-image-4.10.0-32-generic 4.10.0-32.36~16.04.1
ProcVersionSignature: Ubuntu 4.10.0-32.36~16.04.1-generic 4.10.17
Uname: Linux 4.10.0-32-generic x86_64
ApportVersion: 2.20.1-0ubuntu2.10
Architecture: amd64
CurrentDesktop: Unity
Date: Fri Aug 25 13:43:59 2017
InstallationDate: Installed on 2017-04-14 (132 days ago)
InstallationMedia: Ubuntu 16.04.1 LTS "Xenial Xerus" - Release amd64 (20160719)
SourcePackage: linux-hwe
UpgradeStatus: No upgrade log present (probably fresh install)

** Affects: linux-hwe (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug xenial

** Attachment added: "Screenshot"
   
https://bugs.launchpad.net/bugs/1713029/+attachment/4938511/+files/Screenshot%20from%202017-07-28%2010-48-37.png

** Description changed:

  Each one second, my program reads /sys/block/$DEVICE/stat.
  
- It substracts previously saved values, then saves current values, so I know 
the hdd activity. 
- But sometimes (once in 7 days) I've got too big values for sda (between last 
and current ones) (5GB/second).
+ It substracts previously saved values, then saves current values, so I know 
the hdd activity.
+ But sometimes (once in 7 days) I've got too big values for sda (between last 
and current ones) (for example 5GB/second, 19GB/second).
  
  sudo lshw -class disk
-  *-disk                  
-        description: ATA Disk
-        product: SPCC Solid State
-        physical id: 0.0.0
-        bus info: scsi@2:0.0.0
-        logical name: /dev/sda
-        version: 08.2
-        serial: EB84075517B200427436
-        size: 111GiB (120GB)
-        capabilities: partitioned partitioned:dos
-        configuration: ansiversion=5 logicalsectorsize=512 sectorsize=512 
signature=d01f3b8e
+  *-disk
+        description: ATA Disk
+        product: SPCC Solid State
+        physical id: 0.0.0
+        bus info: scsi@2:0.0.0
+        logical name: /dev/sda
+        version: 08.2
+        serial: EB84075517B200427436
+        size: 111GiB (120GB)
+        capabilities: partitioned partitioned:dos
+        configuration: ansiversion=5 logicalsectorsize=512 sectorsize=512 
signature=d01f3b8e
  
  Also I've written the script for monitoring the statistics
  
  #!/bin/bash
  
  while (true) do
-       str=`date`" $(cat /sys/block/sda/stat)"
-       echo $str >> log.txt
-       sleep 10;
- done  
+  str=`date`" $(cat /sys/block/sda/stat)"
+  echo $str >> log.txt
+  sleep 10;
+ done
  
  And got this values
  
  Fr Jul 28 07:39:38 MSK 2017 2368466 475339 105223134 1362848 5753154 7692148 
661424840 31319540 0 4790052 32687100
  Fr Jul 28 07:39:48 MSK 2017 2368466 475339 105223134 1362848 5753170 7692160 
661425104 31319548 0 4790060 32687108
  Fr Jul 28 07:39:58 MSK 2017 2368466 475339 105223134 1362848 5753174 7692162 
661425152 31319556 0 4790068 32687116
  Fr Jul 28 07:40:08 MSK 2017 2369133 475339 105228750 1363380 5771079 7694395 
706209560 31324696 0 4795572 32692780
  Fr Jul 28 07:40:18 MSK 2017 2369133 475339 105228750 1363380 5771087 7694431 
706209960 31324708 0 4795584 32692792
  Fr Jul 28 07:40:28 MSK 2017 2369133 475339 105228750 1363380 5771091 7694433 
706210008 31324716 0 4795592 32692800
  Fr Jul 28 07:40:38 MSK 2017 2369133 475339 105228750 1363380 5771244 7694714 
706213528 31325052 0 4795604 32693136
  
  You can see that the difference (3,4 lines) is very big between
  706209560 and 661425152, my ssd can read 250 Mb/sec, but not 5 Gb/sec.
  
  Also you can use this program for monitoring (g++ -std=c++14 name.cpp)
  
  #include <iostream>
  #include <fstream>
  #include <regex>
  #include <tuple>
  #include <chrono>
  #include <thread>
  #include <cstdint>
  
  const int HDD_READ_POS     = 2;
  const int HDD_WRITE_POS    = 6;
  const int UNIX_SECTOR_SIZE = 512;
  uint64_t prevRead  = static_cast<uint64_t>(0);
  uint64_t prevWrite = static_cast<uint64_t>(0);
  
  std::tuple<uint64_t, uint64_t> hddStatus(const std::string &name="sda")
  {
-     std::ifstream in("/sys/block/"+name+"/stat");
+     std::ifstream in("/sys/block/"+name+"/stat");
  
-     auto readVal_ = static_cast<uint64_t>(0);
-     auto writeVal_= static_cast<uint64_t>(0);
+     auto readVal_ = static_cast<uint64_t>(0);
+     auto writeVal_= static_cast<uint64_t>(0);
  
-     if ( ! in.is_open() ) {
-         return std::tuple<uint64_t, uint64_t> (readVal_, writeVal_);
-     }
+     if ( ! in.is_open() ) {
+         return std::tuple<uint64_t, uint64_t> (readVal_, writeVal_);
+     }
  
-     std::string line;
-     std::regex rgx ( "\\d+" );
-     std::regex_token_iterator<std::string::iterator> end;
+     std::string line;
+     std::regex rgx ( "\\d+" );
+     std::regex_token_iterator<std::string::iterator> end;
  
-     while (std::getline(in, line) ){
+     while (std::getline(in, line) ){
  
-         std::regex_token_iterator<std::string::iterator> iter( line.begin(), 
line.end(), rgx, 0 );
-         int pos_ = 0 ;
+         std::regex_token_iterator<std::string::iterator> iter( line.begin(), 
line.end(), rgx, 0 );
+         int pos_ = 0 ;
  
-         while ( iter != end ) {
+         while ( iter != end ) {
  
-             if ( pos_ == HDD_READ_POS){
-                 readVal_ = std::stoul( *iter ) ;
-             }
+             if ( pos_ == HDD_READ_POS){
+                 readVal_ = std::stoul( *iter ) ;
+             }
  
-             if ( pos_ == HDD_WRITE_POS){
-                 writeVal_ = std::stoul( *iter ) ;
-             }
+             if ( pos_ == HDD_WRITE_POS){
+                 writeVal_ = std::stoul( *iter ) ;
+             }
  
-             ++iter;
-             ++pos_;
-         }
-     }
+             ++iter;
+             ++pos_;
+         }
+     }
  
-     return std::tuple<uint64_t, uint64_t> (readVal_, writeVal_);
+     return std::tuple<uint64_t, uint64_t> (readVal_, writeVal_);
  
  }
- 
  
  void init()
  {
  
-         auto values = hddStatus();
-         prevRead  = std::get<0>( values ) * UNIX_SECTOR_SIZE;
-         prevWrite = std::get<1>( values ) * UNIX_SECTOR_SIZE;
+         auto values = hddStatus();
+         prevRead  = std::get<0>( values ) * UNIX_SECTOR_SIZE;
+         prevWrite = std::get<1>( values ) * UNIX_SECTOR_SIZE;
  
  }
  
- 
  int main(int argc, char const *argv[])
  {
-     init();
-           
+     init();
  
-         while(true){
+         while(true){
  
-             std::ofstream stat("statistics.txt", std::fstream::out | 
std::fstream::app);
-             if ( stat.is_open() ){    
-        
-             auto values = hddStatus();
-             auto read  = std::get<0>( values ) * UNIX_SECTOR_SIZE;
-             auto write = std::get<1>( values ) * UNIX_SECTOR_SIZE;
+             std::ofstream stat("statistics.txt", std::fstream::out | 
std::fstream::app);
+             if ( stat.is_open() ){
  
-              // stat<<"Current Read: "<< read<<" Write: "<<write<<'\n';
-             if (read > prevRead){
-                 stat<<"Diff Read: "<< read - prevRead <<'\n';
-                 std::cout<<"Diff Read: "<< read - prevRead <<'\n';
-             }
+             auto values = hddStatus();
+             auto read  = std::get<0>( values ) * UNIX_SECTOR_SIZE;
+             auto write = std::get<1>( values ) * UNIX_SECTOR_SIZE;
  
-             if ( write > prevWrite){
-                 stat<<"Diff Write: "<<write - prevWrite <<'\n';
-                 std::cout<<"Diff Write: "<<write - prevWrite <<'\n';
-             }
+              // stat<<"Current Read: "<< read<<" Write: "<<write<<'\n';
+             if (read > prevRead){
+                 stat<<"Diff Read: "<< read - prevRead <<'\n';
+                 std::cout<<"Diff Read: "<< read - prevRead <<'\n';
+             }
  
-             prevRead  = read;
-             prevWrite = write;
+             if ( write > prevWrite){
+                 stat<<"Diff Write: "<<write - prevWrite <<'\n';
+                 std::cout<<"Diff Write: "<<write - prevWrite <<'\n';
+             }
  
-             std::this_thread::sleep_for(std::chrono::seconds(1));
+             prevRead  = read;
+             prevWrite = write;
  
-         }
-     }
+             std::this_thread::sleep_for(std::chrono::seconds(1));
  
-     return 0;
-     
+         }
+     }
+ 
+     return 0;
+ 
  }
  
  ProblemType: Bug
  DistroRelease: Ubuntu 16.04
  Package: linux-image-4.10.0-32-generic 4.10.0-32.36~16.04.1
  ProcVersionSignature: Ubuntu 4.10.0-32.36~16.04.1-generic 4.10.17
  Uname: Linux 4.10.0-32-generic x86_64
  ApportVersion: 2.20.1-0ubuntu2.10
  Architecture: amd64
  CurrentDesktop: Unity
  Date: Fri Aug 25 13:43:59 2017
  InstallationDate: Installed on 2017-04-14 (132 days ago)
  InstallationMedia: Ubuntu 16.04.1 LTS "Xenial Xerus" - Release amd64 
(20160719)
  SourcePackage: linux-hwe
  UpgradeStatus: No upgrade log present (probably fresh install)

** Description changed:

  Each one second, my program reads /sys/block/$DEVICE/stat.
  
  It substracts previously saved values, then saves current values, so I know 
the hdd activity.
- But sometimes (once in 7 days) I've got too big values for sda (between last 
and current ones) (for example 5GB/second, 19GB/second).
+ But sometimes (once in 7 days) I've got too big values for sda (between last 
and current ones) (for example 5GB/second, 19GB/second, etc...).
  
  sudo lshw -class disk
   *-disk
         description: ATA Disk
         product: SPCC Solid State
         physical id: 0.0.0
         bus info: scsi@2:0.0.0
         logical name: /dev/sda
         version: 08.2
         serial: EB84075517B200427436
         size: 111GiB (120GB)
         capabilities: partitioned partitioned:dos
         configuration: ansiversion=5 logicalsectorsize=512 sectorsize=512 
signature=d01f3b8e
  
  Also I've written the script for monitoring the statistics
  
  #!/bin/bash
  
  while (true) do
   str=`date`" $(cat /sys/block/sda/stat)"
   echo $str >> log.txt
   sleep 10;
  done
  
  And got this values
  
  Fr Jul 28 07:39:38 MSK 2017 2368466 475339 105223134 1362848 5753154 7692148 
661424840 31319540 0 4790052 32687100
  Fr Jul 28 07:39:48 MSK 2017 2368466 475339 105223134 1362848 5753170 7692160 
661425104 31319548 0 4790060 32687108
  Fr Jul 28 07:39:58 MSK 2017 2368466 475339 105223134 1362848 5753174 7692162 
661425152 31319556 0 4790068 32687116
  Fr Jul 28 07:40:08 MSK 2017 2369133 475339 105228750 1363380 5771079 7694395 
706209560 31324696 0 4795572 32692780
  Fr Jul 28 07:40:18 MSK 2017 2369133 475339 105228750 1363380 5771087 7694431 
706209960 31324708 0 4795584 32692792
  Fr Jul 28 07:40:28 MSK 2017 2369133 475339 105228750 1363380 5771091 7694433 
706210008 31324716 0 4795592 32692800
  Fr Jul 28 07:40:38 MSK 2017 2369133 475339 105228750 1363380 5771244 7694714 
706213528 31325052 0 4795604 32693136
  
  You can see that the difference (3,4 lines) is very big between
  706209560 and 661425152, my ssd can read 250 Mb/sec, but not 5 Gb/sec.
  
  Also you can use this program for monitoring (g++ -std=c++14 name.cpp)
  
  #include <iostream>
  #include <fstream>
  #include <regex>
  #include <tuple>
  #include <chrono>
  #include <thread>
  #include <cstdint>
  
  const int HDD_READ_POS     = 2;
  const int HDD_WRITE_POS    = 6;
  const int UNIX_SECTOR_SIZE = 512;
  uint64_t prevRead  = static_cast<uint64_t>(0);
  uint64_t prevWrite = static_cast<uint64_t>(0);
  
  std::tuple<uint64_t, uint64_t> hddStatus(const std::string &name="sda")
  {
      std::ifstream in("/sys/block/"+name+"/stat");
  
      auto readVal_ = static_cast<uint64_t>(0);
      auto writeVal_= static_cast<uint64_t>(0);
  
      if ( ! in.is_open() ) {
          return std::tuple<uint64_t, uint64_t> (readVal_, writeVal_);
      }
  
      std::string line;
      std::regex rgx ( "\\d+" );
      std::regex_token_iterator<std::string::iterator> end;
  
      while (std::getline(in, line) ){
  
          std::regex_token_iterator<std::string::iterator> iter( line.begin(), 
line.end(), rgx, 0 );
          int pos_ = 0 ;
  
          while ( iter != end ) {
  
              if ( pos_ == HDD_READ_POS){
                  readVal_ = std::stoul( *iter ) ;
              }
  
              if ( pos_ == HDD_WRITE_POS){
                  writeVal_ = std::stoul( *iter ) ;
              }
  
              ++iter;
              ++pos_;
          }
      }
  
      return std::tuple<uint64_t, uint64_t> (readVal_, writeVal_);
  
  }
  
  void init()
  {
  
          auto values = hddStatus();
          prevRead  = std::get<0>( values ) * UNIX_SECTOR_SIZE;
          prevWrite = std::get<1>( values ) * UNIX_SECTOR_SIZE;
  
  }
  
  int main(int argc, char const *argv[])
  {
      init();
  
          while(true){
  
              std::ofstream stat("statistics.txt", std::fstream::out | 
std::fstream::app);
              if ( stat.is_open() ){
  
              auto values = hddStatus();
              auto read  = std::get<0>( values ) * UNIX_SECTOR_SIZE;
              auto write = std::get<1>( values ) * UNIX_SECTOR_SIZE;
  
               // stat<<"Current Read: "<< read<<" Write: "<<write<<'\n';
              if (read > prevRead){
                  stat<<"Diff Read: "<< read - prevRead <<'\n';
                  std::cout<<"Diff Read: "<< read - prevRead <<'\n';
              }
  
              if ( write > prevWrite){
                  stat<<"Diff Write: "<<write - prevWrite <<'\n';
                  std::cout<<"Diff Write: "<<write - prevWrite <<'\n';
              }
  
              prevRead  = read;
              prevWrite = write;
  
              std::this_thread::sleep_for(std::chrono::seconds(1));
  
          }
      }
  
      return 0;
  
  }
  
  ProblemType: Bug
  DistroRelease: Ubuntu 16.04
  Package: linux-image-4.10.0-32-generic 4.10.0-32.36~16.04.1
  ProcVersionSignature: Ubuntu 4.10.0-32.36~16.04.1-generic 4.10.17
  Uname: Linux 4.10.0-32-generic x86_64
  ApportVersion: 2.20.1-0ubuntu2.10
  Architecture: amd64
  CurrentDesktop: Unity
  Date: Fri Aug 25 13:43:59 2017
  InstallationDate: Installed on 2017-04-14 (132 days ago)
  InstallationMedia: Ubuntu 16.04.1 LTS "Xenial Xerus" - Release amd64 
(20160719)
  SourcePackage: linux-hwe
  UpgradeStatus: No upgrade log present (probably fresh install)

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1713029

Title:
  Statistics of IO using is incorrect

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux-hwe/+bug/1713029/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to