Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
47eea28f
提交
47eea28f
2月 14, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More print-perf hacking
上级
ee2b2d0f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
171 行增加
和
15 行删除
+171
-15
Makefile
Makefile
+1
-1
print-perf.cc
print-perf.cc
+170
-14
没有找到文件。
Makefile
浏览文件 @
47eea28f
...
...
@@ -23,7 +23,7 @@ OBJCOPY = $(TOOLPREFIX)objcopy
STRIP
=
$(TOOLPREFIX)
strip
COMFLAGS
:=
-static
-fno-builtin
-fno-strict-aliasing
-O2
-Wall
\
-MD
-m64
-Werror
-fms-extensions
-mno-sse
\
-
g
-
MD
-m64
-Werror
-fms-extensions
-mno-sse
\
-mcmodel
=
large
-mno-red-zone
-I
$(QEMUSRC)
-fno-omit-frame-pointer
\
-DHW_
$(HW)
-include
param.h
-include
compiler.h
-DXV6
\
-Wno-gnu-designator
...
...
print-perf.cc
浏览文件 @
47eea28f
#define __STDC_FORMAT_MACROS
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <inttypes.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <map>
#include "types.h"
#include "sampler.h"
#include <unordered_map>
#include <map>
static
void
__attribute__
((
noreturn
))
edie
(
const
char
*
errstr
,
...)
{
va_list
ap
;
va_start
(
ap
,
errstr
);
vfprintf
(
stderr
,
errstr
,
ap
);
va_end
(
ap
);
fprintf
(
stderr
,
": %s
\n
"
,
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
class
Addr2line
{
private
:
int
_out
,
_in
;
public
:
explicit
Addr2line
(
const
char
*
path
);
~
Addr2line
();
int
lookup
(
uint64_t
pc
,
char
**
func
,
char
**
file
,
int
*
line
)
const
;
};
#ifdef __APPLE__
static
char
*
xstrndup
(
const
char
*
str
,
size_t
len
)
{
char
*
r
;
r
=
(
char
*
)
malloc
(
len
+
1
);
if
(
r
==
NULL
)
return
r
;
memcpy
(
r
,
str
,
len
);
r
[
len
]
=
0
;
return
r
;
}
#else
#define xstrndup strndup
#endif
Addr2line
::
Addr2line
(
const
char
*
path
)
{
static
const
char
*
addr2line_exe
[]
=
{
"addr2line"
,
"x86_64-jos-elf-addr2line"
,
};
int
out
[
2
],
in
[
2
],
check
[
2
],
child
,
r
;
if
(
pipe
(
out
)
<
0
||
pipe
(
in
)
<
0
||
pipe
(
check
)
<
0
)
edie
(
"%s: pipe"
,
__func__
);
if
(
fcntl
(
check
[
1
],
F_SETFD
,
fcntl
(
check
[
1
],
F_GETFD
,
0
)
|
FD_CLOEXEC
)
<
0
)
edie
(
"%s: fcntl"
,
__func__
);
child
=
fork
();
if
(
child
<
0
)
{
edie
(
"%s: fork"
,
__func__
);
}
else
if
(
child
==
0
)
{
unsigned
int
i
;
close
(
check
[
0
]);
dup2
(
out
[
0
],
0
);
close
(
out
[
0
]);
close
(
out
[
1
]);
dup2
(
in
[
1
],
1
);
close
(
in
[
0
]);
close
(
in
[
1
]);
for
(
i
=
0
;
i
<
sizeof
(
addr2line_exe
)
/
sizeof
(
addr2line_exe
[
0
]);
i
++
)
r
=
execlp
(
addr2line_exe
[
i
],
addr2line_exe
[
i
],
"-C"
,
"-f"
,
"-e"
,
path
,
NULL
);
r
=
1
;
assert
(
sizeof
(
r
)
==
write
(
check
[
1
],
&
r
,
sizeof
(
r
)));
exit
(
0
);
}
close
(
out
[
0
]);
close
(
in
[
1
]);
close
(
check
[
1
]);
if
(
read
(
check
[
0
],
&
r
,
sizeof
(
r
))
!=
0
)
{
errno
=
r
;
edie
(
"%s: exec"
,
__func__
);
}
close
(
check
[
0
]);
_out
=
out
[
1
];
_in
=
in
[
0
];
}
Addr2line
::~
Addr2line
()
{
close
(
_in
);
close
(
_out
);
}
int
Addr2line
::
lookup
(
uint64_t
pc
,
char
**
func
,
char
**
file
,
int
*
line
)
const
{
char
buf
[
4096
];
int
n
=
snprintf
(
buf
,
sizeof
(
buf
),
"%#"
PRIx64
"
\n
"
,
pc
);
if
(
n
!=
write
(
_out
,
buf
,
n
))
edie
(
"%s: write"
,
__func__
);
n
=
0
;
while
(
1
)
{
int
r
=
read
(
_in
,
buf
+
n
,
sizeof
(
buf
)
-
n
-
1
);
if
(
r
<
0
)
edie
(
"%s: read"
,
__func__
);
n
+=
r
;
buf
[
n
]
=
0
;
int
nls
=
0
;
for
(
int
i
=
0
;
i
<
n
;
++
i
)
if
(
buf
[
i
]
==
'\n'
)
nls
++
;
if
(
nls
>=
2
)
break
;
}
*
func
=
*
file
=
NULL
;
char
*
nl
,
*
col
,
*
end
;
nl
=
strchr
(
buf
,
'\n'
);
*
func
=
xstrndup
(
buf
,
nl
-
buf
);
col
=
strchr
(
nl
,
':'
);
if
(
!
col
)
goto
bad
;
*
file
=
xstrndup
(
nl
+
1
,
col
-
nl
-
1
);
end
=
NULL
;
*
line
=
strtol
(
col
+
1
,
&
end
,
10
);
if
(
!
end
||
*
end
!=
'\n'
)
goto
bad
;
return
0
;
bad
:
free
(
*
func
);
free
(
*
file
);
*
func
=
*
file
=
NULL
;
*
line
=
0
;
return
-
1
;
}
struct
gt
{
...
...
@@ -22,21 +170,27 @@ struct gt
int
main
(
int
ac
,
char
**
av
)
{
static
const
char
*
pathname
=
"sampler"
;
static
const
char
*
sample
;
static
const
char
*
elf
;
struct
logheader
*
header
;
struct
stat
buf
;
char
*
x
;
int
fd
;
int
i
;
if
(
ac
>
1
)
pathname
=
av
[
1
];
if
(
ac
<
3
)
edie
(
"usage: %s sample-file elf-file"
,
av
[
0
]);
sample
=
av
[
1
];
elf
=
av
[
2
];
fd
=
open
(
pathnam
e
,
O_RDONLY
);
fd
=
open
(
sampl
e
,
O_RDONLY
);
if
(
fd
<
0
)
{
perror
(
"open"
);
exit
(
EXIT_FAILURE
);
}
Addr2line
addr2line
(
elf
);
if
(
fstat
(
fd
,
&
buf
)
<
0
)
{
perror
(
"fstat"
);
...
...
@@ -50,12 +204,6 @@ main(int ac, char **av)
}
header
=
(
struct
logheader
*
)
x
;
printf
(
"ncpus %u
\n
"
,
header
->
ncpus
);
for
(
i
=
0
;
i
<
header
->
ncpus
;
i
++
)
{
printf
(
" offset %lu size %lu
\n
"
,
header
->
cpu
[
i
].
offset
,
header
->
cpu
[
i
].
size
);
}
std
::
unordered_map
<
u64
,
int
>
map
;
for
(
i
=
0
;
i
<
header
->
ncpus
;
i
++
)
{
struct
pmuevent
*
p
;
...
...
@@ -76,8 +224,16 @@ main(int ac, char **av)
for
(
std
::
pair
<
const
u64
,
int
>
&
p
:
map
)
sorted
[
p
.
second
]
=
p
.
first
;
for
(
std
::
pair
<
const
int
,
u64
>
&
p
:
sorted
)
printf
(
"%lx %u
\n
"
,
p
.
second
,
p
.
first
);
for
(
std
::
pair
<
const
int
,
u64
>
&
p
:
sorted
)
{
char
*
func
;
char
*
file
;
int
line
;
addr2line
.
lookup
(
p
.
second
,
&
func
,
&
file
,
&
line
);
printf
(
"%-10u %016"
PRIx64
" %s:%u %s
\n
"
,
p
.
first
,
p
.
second
,
file
,
line
,
func
);
free
(
func
);
free
(
file
);
}
return
0
;
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论