Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-07-27 16:34:08 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7c1dd9751363d7d731ca1371521a0d104afbd1c0
7c1dd975
1 parent
a7a00921
refine system stat, use fgets and sscanf.
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
20 行增加
和
32 行删除
trunk/src/app/srs_app_utility.cpp
trunk/src/app/srs_app_utility.cpp
查看文件 @
7c1dd97
...
...
@@ -393,18 +393,15 @@ bool srs_get_disk_vmstat_stat(SrsDiskStat& r)
r
.
ok
=
false
;
r
.
sample_time
=
srs_get_system_time_ms
();
for
(;;)
{
static
char
label
[
64
];
static
unsigned
long
value
;
int
ret
=
fscanf
(
f
,
"%64s %lu
\n
"
,
label
,
&
value
);
if
(
ret
==
EOF
)
{
break
;
}
if
(
strcmp
(
"pgpgin"
,
label
)
==
0
)
{
static
char
buf
[
1024
];
while
(
fgets
(
buf
,
sizeof
(
buf
),
f
))
{
unsigned
long
value
=
0
;
int
ret
=
sscanf
(
buf
,
"%*s %lu
\n
"
,
&
value
);
srs_assert
(
ret
==
1
);
if
(
strncmp
(
buf
,
"pgpgin "
,
7
)
==
0
)
{
r
.
pgpgin
=
value
;
}
else
if
(
str
cmp
(
"pgpgout"
,
label
)
==
0
)
{
}
else
if
(
str
ncmp
(
buf
,
"pgpgout "
,
8
)
==
0
)
{
r
.
pgpgout
=
value
;
}
}
...
...
@@ -418,8 +415,6 @@ bool srs_get_disk_vmstat_stat(SrsDiskStat& r)
bool
srs_get_disk_diskstats_stat
(
SrsDiskStat
&
r
)
{
// %4d %4d %31s %u
//
FILE
*
f
=
fopen
(
"/proc/diskstats"
,
"r"
);
if
(
f
==
NULL
)
{
srs_warn
(
"open vmstat failed, ignore"
);
...
...
@@ -430,7 +425,6 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
r
.
sample_time
=
srs_get_system_time_ms
();
static
char
buf
[
1024
];
while
(
fgets
(
buf
,
sizeof
(
buf
),
f
))
{
unsigned
int
major
=
0
;
unsigned
int
minor
=
0
;
...
...
@@ -452,11 +446,9 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
&
major
,
&
minor
,
name
,
&
rd_ios
,
&
rd_merges
,
&
rd_sectors
,
&
rd_ticks
,
&
wr_ios
,
&
wr_merges
,
&
wr_sectors
,
&
wr_ticks
,
&
nb_current
,
&
ticks
,
&
aveq
);
srs_assert
(
ret
==
14
);
if
(
ret
==
EOF
)
{
break
;
}
// TODO: FIMXE: config it.
if
(
strcmp
(
"sda"
,
name
)
==
0
)
{
r
.
rd_ios
+=
rd_ios
;
r
.
rd_merges
+=
rd_merges
;
...
...
@@ -541,27 +533,23 @@ void srs_update_meminfo()
SrsMemInfo
&
r
=
_srs_system_meminfo
;
r
.
ok
=
false
;
for
(;;)
{
static
char
label
[
64
];
static
char
buf
[
1024
];
while
(
fgets
(
buf
,
sizeof
(
buf
),
f
))
{
static
unsigned
long
value
;
static
char
postfix
[
64
];
int
ret
=
fscanf
(
f
,
"%64s %lu %64s
\n
"
,
label
,
&
value
,
postfix
);
if
(
ret
==
EOF
)
{
break
;
}
int
ret
=
sscanf
(
buf
,
"%*s %lu"
,
&
value
);
srs_assert
(
ret
==
1
);
if
(
str
cmp
(
"MemTotal:"
,
label
)
==
0
)
{
if
(
str
ncmp
(
buf
,
"MemTotal:"
,
9
)
==
0
)
{
r
.
MemTotal
=
value
;
}
else
if
(
str
cmp
(
"MemFree:"
,
label
)
==
0
)
{
}
else
if
(
str
ncmp
(
buf
,
"MemFree:"
,
8
)
==
0
)
{
r
.
MemFree
=
value
;
}
else
if
(
str
cmp
(
"Buffers:"
,
label
)
==
0
)
{
}
else
if
(
str
ncmp
(
buf
,
"Buffers:"
,
8
)
==
0
)
{
r
.
Buffers
=
value
;
}
else
if
(
str
cmp
(
"Cached:"
,
label
)
==
0
)
{
}
else
if
(
str
ncmp
(
buf
,
"Cached:"
,
7
)
==
0
)
{
r
.
Cached
=
value
;
}
else
if
(
str
cmp
(
"SwapTotal:"
,
label
)
==
0
)
{
}
else
if
(
str
ncmp
(
buf
,
"SwapTotal:"
,
10
)
==
0
)
{
r
.
SwapTotal
=
value
;
}
else
if
(
str
cmp
(
"SwapFree:"
,
label
)
==
0
)
{
}
else
if
(
str
ncmp
(
buf
,
"SwapFree:"
,
9
)
==
0
)
{
r
.
SwapFree
=
value
;
}
}
...
...
请
注册
或
登录
后发表评论