Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Achou.Wang
accel-ppp
提交
88db6241
A
accel-ppp
项目概览
Achou.Wang
/
accel-ppp
通知
6
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
accel-ppp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
88db6241
编写于
12月 24, 2010
作者:
D
Dmitry Kozlov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cli: show cpu and memory utilization in statistics
上级
59f69179
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
88 addition
and
12 deletion
+88
-12
accel-pptpd/cli/std_cmd.c
accel-pptpd/cli/std_cmd.c
+13
-0
accel-pptpd/cli/telnet.c
accel-pptpd/cli/telnet.c
+3
-0
accel-pptpd/memdebug.c
accel-pptpd/memdebug.c
+5
-5
accel-pptpd/triton/md.c
accel-pptpd/triton/md.c
+1
-1
accel-pptpd/triton/timer.c
accel-pptpd/triton/timer.c
+1
-1
accel-pptpd/triton/triton.c
accel-pptpd/triton/triton.c
+59
-4
accel-pptpd/triton/triton.h
accel-pptpd/triton/triton.h
+5
-0
accel-pptpd/triton/triton_p.h
accel-pptpd/triton/triton_p.h
+1
-1
未找到文件。
accel-pptpd/cli/std_cmd.c
浏览文件 @
88db6241
...
...
@@ -16,6 +16,17 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
{
time_t
dt
;
int
day
,
hour
;
char
statm_fname
[
128
];
FILE
*
f
;
unsigned
long
vmsize
=
0
,
vmrss
=
0
;
unsigned
long
page_size_kb
=
sysconf
(
_SC_PAGE_SIZE
)
/
1024
;
sprintf
(
statm_fname
,
"/proc/%i/statm"
,
getpid
());
f
=
fopen
(
statm_fname
,
"r"
);
if
(
f
)
{
fscanf
(
f
,
"%lu %lu"
,
&
vmsize
,
&
vmrss
);
fclose
(
f
);
}
time
(
&
dt
);
dt
-=
triton_stat
.
start_time
;
...
...
@@ -25,6 +36,8 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
dt
%=
60
*
60
;
cli_sendv
(
client
,
"uptime: %i.%02i:%02i:%02i
\r\n
"
,
day
,
hour
,
dt
/
60
,
dt
%
60
);
cli_sendv
(
client
,
"cpu: %i%% (%i/%i)
\r\n
"
,
triton_stat
.
ru_utime
+
triton_stat
.
ru_stime
,
triton_stat
.
ru_utime
,
triton_stat
.
ru_stime
);
cli_sendv
(
client
,
"mem: %lu/%lu kB
\r\n
"
,
vmrss
/
page_size_kb
,
vmsize
/
page_size_kb
);
cli_send
(
client
,
"core:
\r\n
"
);
cli_sendv
(
client
,
" mempool_allocated: %u
\r\n
"
,
triton_stat
.
mempool_allocated
);
cli_sendv
(
client
,
" mempool_available: %u
\r\n
"
,
triton_stat
.
mempool_available
);
...
...
accel-pptpd/cli/telnet.c
浏览文件 @
88db6241
...
...
@@ -69,6 +69,8 @@ static void disconnect(struct telnet_client_t *cln)
log_debug
(
"cli: disconnect
\n
"
);
triton_stop_collect_cpu_usage
();
list_del
(
&
cln
->
entry
);
triton_md_unregister_handler
(
&
cln
->
hnd
);
...
...
@@ -567,6 +569,7 @@ static int serv_read(struct triton_md_handler_t *h)
conn
->
auth
=
1
;
send_prompt
(
conn
);
}
triton_collect_cpu_usage
();
}
return
0
;
}
...
...
accel-pptpd/memdebug.c
浏览文件 @
88db6241
...
...
@@ -80,7 +80,7 @@ void __export md_free(void *ptr, const char *fname, int line)
}
if
(
mem
->
magic2
!=
*
(
uint64_t
*
)(
mem
->
data
+
mem
->
size
))
{
printf
(
"memory corruption:
\n
malloc(%lu) at %s:%i
\n
free at %s:%i
\n
"
,
mem
->
size
,
mem
->
fname
,
mem
->
line
,
fname
,
line
);
printf
(
"memory corruption:
\n
malloc(%lu) at %s:%i
\n
free at %s:%i
\n
"
,
(
long
unsigned
)
mem
->
size
,
mem
->
fname
,
mem
->
line
,
fname
,
line
);
abort
();
}
...
...
@@ -106,7 +106,7 @@ void __export *md_realloc(void *ptr, size_t size, const char *fname, int line)
}
if
(
mem
->
magic2
!=
*
(
uint64_t
*
)(
mem
->
data
+
mem
->
size
))
{
printf
(
"memory corruption:
\n
malloc(%lu) at %s:%i
\n
free at %s:%i
\n
"
,
mem
->
size
,
mem
->
fname
,
mem
->
line
,
fname
,
line
);
printf
(
"memory corruption:
\n
malloc(%lu) at %s:%i
\n
free at %s:%i
\n
"
,
(
long
unsigned
)
mem
->
size
,
mem
->
fname
,
mem
->
line
,
fname
,
line
);
abort
();
}
...
...
@@ -140,11 +140,11 @@ static void siginfo(int num)
spin_lock
(
&
mem_list_lock
);
list_for_each_entry
(
mem
,
&
mem_list
,
entry
)
{
printf
(
"%s:%i %lu
\n
"
,
mem
->
fname
,
mem
->
line
,
mem
->
size
);
printf
(
"%s:%i %lu
\n
"
,
mem
->
fname
,
mem
->
line
,
(
long
unsigned
)
mem
->
size
);
total
+=
mem
->
size
;
}
spin_unlock
(
&
mem_list_lock
);
printf
(
"total = %lu
\n
"
,
total
);
printf
(
"total = %lu
\n
"
,
(
long
unsigned
)
total
);
}
static
void
siginfo2
(
int
num
)
...
...
@@ -154,7 +154,7 @@ static void siginfo2(int num)
spin_lock
(
&
mem_list_lock
);
list_for_each_entry
(
mem
,
&
mem_list
,
entry
)
{
if
(
mem
->
magic1
!=
MAGIC1
||
mem
->
magic2
!=
*
(
uint64_t
*
)(
mem
->
data
+
mem
->
size
))
printf
(
"%s:%i %lu
\n
"
,
mem
->
fname
,
mem
->
line
,
mem
->
size
);
printf
(
"%s:%i %lu
\n
"
,
mem
->
fname
,
mem
->
line
,
(
long
unsigned
)
mem
->
size
);
}
spin_unlock
(
&
mem_list_lock
);
}
...
...
accel-pptpd/triton/md.c
浏览文件 @
88db6241
...
...
@@ -124,7 +124,7 @@ void __export triton_md_register_handler(struct triton_context_t *ctx, struct tr
if
(
ctx
)
h
->
ctx
=
(
struct
_triton_context_t
*
)
ctx
->
tpd
;
else
h
->
ctx
=
(
struct
_triton_context_t
*
)
default_ctx
->
tpd
;
h
->
ctx
=
(
struct
_triton_context_t
*
)
default_ctx
.
tpd
;
ud
->
tpd
=
h
;
spin_lock
(
&
h
->
ctx
->
lock
);
list_add_tail
(
&
h
->
entry
,
&
h
->
ctx
->
handlers
);
...
...
accel-pptpd/triton/timer.c
浏览文件 @
88db6241
...
...
@@ -133,7 +133,7 @@ int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_
if
(
ctx
)
t
->
ctx
=
(
struct
_triton_context_t
*
)
ctx
->
tpd
;
else
t
->
ctx
=
(
struct
_triton_context_t
*
)
default_ctx
->
tpd
;
t
->
ctx
=
(
struct
_triton_context_t
*
)
default_ctx
.
tpd
;
t
->
fd
=
timerfd_create
(
CLOCK_MONOTONIC
,
0
);
if
(
t
->
fd
<
0
)
{
triton_log_error
(
"timer:timerfd_create: %s"
,
strerror
(
errno
));
...
...
accel-pptpd/triton/triton.c
浏览文件 @
88db6241
...
...
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/resource.h>
#include "triton_p.h"
#include "memdebug.h"
...
...
@@ -27,7 +28,18 @@ static mempool_t *ctx_pool;
static
mempool_t
*
call_pool
;
static
mempool_t
*
ctx_stack_pool
;
__export
struct
triton_stat_t
triton_stat
;
struct
triton_stat_t
__export
triton_stat
;
static
struct
timeval
ru_utime
;
static
struct
timeval
ru_stime
;
static
struct
timespec
ru_timestamp
;
static
int
ru_refs
;
static
void
ru_update
(
struct
triton_timer_t
*
);
static
struct
triton_timer_t
ru_timer
=
{
.
period
=
1000
,
.
expire
=
ru_update
,
};
struct
triton_context_t
default_ctx
;
#define log_debug2(fmt, ...)
...
...
@@ -325,11 +337,12 @@ void __export triton_context_unregister(struct triton_context_t *ud)
ctx
->
need_free
=
1
;
spin_lock
(
&
ctx_list_lock
);
list_del
(
&
ctx
->
entry
);
if
(
need_terminate
&&
list_empty
(
&
ctx_list
))
terminate
=
1
;
if
(
__sync_sub_and_fetch
(
&
triton_stat
.
context_count
,
1
)
==
1
)
{
if
(
need_terminate
)
terminate
=
1
;
}
spin_unlock
(
&
ctx_list_lock
);
__sync_sub_and_fetch
(
&
triton_stat
.
context_count
,
1
);
if
(
terminate
)
{
list_for_each_entry
(
t
,
&
threads
,
entry
)
...
...
@@ -438,6 +451,45 @@ void __export triton_cancel_call(struct triton_context_t *ud, void (*func)(void
}
}
void
__export
triton_collect_cpu_usage
(
void
)
{
struct
rusage
rusage
;
if
(
__sync_fetch_and_add
(
&
ru_refs
,
1
)
==
0
)
{
triton_timer_add
(
NULL
,
&
ru_timer
,
0
);
getrusage
(
RUSAGE_SELF
,
&
rusage
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
ru_timestamp
);
ru_utime
=
rusage
.
ru_utime
;
ru_stime
=
rusage
.
ru_stime
;
triton_stat
.
ru_utime
=
0
;
triton_stat
.
ru_stime
=
0
;
}
}
void
__export
triton_stop_collect_cpu_usage
(
void
)
{
if
(
__sync_sub_and_fetch
(
&
ru_refs
,
1
)
==
0
)
triton_timer_del
(
&
ru_timer
);
}
static
void
ru_update
(
struct
triton_timer_t
*
t
)
{
struct
timespec
ts
;
struct
rusage
rusage
;
unsigned
int
dt
;
getrusage
(
RUSAGE_SELF
,
&
rusage
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
dt
=
(
ts
.
tv_sec
-
ru_timestamp
.
tv_sec
)
*
1000000
+
(
ts
.
tv_nsec
-
ru_timestamp
.
tv_nsec
)
/
1000000
;
triton_stat
.
ru_utime
=
(
double
)((
rusage
.
ru_utime
.
tv_sec
-
ru_utime
.
tv_sec
)
*
1000000
+
(
rusage
.
ru_utime
.
tv_usec
-
ru_utime
.
tv_usec
))
/
dt
*
100
;
triton_stat
.
ru_stime
=
(
double
)((
rusage
.
ru_stime
.
tv_sec
-
ru_stime
.
tv_sec
)
*
1000000
+
(
rusage
.
ru_stime
.
tv_usec
-
ru_stime
.
tv_usec
))
/
dt
*
100
;
ru_timestamp
=
ts
;
ru_utime
=
rusage
.
ru_utime
;
ru_stime
=
rusage
.
ru_stime
;
}
int
__export
triton_init
(
const
char
*
conf_file
)
{
ctx_pool
=
mempool_create2
(
sizeof
(
struct
_triton_context_t
));
...
...
@@ -492,6 +544,9 @@ void __export triton_run()
md_run
();
timer_run
();
triton_context_register
(
&
default_ctx
,
NULL
);
triton_context_wakeup
(
&
default_ctx
);
}
void
__export
triton_terminate
()
...
...
accel-pptpd/triton/triton.h
浏览文件 @
88db6241
...
...
@@ -64,6 +64,8 @@ struct triton_stat_t
unsigned
int
timer_count
;
unsigned
int
timer_pending
;
time_t
start_time
;
int
ru_utime
;
int
ru_stime
;
};
extern
struct
triton_stat_t
triton_stat
;
...
...
@@ -98,6 +100,9 @@ void triton_event_fire(int ev_id, void *arg);
struct
conf_sect_t
*
conf_get_section
(
const
char
*
name
);
char
*
conf_get_opt
(
const
char
*
sect
,
const
char
*
name
);
void
triton_collect_cpu_usage
(
void
);
void
triton_stop_collect_cpu_usage
(
void
);
#define TRITON_OK 0
#define TRITON_ERR_NOCOMP -1
#define TRITON_ERR_NOSUPP -2
...
...
accel-pptpd/triton/triton_p.h
浏览文件 @
88db6241
...
...
@@ -95,7 +95,7 @@ void md_run();
void
md_terminate
();
void
timer_run
();
void
timer_terminate
();
struct
triton_context_t
*
default_ctx
;
extern
struct
triton_context_t
default_ctx
;
int
triton_queue_ctx
(
struct
_triton_context_t
*
);
void
triton_thread_wakeup
(
struct
_triton_thread_t
*
);
int
conf_load
(
const
char
*
fname
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录