github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ios/diskstats_darwin.go (about)

     1  // Package ios is a collection of interfaces to the local storage subsystem;
     2  // the package includes OS-dependent implementations for those interfaces.
     3  /*
     4   * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
     5   */
     6  package ios
     7  
     8  import (
     9  	"github.com/NVIDIA/aistore/cmn/cos"
    10  	"github.com/lufia/iostat"
    11  )
    12  
    13  // Based on:
    14  // - https://www.kernel.org/doc/Documentation/iostats.txt
    15  // - https://www.kernel.org/doc/Documentation/block/stat.txt
    16  type blockStats struct {
    17  	readSectors  int64 // 3 - # of sectors read
    18  	readMs       int64 // 4 - # ms spent reading
    19  	writeSectors int64 // 7 - # of sectors written
    20  	writeMs      int64 // 8 - # of milliseconds spent writing
    21  	ioMs         int64 // 10 - # of milliseconds spent doing I/Os
    22  }
    23  
    24  type allBlockStats map[string]*blockStats
    25  
    26  func readStats(_, _ cos.StrKVs, all allBlockStats) {
    27  	driveStats, err := iostat.ReadDriveStats()
    28  	if err != nil {
    29  		return
    30  	}
    31  	for _, stats := range driveStats {
    32  		ds, ok := all[stats.Name]
    33  		if !ok {
    34  			all[stats.Name] = &blockStats{}
    35  			ds = all[stats.Name]
    36  		}
    37  		*ds = blockStats{
    38  			readSectors:  stats.BytesRead / 512, // HACK
    39  			readMs:       stats.TotalReadTime.Milliseconds(),
    40  			writeSectors: stats.BytesWritten / 512, // ditto
    41  			writeMs:      stats.TotalWriteTime.Milliseconds(),
    42  			ioMs:         stats.TotalReadTime.Milliseconds() + stats.TotalWriteTime.Milliseconds(),
    43  		}
    44  	}
    45  }
    46  
    47  func (*blockStats) Reads() int64         { return 0 } // TODO: not implemented
    48  func (ds *blockStats) ReadBytes() int64  { return ds.readSectors * 512 }
    49  func (*blockStats) Writes() int64        { return 0 } // TODO: not implemented
    50  func (ds *blockStats) WriteBytes() int64 { return ds.writeSectors * 512 }
    51  func (ds *blockStats) IOMs() int64       { return ds.ioMs }
    52  func (ds *blockStats) WriteMs() int64    { return ds.writeMs }
    53  func (ds *blockStats) ReadMs() int64     { return ds.readMs }
    54  
    55  // NVMe multipathing - Linux only
    56  // * nvmeInN:     instance I namespace N
    57  // * nvmeIcCnN:   instance I controller C namespace N
    58  
    59  func icn(string, string) (string, error)  { return "", nil }
    60  func icnPath(string, string, string) bool { return false }