1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef DUMP_CPU_DATA_H 16 #define DUMP_CPU_DATA_H 17 #include <string> 18 #include <vector> 19 #include "parcel.h" 20 #include "util/dump_cpu_info_util.h" 21 #include "delayed_sp_singleton.h" 22 #include "dump_errors.h" 23 namespace OHOS { 24 namespace HiviewDFX { 25 #define RETURN_PARCEL_READ_HELPER_RET(parcel, type, out, failRet) \ 26 do { \ 27 bool ret = (parcel).Read##type((out)); \ 28 if (!ret) { \ 29 return failRet; \ 30 } \ 31 } while (0) 32 33 #define RETURN_PARCEL_WRITE_HELPER_RET(parcel, type, value, failRet) \ 34 do { \ 35 bool ret = (parcel).Write##type((value)); \ 36 if (!ret) { \ 37 return failRet; \ 38 } \ 39 } while (0) 40 41 class DumpCpuData : public Parcelable { 42 public: 43 using StringCpuMatrix = std::vector<std::vector<std::string>>; 44 DumpCpuData(); 45 DumpCpuData(std::string& startTime, std::string& endTime, int cpuUsagePid, StringCpuMatrix dumpCPUDatas); 46 ~DumpCpuData(); 47 static DumpCpuData *Unmarshalling(Parcel& parcel); 48 bool Marshalling(Parcel& parcel) const override; 49 bool ReadFromParcel(Parcel &parcel); 50 bool WriteStringMatrix(const std::vector<std::vector<std::string>> &martrixVec, Parcel &data) const; 51 bool ReadStringMatrix(std::vector<std::vector<std::string>> &martrixVec, Parcel &data); 52 public: 53 std::string startTime_; 54 std::string endTime_; 55 int cpuUsagePid_ = -1; 56 StringCpuMatrix dumpCPUDatas_; 57 private: 58 friend DumpDelayedSpSingleton<DumpCpuData>; 59 }; 60 } // namespace HiviewDFX 61 } // namespace OHOS 62 #endif 63