summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-06-02 16:24:49 +0300
committerYaroslav Brustinov <ybrustin@cisco.com>2016-06-02 16:24:49 +0300
commit300ec24108211721d99ac9faf67fd1f91057b95b (patch)
treed6cc791b36826be18033041a9f9a29845fa55b03 /src
parent84fc182fd1021b0ad564478f284afff660a5b924 (diff)
cpu utilization per thread + mbufs per socket + add in tui
Diffstat (limited to 'src')
-rwxr-xr-xsrc/bp_sim.cpp67
-rwxr-xr-xsrc/bp_sim.h10
-rw-r--r--src/internal_api/trex_platform_api.h4
-rw-r--r--src/main_dpdk.cpp21
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp13
-rw-r--r--src/rpc-server/commands/trex_rpc_cmds.h2
-rw-r--r--src/rpc-server/trex_rpc_cmds_table.cpp2
-rw-r--r--src/trex_defs.h2
-rwxr-xr-xsrc/utl_cpuu.cpp34
-rwxr-xr-xsrc/utl_cpuu.h15
10 files changed, 81 insertions, 89 deletions
diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp
index 27a79268..be9de21e 100755
--- a/src/bp_sim.cpp
+++ b/src/bp_sim.cpp
@@ -496,39 +496,24 @@ void CRteMemPool::dump_in_case_of_error(FILE *fd){
dump(fd);
}
-std::string CRteMemPool::add_to_json(
- std::string name,
- rte_mempool_t * pool,
- bool last){
+void CRteMemPool::add_to_json(Json::Value &json, std::string name, rte_mempool_t * pool){
uint32_t p_free = rte_mempool_count(pool);
uint32_t p_size = pool->size;
- char buff[200];
- sprintf(buff,"\"%s\":[%llu,%llu]",name.c_str(),(unsigned long long)p_free,(unsigned long long)p_size);
- std::string json = std::string(buff) + (last?std::string(""):std::string(","));
- return (json);
+ json[name].append((unsigned long long)p_free);
+ json[name].append((unsigned long long)p_size);
}
-std::string CRteMemPool::dump_as_json(uint8_t id,bool last){
-
- char buff[200];
- sprintf(buff,"\"socket-%d\":{", (int)id);
-
- std::string json=std::string(buff);
-
- json+=add_to_json("64b",m_small_mbuf_pool);
- json+=add_to_json("128b",m_mbuf_pool_128);
- json+=add_to_json("256b",m_mbuf_pool_256);
- json+=add_to_json("512b",m_mbuf_pool_512);
- json+=add_to_json("1024b",m_mbuf_pool_1024);
- json+=add_to_json("2048b",m_mbuf_pool_2048);
- json+=add_to_json("4096b",m_mbuf_pool_4096);
- json+=add_to_json("9kb",m_mbuf_pool_9k,true);
-
- json+="}" ;
- if (last==false) {
- json+="," ;
- }
+Json::Value CRteMemPool::dump_as_json(){
+ Json::Value json;
+ add_to_json(json, "64b", m_small_mbuf_pool);
+ add_to_json(json, "128b", m_mbuf_pool_128);
+ add_to_json(json, "256b", m_mbuf_pool_256);
+ add_to_json(json, "512b", m_mbuf_pool_512);
+ add_to_json(json, "1024b", m_mbuf_pool_1024);
+ add_to_json(json, "2048b", m_mbuf_pool_2048);
+ add_to_json(json, "4096b", m_mbuf_pool_4096);
+ add_to_json(json, "9kb", m_mbuf_pool_9k);
return (json);
}
@@ -546,32 +531,26 @@ void CRteMemPool::dump(FILE *fd){
DUMP_MBUF("mbuf_9k",m_mbuf_pool_9k);
}
-////////////////////////////////////////
+////////////////////////////////////////
-std::string CGlobalInfo::dump_pool_as_json(void){
-
- std::string json="\"mbuf_stats\":{";
+Json::Value CGlobalInfo::dump_pool_as_json(void){
+ Json::Value json;
CPlatformSocketInfo * lpSocket =&m_socket;
- int last_socket=-1;
- /* calc the last socket */
- int i;
- for (i=0; i<(int)MAX_SOCKETS_SUPPORTED; i++) {
+ for (int i=0; i<(int)MAX_SOCKETS_SUPPORTED; i++) {
if (lpSocket->is_sockets_enable((socket_id_t)i)) {
- last_socket=i;
+ std::string socket_id = "cpu-socket-" + std::to_string(i);
+ json["mbuf_stats"][socket_id] = m_mem_pool[i].dump_as_json();
}
}
-
- for (i=0; i<(int)MAX_SOCKETS_SUPPORTED; i++) {
- if (lpSocket->is_sockets_enable((socket_id_t)i)) {
- json+=m_mem_pool[i].dump_as_json(i,last_socket==i?true:false);
- }
- }
- json+="},";
return json;
}
+std::string CGlobalInfo::dump_pool_as_json_str(void){
+ return ("\"mbuf_stats\":" + dump_pool_as_json().toStyledString() + ",");
+}
+
void CGlobalInfo::free_pools(){
CPlatformSocketInfo * lpSocket =&m_socket;
CRteMemPool * lpmem;
diff --git a/src/bp_sim.h b/src/bp_sim.h
index 7b4dfdd5..8aead5f1 100755
--- a/src/bp_sim.h
+++ b/src/bp_sim.h
@@ -1149,13 +1149,10 @@ public:
void dump_in_case_of_error(FILE *fd);
- std::string dump_as_json(uint8_t id,bool last);
+ Json::Value dump_as_json();
private:
- std::string add_to_json(std::string name,
- rte_mempool_t * pool,
- bool last=false);
-
+ void add_to_json(Json::Value &json, std::string name, rte_mempool_t * pool);
public:
rte_mempool_t * m_small_mbuf_pool; /* pool for start packets */
@@ -1249,7 +1246,8 @@ public:
}
- static std::string dump_pool_as_json(void);
+ static Json::Value dump_pool_as_json(void);
+ static std::string dump_pool_as_json_str(void);
public:
diff --git a/src/internal_api/trex_platform_api.h b/src/internal_api/trex_platform_api.h
index ca37b0da..b0294883 100644
--- a/src/internal_api/trex_platform_api.h
+++ b/src/internal_api/trex_platform_api.h
@@ -28,6 +28,7 @@ limitations under the License.
#include <string.h>
#include "flow_stat_parser.h"
#include "trex_defs.h"
+#include <json/json.h>
/**
* Global stats
@@ -157,6 +158,7 @@ public:
virtual void flush_dp_messages() const = 0;
virtual int get_active_pgids(flow_stat_active_t &result) const = 0;
virtual int get_cpu_util_full(cpu_util_full_t &result) const = 0;
+ virtual int get_mbuf_util(Json::Value &result) const = 0;
virtual CFlowStatParser *get_flow_stat_parser() const = 0;
virtual ~TrexPlatformApi() {}
};
@@ -190,6 +192,7 @@ public:
void flush_dp_messages() const;
int get_active_pgids(flow_stat_active_t &result) const;
int get_cpu_util_full(cpu_util_full_t &result) const;
+ int get_mbuf_util(Json::Value &result) const;
CFlowStatParser *get_flow_stat_parser() const;
};
@@ -255,6 +258,7 @@ public:
}
int get_active_pgids(flow_stat_active_t &result) const {return 0;}
int get_cpu_util_full(cpu_util_full_t &result) const {return 0;}
+ int get_mbuf_util(Json::Value &result) const {return 0;}
CFlowStatParser *get_flow_stat_parser() const {return new CFlowStatParser();}
private:
diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp
index ff4b2b6a..94679d72 100644
--- a/src/main_dpdk.cpp
+++ b/src/main_dpdk.cpp
@@ -2427,7 +2427,7 @@ public:
public:
void Dump(FILE *fd,DumpFormat mode);
void DumpAllPorts(FILE *fd);
- void dump_json(std::string & json, bool baseline,uint32_t stats_tick);
+ void dump_json(std::string & json, bool baseline);
private:
std::string get_field(std::string name,float &f);
std::string get_field(std::string name,uint64_t &f);
@@ -2467,7 +2467,7 @@ std::string CGlobalStats::get_field_port(int port,std::string name,uint64_t &f){
}
-void CGlobalStats::dump_json(std::string & json, bool baseline,uint32_t stats_tick){
+void CGlobalStats::dump_json(std::string & json, bool baseline){
/* refactor this to JSON */
json="{\"name\":\"trex-global\",\"type\":0,";
@@ -2535,10 +2535,6 @@ void CGlobalStats::dump_json(std::string & json, bool baseline,uint32_t stats_ti
json+=GET_FIELD_PORT(i,m_total_rx_pps);
}
json+=m_template.dump_as_json("template");
- if ( stats_tick %4==0){
- json+=CGlobalInfo::dump_pool_as_json(); /* no need a feq update beacuse it trash the cores D cache, once in 2 sec */
- }
-
json+="\"unknown\":0}}" ;
}
@@ -3776,7 +3772,7 @@ CGlobalTRex::publish_async_data(bool sync_now, bool baseline) {
get_stats(m_stats);
}
- m_stats.dump_json(json, baseline,m_stats_cnt);
+ m_stats.dump_json(json, baseline);
m_zmq_publisher.publish_json(json);
/* generator json , all cores are the same just sample the first one */
@@ -3869,7 +3865,7 @@ CGlobalTRex::handle_slow_path(bool &was_stopped) {
if (m_io_modes.m_g_mode == CTrexGlobalIoMode::gMem) {
if ( m_stats_cnt%4==0) {
- fprintf (stdout," %s \n",CGlobalInfo::dump_pool_as_json().c_str());
+ fprintf (stdout," %s \n",CGlobalInfo::dump_pool_as_json_str().c_str());
}
}
@@ -5707,13 +5703,18 @@ int TrexDpdkPlatformApi::get_active_pgids(flow_stat_active_t &result) const {
}
int TrexDpdkPlatformApi::get_cpu_util_full(cpu_util_full_t &cpu_util_full) const {
- for (int i=0; i<(int)g_trex.m_fl.m_threads_info.size(); i++) {
- CFlowGenListPerThread * lp=g_trex.m_fl.m_threads_info[i];
+ for (int thread_id=0; thread_id<(int)g_trex.m_fl.m_threads_info.size(); thread_id++) {
+ CFlowGenListPerThread * lp=g_trex.m_fl.m_threads_info[thread_id];
cpu_util_full.push_back(lp->m_cpu_cp_u.GetHistory());
}
return 0;
}
+int TrexDpdkPlatformApi::get_mbuf_util(Json::Value &mbuf_pool) const {
+ mbuf_pool = CGlobalInfo::dump_pool_as_json();
+ return 0;
+}
+
CFlowStatParser *TrexDpdkPlatformApi::get_flow_stat_parser() const {
return CTRexExtendedDriverDb::Ins()->get_drv()->get_flow_stat_parser();
}
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index 541ff099..37eafef8 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -156,22 +156,23 @@ TrexRpcCmdGetActivePGIds::_run(const Json::Value &params, Json::Value &result) {
return (TREX_RPC_CMD_OK);
}
-/*
- Get cpu utilization per thread with up to 20 latest values, Latest value will be first in array.
- */
+
+// get utilization of CPU per thread with up to 20 latest values + mbufs per socket
trex_rpc_cmd_rc_e
-TrexRpcCmdGetCpuUtilFull::_run(const Json::Value &params, Json::Value &result) {
+TrexRpcCmdGetUtilization::_run(const Json::Value &params, Json::Value &result) {
cpu_util_full_t cpu_util_full;
Json::Value &section = result["result"];
- section = Json::arrayValue;
+
+ if (get_stateless_obj()->get_platform_api()->get_mbuf_util(section) != 0)
+ return TREX_RPC_CMD_INTERNAL_ERR;
if (get_stateless_obj()->get_platform_api()->get_cpu_util_full(cpu_util_full) != 0)
return TREX_RPC_CMD_INTERNAL_ERR;
for (int thread_id = 0; thread_id < cpu_util_full.size(); thread_id++) {
for (int history_id = 0; history_id < cpu_util_full[thread_id].size(); history_id++) {
- section[thread_id].append(cpu_util_full.at(thread_id).at(history_id));
+ section["cpu"][thread_id].append(cpu_util_full.at(thread_id).at(history_id));
}
}
return (TREX_RPC_CMD_OK);
diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h
index 0df9fd2b..2776727d 100644
--- a/src/rpc-server/commands/trex_rpc_cmds.h
+++ b/src/rpc-server/commands/trex_rpc_cmds.h
@@ -67,7 +67,7 @@ TREX_RPC_CMD_DEFINE(TrexRpcPublishNow, "publish_now", 2, false,
TREX_RPC_CMD_DEFINE(TrexRpcCmdGetCmds, "get_supported_cmds", 0, false, APIClass::API_CLASS_TYPE_CORE);
TREX_RPC_CMD_DEFINE(TrexRpcCmdGetVersion, "get_version", 0, false, APIClass::API_CLASS_TYPE_CORE);
TREX_RPC_CMD_DEFINE(TrexRpcCmdGetActivePGIds, "get_active_pgids", 0, false, APIClass::API_CLASS_TYPE_CORE);
-TREX_RPC_CMD_DEFINE(TrexRpcCmdGetCpuUtilFull, "get_cpu_util_full", 0, false, APIClass::API_CLASS_TYPE_CORE);
+TREX_RPC_CMD_DEFINE(TrexRpcCmdGetUtilization, "get_utilization", 0, false, APIClass::API_CLASS_TYPE_CORE);
TREX_RPC_CMD_DEFINE_EXTENDED(TrexRpcCmdGetSysInfo, "get_system_info", 0, false, APIClass::API_CLASS_TYPE_CORE,
diff --git a/src/rpc-server/trex_rpc_cmds_table.cpp b/src/rpc-server/trex_rpc_cmds_table.cpp
index 37fed848..6144d265 100644
--- a/src/rpc-server/trex_rpc_cmds_table.cpp
+++ b/src/rpc-server/trex_rpc_cmds_table.cpp
@@ -39,7 +39,7 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() {
register_command(new TrexRpcCmdGetCmds());
register_command(new TrexRpcCmdGetVersion());
register_command(new TrexRpcCmdGetActivePGIds());
- register_command(new TrexRpcCmdGetCpuUtilFull());
+ register_command(new TrexRpcCmdGetUtilization());
register_command(new TrexRpcCmdGetSysInfo());
register_command(new TrexRpcCmdGetOwner());
register_command(new TrexRpcCmdAcquire());
diff --git a/src/trex_defs.h b/src/trex_defs.h
index 55e10fb2..62024fa8 100644
--- a/src/trex_defs.h
+++ b/src/trex_defs.h
@@ -37,6 +37,6 @@ limitations under the License.
typedef std::set<uint32_t> flow_stat_active_t;
typedef std::set<uint32_t>::iterator flow_stat_active_it_t;
-typedef std::vector<std::vector<double>> cpu_util_full_t;
+typedef std::vector<std::vector<uint8_t>> cpu_util_full_t;
#endif
diff --git a/src/utl_cpuu.cpp b/src/utl_cpuu.cpp
index 1954058c..1191eb74 100755
--- a/src/utl_cpuu.cpp
+++ b/src/utl_cpuu.cpp
@@ -25,8 +25,8 @@ limitations under the License.
void CCpuUtlCp::Create(CCpuUtlDp * cdp){
m_dpcpu=cdp;
- m_cpu_util.clear();
- m_cpu_util.push_back(0.0); // here it's same as insert to front
+ memset(m_cpu_util, 0, sizeof(m_cpu_util));
+ m_history_latest_index = 0;
m_cpu_util_lpf=0.0;
m_ticks=0;
m_work=0;
@@ -43,29 +43,35 @@ void CCpuUtlCp::Update(){
m_work++;
}
if (m_ticks==100) {
- double window_cpu_u = (double)m_work/m_ticks;
/* LPF*/
- m_cpu_util_lpf = (m_cpu_util_lpf*0.75)+(window_cpu_u*0.25);
- m_cpu_util.insert(m_cpu_util.begin(), window_cpu_u);
- if (m_cpu_util.size() > history_size)
- m_cpu_util.pop_back();
+ m_cpu_util_lpf = (m_cpu_util_lpf*0.75)+((double)m_work*0.25);
+ AppendHistory(m_work);
m_ticks=0;
m_work=0;
-
}
}
/* return cpu % Smoothed */
double CCpuUtlCp::GetVal(){
- return (m_cpu_util_lpf*100); // percentage
+ return (m_cpu_util_lpf);
}
/* return cpu % Raw */
-double CCpuUtlCp::GetValRaw(){
- return (m_cpu_util.front()*100); // percentage
+uint8_t CCpuUtlCp::GetValRaw(){
+ return (m_cpu_util[m_history_latest_index]);
+}
+
+/* return cpu % utilization history */
+std::vector<uint8_t> CCpuUtlCp::GetHistory(){
+ std::vector<uint8_t> history_vect;
+ for (int i = m_history_latest_index + m_history_size; i > m_history_latest_index; i--) {
+ history_vect.insert(history_vect.begin(), m_cpu_util[i % m_history_size]);
+ }
+ return (history_vect);
}
-/* return cpu utilization history */
-std::vector<double> CCpuUtlCp::GetHistory(){
- return (m_cpu_util);
+/* save last CPU % util in history */
+void CCpuUtlCp::AppendHistory(uint8_t val){
+ m_history_latest_index = (m_history_latest_index + 1) % m_history_size;
+ m_cpu_util[m_history_latest_index] = val;
}
diff --git a/src/utl_cpuu.h b/src/utl_cpuu.h
index f96f4688..ad4b2e3b 100755
--- a/src/utl_cpuu.h
+++ b/src/utl_cpuu.h
@@ -23,6 +23,7 @@ limitations under the License.
#include <stdint.h>
#include <vector>
+#include <cstring>
#include "os_time.h"
#include "mbuf.h"
@@ -57,15 +58,17 @@ public:
void Update();
/* return cpu % */
double GetVal();
- double GetValRaw();
- std::vector<double> GetHistory();
+ uint8_t GetValRaw();
+ std::vector<uint8_t> GetHistory();
private:
+ void AppendHistory(uint8_t);
CCpuUtlDp * m_dpcpu;
- uint16_t m_ticks;
- uint16_t m_work;
+ uint8_t m_ticks;
+ uint8_t m_work;
- std::vector<double> m_cpu_util; // save history
- const int history_size=20;
+ static const int m_history_size=20;
+ uint8_t m_cpu_util[m_history_size]; // history as cyclic array
+ uint8_t m_history_latest_index;
double m_cpu_util_lpf;
};