Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/djherbis/atime"
)
var durations = []time.Duration{
time.Nanosecond,
time.Microsecond,
time.Millisecond,
}
func main() {
var errCounts = make([]int, len(durations))
var succCounts = make([]int, len(durations))
for j := 0; j < 3; j++ {
for i := 1; i <= 100; i++ {
err := checkAtimeSupport("/home/harsha", time.Duration(i)*durations[j])
if err != nil {
errCounts[j]++
} else {
succCounts[j]++
}
}
}
for j := 0; j < 3; j++ {
fmt.Println("Errors:", errCounts[j], "Success:", succCounts[j], "Duration:", durations[j])
}
}
// Return error if Atime is disabled on the O/S
func checkAtimeSupport(dir string, delay time.Duration) (err error) {
file, err := ioutil.TempFile(dir, "prefix")
if err != nil {
return err
}
fname := file.Name()
defer os.Remove(fname)
finfo1, err := os.Stat(fname)
if err != nil {
file.Close()
return err
}
file.Close()
time.Sleep(delay)
if _, err = ioutil.ReadFile(fname); err != nil {
return err
}
finfo2, err := os.Stat(fname)
if atime.Get(finfo2).Equal(atime.Get(finfo1)) {
return errors.New("Atime not supported")
}
return
}
@harshavardhana

This comment has been minimized.

Copy link
Owner Author

commented Jul 8, 2019

Errors: 97 Success: 3 Duration: 1ns
Errors: 97 Success: 3 Duration: 1µs
Errors: 1 Success: 99 Duration: 1ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.