Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
c01b7d28
提交
c01b7d28
2月 13, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a stat member to devsw and a sampstat function
上级
1258b4c3
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
38 行增加
和
39 行删除
+38
-39
file.hh
file.hh
+1
-0
fs.cc
fs.cc
+8
-0
perf.cc
perf.cc
+0
-31
print-perf.c
print-perf.c
+1
-1
sampler.cc
sampler.cc
+28
-7
没有找到文件。
file.hh
浏览文件 @
c01b7d28
...
...
@@ -53,6 +53,7 @@ struct inode : public rcu_freed {
struct
devsw
{
int
(
*
read
)(
struct
inode
*
,
char
*
,
u32
,
u32
);
int
(
*
write
)(
struct
inode
*
,
char
*
,
u32
,
u32
);
void
(
*
stat
)(
struct
inode
*
,
struct
stat
*
);
};
extern
struct
devsw
devsw
[];
...
...
fs.cc
浏览文件 @
c01b7d28
...
...
@@ -529,6 +529,14 @@ itrunc(struct inode *ip)
void
stati
(
struct
inode
*
ip
,
struct
stat
*
st
)
{
if
(
ip
->
type
==
T_DEV
){
if
(
ip
->
major
<
0
||
ip
->
major
>=
NDEV
||
!
devsw
[
ip
->
major
].
stat
)
memset
(
st
,
0
,
sizeof
(
*
st
));
else
devsw
[
ip
->
major
].
stat
(
ip
,
st
);
return
;
}
st
->
dev
=
ip
->
dev
;
st
->
ino
=
ip
->
inum
;
st
->
type
=
ip
->
type
;
...
...
perf.cc
浏览文件 @
c01b7d28
...
...
@@ -29,36 +29,6 @@ conf(int fd, sampop_t op)
close
(
fd
);
}
static
void
save
(
void
)
{
static
char
buf
[
4096
];
int
fd
,
sfd
;
int
r
;
fd
=
open
(
"/dev/sampler"
,
O_RDONLY
);
if
(
fd
<
0
)
die
(
"perf: open failed"
);
unlink
(
"perf.data"
);
sfd
=
open
(
"perf.data"
,
O_RDWR
|
O_CREATE
);
if
(
sfd
<
0
)
die
(
"perf: open failed"
);
while
(
1
)
{
r
=
read
(
fd
,
buf
,
sizeof
(
buf
));
if
(
r
<
0
)
die
(
"perf: read failed"
);
if
(
r
==
0
)
break
;
if
(
write
(
sfd
,
buf
,
r
)
!=
r
)
die
(
"perf: truncated write"
);
}
close
(
sfd
);
close
(
fd
);
}
int
main
(
int
ac
,
const
char
*
av
[])
{
...
...
@@ -78,6 +48,5 @@ main(int ac, const char *av[])
wait
();
conf
(
fd
,
SAMP_DISABLE
);
save
();
exit
();
}
print-perf.c
浏览文件 @
c01b7d28
...
...
@@ -11,7 +11,7 @@
int
main
(
int
ac
,
char
**
av
)
{
static
const
char
*
pathname
=
"
perf.data
"
;
static
const
char
*
pathname
=
"
sampler
"
;
struct
logheader
*
header
;
struct
stat
buf
;
void
*
x
;
...
...
sampler.cc
浏览文件 @
c01b7d28
...
...
@@ -4,6 +4,7 @@ extern "C" {
#include "condvar.h"
#include "fs.h"
#include "kernel.h"
#include "stat.h"
}
#include "file.hh"
...
...
@@ -15,6 +16,9 @@ extern "C" {
#include "sampler.h"
}
#define LOGHEADER_SZ (sizeof(struct logheader) + \
sizeof(((struct logheader*)0)->cpu[0])*NCPU)
static
volatile
u64
selector
;
static
volatile
u64
period
;
...
...
@@ -153,20 +157,36 @@ readlog(char *dst, u32 off, u32 n)
return
ret
;
}
static
void
sampstat
(
struct
inode
*
ip
,
struct
stat
*
st
)
{
struct
pmulog
*
q
=
&
pmulog
[
NCPU
];
struct
pmulog
*
p
;
u64
sz
=
0
;
sz
+=
LOGHEADER_SZ
;
for
(
p
=
&
pmulog
[
0
];
p
!=
q
;
p
++
)
sz
+=
p
->
count
*
sizeof
(
struct
pmuevent
);
st
->
dev
=
ip
->
dev
;
st
->
ino
=
ip
->
inum
;
st
->
type
=
ip
->
type
;
st
->
nlink
=
ip
->
nlink
;
st
->
size
=
sz
;
}
static
int
sampread
(
struct
inode
*
ip
,
char
*
dst
,
u32
off
,
u32
n
)
{
struct
pmulog
*
q
=
&
pmulog
[
NCPU
];
struct
pmulog
*
p
;
struct
logheader
*
hdr
;
u64
hdrlen
;
int
ret
;
int
i
;
ret
=
0
;
hdrlen
=
sizeof
(
*
hdr
)
+
sizeof
(
hdr
->
cpu
[
0
])
*
NCPU
;
if
(
off
<
hdrlen
)
{
u64
len
=
hdrlen
;
if
(
off
<
LOGHEADER_SZ
)
{
u64
len
=
LOGHEADER_SZ
;
u64
cc
;
hdr
=
(
logheader
*
)
kmalloc
(
len
);
...
...
@@ -182,7 +202,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
i
++
;
}
cc
=
MIN
(
hdrlen
-
off
,
n
);
cc
=
MIN
(
LOGHEADER_SZ
-
off
,
n
);
memmove
(
dst
,
(
char
*
)
hdr
+
off
,
cc
);
kmfree
(
hdr
);
...
...
@@ -192,8 +212,8 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
dst
+=
cc
;
}
if
(
off
>=
hdrlen
)
ret
+=
readlog
(
dst
,
off
-
hdrlen
,
n
);
if
(
off
>=
LOGHEADER_SZ
)
ret
+=
readlog
(
dst
,
off
-
LOGHEADER_SZ
,
n
);
return
ret
;
}
...
...
@@ -257,4 +277,5 @@ initsamp(void)
devsw
[
SAMPLER
].
write
=
sampwrite
;
devsw
[
SAMPLER
].
read
=
sampread
;
devsw
[
SAMPLER
].
stat
=
sampstat
;
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论