Skip to content

Commit

Permalink
optimize: add caps json && print more useful data
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgBig committed Dec 12, 2018
1 parent 2879b11 commit 76d1d3f
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 24 deletions.
341 changes: 341 additions & 0 deletions protocol/msg_define.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
{
"NameSpace": "rokid",
"Comment": "collect data define",
"Message": [
{
"MsgName": "ProcCPUInfo",
"Comment": "process cpu usage",
"Fields": [
{
"Name": "pid",
"Type": "uint32",
"Comment": "process id",
"Default": 0
},
{
"Name": "status",
"Type": "string",
"Comment": "process status",
"Default": "sss"
},{
"Name": "full_name",
"Type": "string",
"Comment": "process command line"
},
{
"Name": "utime",
"Type": "int64",
"Comment": "cpu jiffy in user mode"
},
{
"Name": "stime",
"Type": "int64",
"Comment": "cpu jiffy in kernel mode"
},
{
"Name": "ticks",
"Type": "int64",
"Comment": "jiffy summary"
},
{
"Name": "nice",
"Type": "int32",
"Comment": "nice value"
},
{
"Name": "cpu_usage",
"Type": "float",
"Comment": "cpu usage percent"
}
]
},
{
"MsgName": "ProcMemInfo",
"Comment": "process memory info",
"Fields": [
{
"Name": "pid",
"Type": "uint32",
"Comment": "process id"
},
{
"Name": "full_name",
"Type": "string",
"Comment": "process command line"
},
{
"Name": "shared_clean",
"Type": "int64",
"Comment": "shared clean memory"
},
{
"Name": "shared_dirty",
"Type": "int64",
"Comment": "shared dirty memory"
},
{
"Name": "private_clean",
"Type": "int64",
"Comment": "private clean memory"
},
{
"Name": "private_dirty",
"Type": "int64",
"Comment": "private dirty memory"
},
{
"Name": "pss",
"Type": "int64",
"Comment": "proportional set size"
},
{
"Name": "rss",
"Type": "int64",
"Comment": "resident set size"
}
]
},
{
"MsgName": "SysCPUCoreInfo",
"Comment": "cpu core info",
"Fields": [
{
"Name": "usr_usage",
"Type": "float",
"Comment": "jiffy in user mode"
},
{
"Name": "sys_usage",
"Type": "float",
"Comment": "jiffy in kernel mode"
},
{
"Name": "idle_usage",
"Type": "float",
"Comment": "idle percent"
},
{
"Name": "io_usage",
"Type": "float",
"Comment": "iowait percent"
},
{
"Name": "busy_usage",
"Type": "float",
"Comment": "busy percent"
}
]
},
{
"MsgName": "SysCPUInfo",
"Comment": "system cpu info",
"Fields": [
{
"Name": "total",
"Type": "SysCPUCoreInfo",
"Comment": "cpu info"
},
{
"Name": "cores",
"Type": "SysCPUCoreInfo",
"repeated": true,
"Comment": "cpu info per core"
}
]
},
{
"MsgName": "SysMemInfo",
"Comment": "system memory info",
"Fields": [
{
"Name": "total",
"Type": "int64",
"Comment": "total memory"
},
{
"Name": "free",
"Type": "int64",
"Comment": "free memory"
},
{
"Name": "buffers",
"Type": "int64",
"Comment": "buffers memory"
},
{
"Name": "cached",
"Type": "int64",
"Comment": "cached memory"
},
{
"Name": "available",
"Type": "int64",
"Comment": "available memory"
}
]
},
{
"MsgName": "CPUInfos",
"Comment": "cpu info",
"Fields": [
{
"Name": "proc_cpu_list",
"Type": "ProcCPUInfo",
"Repeated": true,
"Comment": "processes cpu infos"
},
{
"Name": "sys_cpu",
"Type": "SysCPUInfo",
"Comment": "system cpu infos"
},
{
"Name": "timestamp",
"Type": "int64",
"Comment": "collect time"
}
]
},
{
"MsgName": "MemInfos",
"Comment": "memory infos",
"Fields": [
{
"Name": "proc_mem_info",
"Type": "ProcMemInfo",
"Repeated": true,
"Comment": "processes memory info"
},
{
"Name": "sys_mem",
"Type": "SysMemInfo",
"Comment": "system memory info"
},
{
"Name": "timestamp",
"Type": "int64",
"Comment": "collect time"
}
]
},
{
"MsgName": "CollectData",
"Comment": "collected data",
"Fields": [
{
"Name": "cpu",
"Type": "CPUInfos",
"Comment": "cpu infos"
},
{
"Name": "mem",
"Type": "MemInfos",
"Comment": "memory infos"
},
{
"Name": "timestamp",
"Type": "int64",
"Comment": "collect time"
}
]
},
{
"MsgName": "TaskCommand",
"Comment": "任务下发(平台->设备)",
"Fields": [
{
"Name": "task_id",
"Type": "int32",
"Comment": "任务id"
},
{
"Name": "task_type",
"Type": "string",
"Comment": "任务类型"
},
{
"Name": "shell_id",
"Type": "uint32",
"Comment": "脚本id"
},
{
"Name": "shell_type",
"Type": "string",
"Comment": "脚本类型"
},
{
"Name": "shell_content",
"Type": "string",
"Comment": "脚本内容"
},
{
"Name": "timestamp",
"Type": "int64",
"Comment": "命令时间"
}
]
},
{
"MsgName": "TaskStatus",
"Comment": "任务状态(设备->平台)",
"Fields": [
{
"Name": "task_id",
"Type": "int32",
"Comment": "设备sn"
},
{
"Name": "status",
"Type": "int32",
"Comment": "任务状态:0-运行中, 1-执行失败, 2-正常结束, 3-准备中"
},
{
"Name": "message",
"Type": "string",
"Comment": "状态描述"
},
{
"Name": "shell_id",
"Type": "int32",
"Comment": "脚本id"
},
{
"Name": "timestamp",
"Type": "int64",
"Comment": "采集时间"
}
]
},
{
"MsgName": "DeviceStatus",
"Comment": "设备状态(设备->平台)",
"Fields": [
{
"Name": "sn",
"Type": "string",
"Comment": "设备sn"
},
{
"Name": "version",
"Type": "string",
"Comment": "设备版本"
},
{
"Name": "status",
"Type": "int32",
"Comment": "设备状态:0-idle,1-exe"
},
{
"Name": "shell_id",
"Type": "int32",
"Comment": "脚本id"
},
{
"Name": "timestamp",
"Type": "int64",
"Comment": "采集时间"
}
]
}
]
}
2 changes: 1 addition & 1 deletion sample/proc/1588/stat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1588 (pulseaudio) S 1 1 1 0 -1 4210944 615 0 434 0 742 618 0 0 9 -11 2 0 875 22171648 1185 4294967tati95 65536 127656 3197902368 3197901520 3065914440 0 0 4096 19011 0 0 0 17 0 0 0 0 0 0 195368 196656 200704 3197902621 3197902717 3197902717 3197902824 0
1588 (pulseaudio) S 1 1 1 0 -1 4210944 615 0 434 0 742 618 0 0 9 10 2 0 875 22171648 1185 4294967tati95 65536 127656 3197902368 3197901520 3065914440 0 0 4096 19011 0 0 0 17 0 0 0 0 0 0 195368 196656 200704 3197902621 3197902717 3197902717 3197902824 0
23 changes: 4 additions & 19 deletions src/executors/busy_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ template<typename T=unsigned long>
T fast_strtoul_10(char **endptr) {
char c;
char *str = *endptr;
auto n = (T) (*str - '0');
T n = *str - '0';

/* Need to stop on both ' ' and '\n' */
while ((c = *++str) > ' ')
Expand Down Expand Up @@ -161,7 +161,7 @@ getProcessTop(const std::string &dir, uint32_t pid) {
stat->stime = fast_strtoul_10(&cp);
stat->ticks = stat->utime + stat->stime;
cp = skip_fields(cp, 3); /* cutime, cstime, priority */
stat->nice = fast_strtoul_10<int32_t>(&cp);
stat->nice = (*cp == '-' ? ++cp, -1 : 1) * fast_strtoul_10(&cp);
cp = skip_fields(cp, 2); /* timeout, it_real_value */
stat->startTime = fast_strtoul_10(&cp);
/* vsz is in bytes and we want kb */
Expand Down Expand Up @@ -368,23 +368,8 @@ std::shared_ptr<SystemTopInfo> getSystemTop(const std::string &dir) {

static int32_t
readCPUJif(FILE *fp, const std::shared_ptr<SystemCPUInfo> &coreJif) {
static const char fmt[] = "cp%*s %"
PRIu64
" %"
PRIu64
" %"
PRIu64 \

" %"
PRIu64
" %"
PRIu64
" %"
PRIu64
" %"
PRIu64
" %"
PRIu64;
static const char fmt[] = "cp%*s %" PRIu64 " %" PRIu64 " %" PRIu64 \
" %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64;

/* not "cpu" */
if (!fgets(line_buf, LINE_BUF_SIZE, fp) || line_buf[0] != 'c') {
Expand Down
Loading

0 comments on commit 76d1d3f

Please sign in to comment.