forked from david415/python-ftools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathftools-examples.py
More file actions
executable file
·42 lines (30 loc) · 1.27 KB
/
ftools-examples.py
File metadata and controls
executable file
·42 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
import ftools
import sys
import time
def main():
if len(sys.argv) < 2:
print 'Usage: %s <filename>' % sys.argv[0]
return
pages_cached = 0
pages_total = 0
fd = file(sys.argv[1], 'r')
ftools.fadvise(fd.fileno(),mode="POSIX_FADV_WILLNEED")
print "fadvise POSIX_FADV_WILLNEED"
print "sleeping..."
time.sleep(1)
pages_cached, pages_total = ftools.fincore_ratio(fd.fileno())
print "fincore_ratio: %i of %i pages cached (%.00f%%)" % (pages_cached, pages_total, (float(pages_cached) / float(pages_total)) * 100.0)
ftools.fadvise(fd.fileno(),mode="POSIX_FADV_DONTNEED")
print "fadvise POSIX_FADV_DONTNEED"
pages_cached, pages_total = ftools.fincore_ratio(fd.fileno())
print "fincore_ratio: %i of %i pages cached (%.00f%%)" % (pages_cached, pages_total, (float(pages_cached) / float(pages_total)) * 100.0)
ftools.fadvise(fd.fileno(),mode="POSIX_FADV_WILLNEED")
print "fadvise POSIX_FADV_WILLNEED"
print "sleeping..."
time.sleep(1)
pages_cached, pages_total = ftools.fincore_ratio(fd.fileno())
fd.close()
print "fincore_ratio: %i of %i pages cached (%.00f%%)" % (pages_cached, pages_total, (float(pages_cached) / float(pages_total)) * 100.0)
if __name__ == '__main__':
main()