Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nocache
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Danil Mikhailov
nocache
Commits
1afccbcc
Commit
1afccbcc
authored
Feb 05, 2012
by
Julius Plenz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tool "cachestats" to print out the cache map
parent
5e6c065f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
0 deletions
+104
-0
Makefile
Makefile
+1
-0
cachestats.c
cachestats.c
+103
-0
No files found.
Makefile
View file @
1afccbcc
default
:
gcc
-Wall
-o
cachestats cachestats.c
gcc
-Wall
-fPIC
-c
-o
nocache.o nocache.c
gcc
-Wall
-fPIC
-c
-o
fcntl_helpers.o fcntl_helpers.c
gcc
-Wall
-shared
-Wl
,-soname,nocache.so.1
-ldl
-o
nocache.so nocache.o fcntl_helpers.o
cachestats.c
0 → 100644
View file @
1afccbcc
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <error.h>
#include <stdio.h>
int
exiterr
(
const
char
*
s
)
{
perror
(
s
);
exit
(
-
1
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
,
j
;
int
pages
;
int
PAGESIZE
;
int
quiet
=
0
;
int
verbose
=
0
;
int
fd
;
struct
stat
st
;
void
*
file
=
NULL
;
unsigned
char
*
pageinfo
=
NULL
;
PAGESIZE
=
getpagesize
();
if
(
argc
>
1
)
{
if
(
!
strcmp
(
"-v"
,
argv
[
1
]))
verbose
=
1
;
else
if
(
!
strcmp
(
"-q"
,
argv
[
1
]))
quiet
=
1
;
}
else
{
fprintf
(
stderr
,
"usage: %s [-qv] <file> "
"-- print out cache statistics
\n
"
,
argv
[
0
]);
fprintf
(
stderr
,
"
\t
-v
\t
print verbose cache map
\n
"
);
fprintf
(
stderr
,
"
\t
-q
\t
exit code tells if file is fully cached
\n
"
);
exit
(
1
);
}
if
(
quiet
||
verbose
)
argv
++
;
fd
=
open
(
argv
[
1
],
O_RDONLY
);
if
(
fd
==
-
1
)
exiterr
(
"open"
);
if
(
fstat
(
fd
,
&
st
)
==
-
1
)
exiterr
(
"fstat"
);
if
(
!
S_ISREG
(
st
.
st_mode
))
{
fprintf
(
stderr
,
"%s: S_ISREG: not a regular file"
,
argv
[
1
]);
return
EXIT_FAILURE
;
}
if
(
st
.
st_size
==
0
)
{
fprintf
(
stderr
,
"%s: file size is 0!
\n
"
,
argv
[
1
]);
return
EXIT_FAILURE
;
}
pages
=
(
st
.
st_size
+
PAGESIZE
-
1
)
/
PAGESIZE
;
pageinfo
=
calloc
(
sizeof
(
*
pageinfo
),
pages
);
if
(
!
pageinfo
)
exiterr
(
"calloc"
);
file
=
mmap
(
NULL
,
st
.
st_size
,
PROT_NONE
,
MAP_SHARED
,
fd
,
0
);
if
(
file
==
MAP_FAILED
)
exiterr
(
"mmap"
);
if
(
mincore
(
file
,
st
.
st_size
,
pageinfo
)
==
-
1
)
exiterr
(
"mincore"
);
i
=
j
=
0
;
while
(
i
<
pages
)
if
(
pageinfo
[
i
++
]
&
1
)
j
++
;
if
(
quiet
)
{
if
(
j
==
i
)
return
EXIT_SUCCESS
;
return
EXIT_FAILURE
;
}
printf
(
"pages in cache: %d/%d (%.1f%%)
\n
"
,
j
,
i
,
100
.
0
*
j
/
i
);
#define PAGES_PER_LINE 16
if
(
verbose
)
{
printf
(
"
\n
cache map:
\n
"
);
for
(
i
=
0
;
i
<=
(
pages
-
1
)
/
PAGES_PER_LINE
;
i
++
)
{
printf
(
"%6d: |"
,
i
);
for
(
j
=
0
;
j
<
PAGES_PER_LINE
;
j
++
)
{
printf
(
"%c|"
,
pageinfo
[
i
*
PAGES_PER_LINE
+
j
]
&
1
?
'x'
:
' '
);
}
printf
(
"
\n
"
);
}
}
munmap
(
file
,
st
.
st_size
);
return
EXIT_SUCCESS
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment