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 "delayed_sp_singleton.h" 21 #include "dump_errors.h" 22 namespace OHOS { 23 namespace HiviewDFX { 24 #define RETURN_PARCEL_READ_HELPER_RET(parcel, type, out, failRet) \ 25 do { \ 26 bool ret = (parcel).Read##type((out)); \ 27 if (!ret) { \ 28 return failRet; \ 29 } \ 30 } while (0) 31 32 #define RETURN_PARCEL_WRITE_HELPER_RET(parcel, type, value, failRet) \ 33 do { \ 34 bool ret = (parcel).Write##type((value)); \ 35 if (!ret) { \ 36 return failRet; \ 37 } \ 38 } while (0) 39 40 class DumpCpuData : public Parcelable { 41 public: 42 using StringCpuMatrix = std::vector<std::vector<std::string>>; 43 DumpCpuData(); 44 DumpCpuData(std::string& startTime, std::string& endTime, int cpuUsagePid, StringCpuMatrix dumpCPUDatas); 45 ~DumpCpuData(); 46 static DumpCpuData *Unmarshalling(Parcel& parcel); 47 bool Marshalling(Parcel& parcel) const override; 48 bool ReadFromParcel(Parcel &parcel); 49 bool WriteStringMatrix(const std::vector<std::vector<std::string>> &martrixVec, Parcel &data) const; 50 bool ReadStringMatrix(std::vector<std::vector<std::string>> &martrixVec, Parcel &data); 51 public: 52 std::string startTime_; 53 std::string endTime_; 54 int cpuUsagePid_ = -1; 55 StringCpuMatrix dumpCPUDatas_; 56 private: 57 friend DumpDelayedSpSingleton<DumpCpuData>; 58 }; 59 } // namespace HiviewDFX 60 } // namespace OHOS 61 #endif 62