Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created July 8, 2019 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshavardhana/0aff51f63a63059b3ebbd0c172e40872 to your computer and use it in GitHub Desktop.
Save harshavardhana/0aff51f63a63059b3ebbd0c172e40872 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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