From e0ca7a226fd37023ff8a9d80e46403a34492c1d7 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Sun, 5 Jun 2016 01:16:11 +0300 Subject: cpu utilization: don't return vectors, only change passed arguments. --- src/bp_sim.cpp | 14 ++++++-------- src/bp_sim.h | 4 ++-- src/main_dpdk.cpp | 6 ++++-- src/trex_defs.h | 2 ++ src/utl_cpuu.cpp | 9 ++++----- src/utl_cpuu.h | 4 ++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index be9de21e..cb70c572 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -504,8 +504,7 @@ void CRteMemPool::add_to_json(Json::Value &json, std::string name, rte_mempool_t } -Json::Value CRteMemPool::dump_as_json(){ - Json::Value json; +void 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); @@ -514,7 +513,6 @@ Json::Value CRteMemPool::dump_as_json(){ 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); } @@ -534,21 +532,21 @@ void CRteMemPool::dump(FILE *fd){ //////////////////////////////////////// -Json::Value CGlobalInfo::dump_pool_as_json(void){ - Json::Value json; +void CGlobalInfo::dump_pool_as_json(Json::Value &json){ CPlatformSocketInfo * lpSocket =&m_socket; for (int i=0; i<(int)MAX_SOCKETS_SUPPORTED; i++) { if (lpSocket->is_sockets_enable((socket_id_t)i)) { std::string socket_id = "cpu-socket-" + std::to_string(i); - json["mbuf_stats"][socket_id] = m_mem_pool[i].dump_as_json(); + m_mem_pool[i].dump_as_json(json["mbuf_stats"][socket_id]); } } - return json; } std::string CGlobalInfo::dump_pool_as_json_str(void){ - return ("\"mbuf_stats\":" + dump_pool_as_json().toStyledString() + ","); + Json::Value json; + dump_pool_as_json(json); + return (json.toStyledString()); } void CGlobalInfo::free_pools(){ diff --git a/src/bp_sim.h b/src/bp_sim.h index 8aead5f1..5d25506d 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -1149,7 +1149,7 @@ public: void dump_in_case_of_error(FILE *fd); - Json::Value dump_as_json(); + void dump_as_json(Json::Value &json); private: void add_to_json(Json::Value &json, std::string name, rte_mempool_t * pool); @@ -1246,7 +1246,7 @@ public: } - static Json::Value dump_pool_as_json(void); + static void dump_pool_as_json(Json::Value &json); static std::string dump_pool_as_json_str(void); diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 94679d72..75da27ca 100644 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -5703,15 +5703,17 @@ 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 { + static cpu_vct_t cpu_vct; 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()); + cpu_util_full.push_back(cpu_vct); + lp->m_cpu_cp_u.GetHistory(cpu_util_full.back()); } return 0; } int TrexDpdkPlatformApi::get_mbuf_util(Json::Value &mbuf_pool) const { - mbuf_pool = CGlobalInfo::dump_pool_as_json(); + CGlobalInfo::dump_pool_as_json(mbuf_pool); return 0; } diff --git a/src/trex_defs.h b/src/trex_defs.h index 62024fa8..bbf3f3ba 100644 --- a/src/trex_defs.h +++ b/src/trex_defs.h @@ -15,6 +15,7 @@ limitations under the License. */ #include #include +#include #ifndef __TREX_DEFS_H__ #define __TREX_DEFS_H__ @@ -38,5 +39,6 @@ limitations under the License. typedef std::set flow_stat_active_t; typedef std::set::iterator flow_stat_active_it_t; typedef std::vector> cpu_util_full_t; +typedef std::vector cpu_vct_t; #endif diff --git a/src/utl_cpuu.cpp b/src/utl_cpuu.cpp index 1191eb74..7786356e 100755 --- a/src/utl_cpuu.cpp +++ b/src/utl_cpuu.cpp @@ -61,13 +61,12 @@ uint8_t CCpuUtlCp::GetValRaw(){ return (m_cpu_util[m_history_latest_index]); } -/* return cpu % utilization history */ -std::vector CCpuUtlCp::GetHistory(){ - std::vector history_vect; +/* get cpu % utilization history */ +void CCpuUtlCp::GetHistory(cpu_vct_t &cpu_vct){ + cpu_vct.clear(); 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]); + cpu_vct.push_back(m_cpu_util[i % m_history_size]); } - return (history_vect); } /* save last CPU % util in history */ diff --git a/src/utl_cpuu.h b/src/utl_cpuu.h index ad4b2e3b..109fff4f 100755 --- a/src/utl_cpuu.h +++ b/src/utl_cpuu.h @@ -22,8 +22,8 @@ limitations under the License. */ #include -#include #include +#include "trex_defs.h" #include "os_time.h" #include "mbuf.h" @@ -59,7 +59,7 @@ public: /* return cpu % */ double GetVal(); uint8_t GetValRaw(); - std::vector GetHistory(); + void GetHistory(cpu_vct_t &cpu_vct); private: void AppendHistory(uint8_t); CCpuUtlDp * m_dpcpu; -- cgit 1.2.3-korg