diff options
-rwxr-xr-x | src/bp_sim.cpp | 10 | ||||
-rwxr-xr-x | src/bp_sim.h | 1 | ||||
-rw-r--r-- | src/internal_api/trex_platform_api.h | 3 | ||||
-rw-r--r-- | src/main_dpdk.cpp | 11 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_general.cpp | 20 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 1 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmds_table.cpp | 1 | ||||
-rw-r--r-- | src/trex_defs.h | 2 | ||||
-rwxr-xr-x | src/utl_cpuu.cpp | 24 | ||||
-rwxr-xr-x | src/utl_cpuu.h | 14 |
10 files changed, 77 insertions, 10 deletions
diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index 51023b90..27a79268 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -4511,6 +4511,16 @@ double CFlowGenList::GetCpuUtil(){ return (c/m_threads_info.size()); } +double CFlowGenList::GetCpuUtilRaw(){ + int i; + double c=0.0; + for (i=0; i<(int)m_threads_info.size(); i++) { + CFlowGenListPerThread * lp=m_threads_info[i]; + c+=lp->m_cpu_cp_u.GetValRaw(); + } + return (c/m_threads_info.size()); +} + void CFlowGenList::UpdateFast(){ diff --git a/src/bp_sim.h b/src/bp_sim.h index bb7dd928..7b4dfdd5 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -3841,6 +3841,7 @@ public: void DumpPktSize(); void UpdateFast(); double GetCpuUtil(); + double GetCpuUtilRaw(); public: double get_total_kcps(); diff --git a/src/internal_api/trex_platform_api.h b/src/internal_api/trex_platform_api.h index a52f9e60..ca37b0da 100644 --- a/src/internal_api/trex_platform_api.h +++ b/src/internal_api/trex_platform_api.h @@ -156,6 +156,7 @@ public: virtual bool get_promiscuous(uint8_t port_id) const = 0; 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 CFlowStatParser *get_flow_stat_parser() const = 0; virtual ~TrexPlatformApi() {} }; @@ -188,6 +189,7 @@ public: bool get_promiscuous(uint8_t port_id) const; 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; CFlowStatParser *get_flow_stat_parser() const; }; @@ -252,6 +254,7 @@ public: void flush_dp_messages() const { } 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;} CFlowStatParser *get_flow_stat_parser() const {return new CFlowStatParser();} private: diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index ca5664d7..ff4b2b6a 100644 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -2417,6 +2417,7 @@ public: float m_active_flows; float m_open_flows; float m_cpu_util; + float m_cpu_util_raw; float m_rx_cpu_util; float m_bw_per_core; uint8_t m_threads; @@ -2484,6 +2485,7 @@ void CGlobalStats::dump_json(std::string & json, bool baseline,uint32_t stats_ti #define GET_FIELD_PORT(p,f) get_field_port(p,std::string(#f),lp->f) json+=GET_FIELD(m_cpu_util); + json+=GET_FIELD(m_cpu_util_raw); json+=GET_FIELD(m_bw_per_core); json+=GET_FIELD(m_rx_cpu_util); json+=GET_FIELD(m_platform_factor); @@ -3542,6 +3544,7 @@ void CGlobalTRex::get_stats(CGlobalStats & stats){ stats.m_num_of_ports = m_max_ports; stats.m_cpu_util = m_fl.GetCpuUtil(); + stats.m_cpu_util_raw = m_fl.GetCpuUtilRaw(); if (get_is_stateless()) { stats.m_rx_cpu_util = m_rx_sl.get_cpu_util(); } @@ -5703,6 +5706,14 @@ int TrexDpdkPlatformApi::get_active_pgids(flow_stat_active_t &result) const { return g_trex.m_trex_stateless->m_rx_flow_stat.get_active_pgids(result); } +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]; + cpu_util_full.push_back(lp->m_cpu_cp_u.GetHistory()); + } + 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 68ea2587..541ff099 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -156,6 +156,26 @@ TrexRpcCmdGetActivePGIds::_run(const Json::Value ¶ms, 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. + */ +trex_rpc_cmd_rc_e +TrexRpcCmdGetCpuUtilFull::_run(const Json::Value ¶ms, Json::Value &result) { + cpu_util_full_t cpu_util_full; + + Json::Value §ion = result["result"]; + section = Json::arrayValue; + + 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)); + } + } + return (TREX_RPC_CMD_OK); +} /** * get the CPU model diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h index affa65c1..0df9fd2b 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -67,6 +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_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 7104792e..37fed848 100644 --- a/src/rpc-server/trex_rpc_cmds_table.cpp +++ b/src/rpc-server/trex_rpc_cmds_table.cpp @@ -39,6 +39,7 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() { register_command(new TrexRpcCmdGetCmds()); register_command(new TrexRpcCmdGetVersion()); register_command(new TrexRpcCmdGetActivePGIds()); + register_command(new TrexRpcCmdGetCpuUtilFull()); 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 665c1edc..55e10fb2 100644 --- a/src/trex_defs.h +++ b/src/trex_defs.h @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ #include <set> +#include <queue> #ifndef __TREX_DEFS_H__ #define __TREX_DEFS_H__ @@ -36,5 +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; #endif diff --git a/src/utl_cpuu.cpp b/src/utl_cpuu.cpp index 4d75cf6f..1954058c 100755 --- a/src/utl_cpuu.cpp +++ b/src/utl_cpuu.cpp @@ -25,7 +25,9 @@ limitations under the License. void CCpuUtlCp::Create(CCpuUtlDp * cdp){ m_dpcpu=cdp; - m_cpu_util=0.0; + m_cpu_util.clear(); + m_cpu_util.push_back(0.0); // here it's same as insert to front + m_cpu_util_lpf=0.0; m_ticks=0; m_work=0; } @@ -41,17 +43,29 @@ void CCpuUtlCp::Update(){ m_work++; } if (m_ticks==100) { - double window_cpu_u = ((double)m_work/(double)m_ticks); + double window_cpu_u = (double)m_work/m_ticks; /* LPF*/ - m_cpu_util = (m_cpu_util*0.75)+(window_cpu_u*0.25); + 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_ticks=0; m_work=0; } } -/* return cpu % */ +/* return cpu % Smoothed */ double CCpuUtlCp::GetVal(){ - return (m_cpu_util*100); + return (m_cpu_util_lpf*100); // percentage } +/* return cpu % Raw */ +double CCpuUtlCp::GetValRaw(){ + return (m_cpu_util.front()*100); // percentage +} + +/* return cpu utilization history */ +std::vector<double> CCpuUtlCp::GetHistory(){ + return (m_cpu_util); +} diff --git a/src/utl_cpuu.h b/src/utl_cpuu.h index e5305783..f96f4688 100755 --- a/src/utl_cpuu.h +++ b/src/utl_cpuu.h @@ -22,6 +22,7 @@ limitations under the License. */ #include <stdint.h> +#include <vector> #include "os_time.h" #include "mbuf.h" @@ -56,13 +57,16 @@ public: void Update(); /* return cpu % */ double GetVal(); - + double GetValRaw(); + std::vector<double> GetHistory(); private: - CCpuUtlDp * m_dpcpu; - uint16_t m_ticks; - uint16_t m_work; + CCpuUtlDp * m_dpcpu; + uint16_t m_ticks; + uint16_t m_work; - double m_cpu_util; + std::vector<double> m_cpu_util; // save history + const int history_size=20; + double m_cpu_util_lpf; }; #endif |