diff --git a/include/pcerrc.h b/include/pcerrc.h index a835c71d2e3009ab1925cb7465ab1baaf4ef4366..f5c6c02578f843b9e768fb38a958baf7ae371fea 100644 --- a/include/pcerrc.h +++ b/include/pcerrc.h @@ -79,6 +79,7 @@ extern "C" { // warnning code #define LIBPERF_WARN_CTXID_LOST 1000 +#define LIBPERF_WARN_FAIL_GET_PROC 1001 /** diff --git a/pmu/pmu_list.cpp b/pmu/pmu_list.cpp index 003d1b58b75f1a9a08966ff6d4be8a93debfe7fb..7f06549d4da7b48a78d298f8032815a38b150944 100644 --- a/pmu/pmu_list.cpp +++ b/pmu/pmu_list.cpp @@ -625,16 +625,22 @@ namespace KUNPENG_PMU { if (childTidList == nullptr) { return LIBPERF_ERR_INVALID_PID; } + bool foundProc = false; for (int j = 0; j < numChild; j++) { struct ProcTopology* procTopo = GetProcTopology(childTidList[j]); if (procTopo == nullptr) { - New(LIBPERF_ERR_FAIL_GET_PROC); - return LIBPERF_ERR_FAIL_GET_PROC; + SetWarn(LIBPERF_WARN_FAIL_GET_PROC, "process not found: " + std::to_string(childTidList[j])); + continue; } + foundProc = true; DBG_PRINT("Add to proc map: %d\n", childTidList[j]); procTopoList.emplace_back(shared_ptr(procTopo, FreeProcTopo)); } delete[] childTidList; + if (!foundProc) { + New(LIBPERF_ERR_FAIL_GET_PROC, "process not found: " + std::to_string(pmuTaskAttrHead->pidList[i])); + return LIBPERF_ERR_FAIL_GET_PROC; + } } return SUCCESS; } diff --git a/pmu/spe.h b/pmu/spe.h index 1312403ca63e7173448743e6ddaa5ef2c13129ef..71b2d7b2a28484043f0ee4bba73e90d2779aa894 100644 --- a/pmu/spe.h +++ b/pmu/spe.h @@ -135,7 +135,7 @@ public: ~Spe() { if (records != nullptr) { - delete records; + delete[] records; records = nullptr; } } diff --git a/util/pcerr.cpp b/util/pcerr.cpp index 6441a84d1bc92d6ed7516aa7654525cd0fe95709..cabb7b07dfa3e10ba21135f95af7354342f04d8f 100644 --- a/util/pcerr.cpp +++ b/util/pcerr.cpp @@ -51,18 +51,8 @@ namespace pcerr { }; static int warnCode = SUCCESS; static std::string warnMsg = ""; - - ProfErrorObj ProfErrorObj::profErrorObj; - - ProfErrorObj& ProfErrorObj::GetInstance() - { - return profErrorObj; - } - - void ProfErrorObj::SetProfError(const ProfError& profError) - { - this->profError = profError; - } + static int errCode = SUCCESS; + static std::string errMsg = ""; void New(int code) { @@ -76,31 +66,35 @@ namespace pcerr { void New(int code, const std::string& msg) { - ProfError profError = std::make_shared(code, msg); - ProfErrorObj::GetInstance().SetProfError(profError); + errCode = code; + errMsg = msg; } void SetWarn(int warn) { - warnCode = warn; auto findMsg = warnMsgs.find(warn); if (findMsg != warnMsgs.end()) { - warnMsg = findMsg->second; + SetWarn(warn, findMsg->second); } else { - warnMsg = ""; + SetWarn(warn, ""); } } + void SetWarn(int code, const std::string& msg) + { + warnCode = code; + warnMsg = msg; + } } // namespace pcerr int Perrorno() { - return pcerr::ProfErrorObj::GetInstance().GetProfError()->Code(); + return pcerr::errCode; } const char* Perror() { - return pcerr::ProfErrorObj::GetInstance().GetProfError()->Msg(); + return pcerr::errMsg.c_str(); } int GetWarn() diff --git a/util/pcerr.h b/util/pcerr.h index 125bfe2e517c9d488797819461aae122b36025e6..27598c61a2bbe66506219795d24148e95a1d7cbf 100644 --- a/util/pcerr.h +++ b/util/pcerr.h @@ -21,71 +21,10 @@ #include "pcerrc.h" namespace pcerr { - namespace details { - struct BaseError; - } - - using ProfError = std::shared_ptr; - - namespace details { - struct BaseError : std::enable_shared_from_this { - virtual ~BaseError() = 0; - virtual const char* Msg() const - { - return nullptr; - } - virtual int Code() const - { - return 0; - } - ProfError GetThisError() - { - return shared_from_this(); - } - }; - inline BaseError::~BaseError() - {} - } // namespace details - - namespace details { - class CodeStrMsgError : public BaseError { - public: - CodeStrMsgError(int code, const std::string& msg) : m_code{code}, m_msg{msg} - {} - int Code() const override - { - return this->m_code; - }; - const char* Msg() const override - { - return this->m_msg.c_str(); - }; - - private: - int m_code; - std::string m_msg; - }; - } // namespace details - class ProfErrorObj { - public: - static ProfErrorObj& GetInstance(); - void SetProfError(const ProfError& profError); - ProfError& GetProfError() - { - if (profError == nullptr) { - profError = std::make_shared(0, "success"); - } - return profError; - } - - private: - ProfError profError; - static ProfErrorObj profErrorObj; - }; - void [[nodiscard]] New(int code); void [[nodiscard]] New(int code, const std::string& msg); void [[nodiscard]] SetWarn(int warn); + void [[nodiscard]] SetWarn(int warn, const std::string& msg); } // namespace pcerr #endif \ No newline at end of file