From 467bf894d284a2c0ce27f047a27f31c58a8ed029 Mon Sep 17 00:00:00 2001 From: wenlong12 Date: Tue, 8 Feb 2022 17:54:18 +0800 Subject: [PATCH] Fix coding specification issue Signed-off-by:wenlong12 Signed-off-by: wenlong12 --- include/hashlist.hpp | 5 +- include/perf_file_format.h | 1 - include/perf_file_reader.h | 1 - include/report.h | 2 - include/report_json_file.h | 124 ++++++++++++------ include/ring_buffer.h | 1 - include/subcommand.h | 6 +- include/tracked_command.h | 4 - src/report_json_file.cpp | 4 +- src/subcommand.cpp | 4 - src/subcommand_stat.cpp | 6 +- .../ElfParser_fuzzer/ElfParser_fuzzer.h | 2 +- 12 files changed, 91 insertions(+), 69 deletions(-) diff --git a/include/hashlist.hpp b/include/hashlist.hpp index 168b863..20e4d06 100755 --- a/include/hashlist.hpp +++ b/include/hashlist.hpp @@ -13,6 +13,9 @@ * limitations under the License. */ +#ifndef HIPERF_HASHLIST_HPP +#define HIPERF_HASHLIST_HPP + #include "hashlist.h" namespace OHOS { @@ -997,4 +1000,4 @@ HashList::ReclaimNode(LinkNode *&pnode) } } // namespace HiPerf } // namespace Developtools -} // namespace OHOS \ No newline at end of file +} // namespace OHOS #endif // HIPERF_HASHLIST_HPP diff --git a/include/perf_file_format.h b/include/perf_file_format.h index 38edae0..83ae1f4 100755 --- a/include/perf_file_format.h +++ b/include/perf_file_format.h @@ -16,7 +16,6 @@ #define HIPERF_PERF_FILE_FORMAT_H #include -#include #include "perf_event_record.h" diff --git a/include/perf_file_reader.h b/include/perf_file_reader.h index 285be56..a799bda 100755 --- a/include/perf_file_reader.h +++ b/include/perf_file_reader.h @@ -19,7 +19,6 @@ #include #include #include -#include #include "perf_event_record.h" #include "perf_file_format.h" diff --git a/include/report.h b/include/report.h index b33728d..a90201f 100755 --- a/include/report.h +++ b/include/report.h @@ -19,10 +19,8 @@ #include #include #include -#include #include #include -#include #include #include "debug_logger.h" diff --git a/include/report_json_file.h b/include/report_json_file.h index fa566a0..a46bf97 100755 --- a/include/report_json_file.h +++ b/include/report_json_file.h @@ -19,10 +19,7 @@ #include #include #include -#include #include -#include -#include #include #include "debug_logger.h" @@ -95,7 +92,9 @@ template void OutputJsonPair(FILE *output, const K &key, const T &value, bool first = false) { if (!first) { - fprintf(output, ","); + if (fprintf(output, ",") < 0) { + return; + } } OutputJsonKey(output, key); OutputJsonValue(output, value); @@ -109,16 +108,20 @@ void OutputJsonVectorList(FILE *output, const std::string &key, const std::vecto bool first = false) { if (!first) { - fprintf(output, ","); + if (fprintf(output, ",") < 0) { + return; + } } - fprintf(output, "\"%s\":", key.c_str()); - fprintf(output, "["); - auto it = value.begin(); - while (it != value.end()) { - OutputJsonValue(output, *it, it == value.begin()); - it++; + if (fprintf(output, "\"%s\":[", key.c_str()) != -1) { + auto it = value.begin(); + while (it != value.end()) { + OutputJsonValue(output, *it, it == value.begin()); + it++; + } + if (fprintf(output, "]") < 0) { + return; + } } - fprintf(output, "]"); } /* @@ -129,16 +132,21 @@ void OutputJsonMapList(FILE *output, const std::string &key, const std::mapsecond, it == value.begin()); - it++; + if (fprintf(output, "\"%s\":[", key.c_str()) != -1) { + fprintf(output, "["); + auto it = value.begin(); + while (it != value.end()) { + OutputJsonValue(output, it->second, it == value.begin()); + it++; + } + if (fprintf(output, "]") < 0) { + return; + } } - fprintf(output, "]"); } /* @@ -149,16 +157,20 @@ void OutputJsonMap(FILE *output, const std::string &key, const std::map &v bool first = false) { if (!first) { - fprintf(output, ","); + if (fprintf(output, ",") < 0) { + return; + } } - fprintf(output, "\"%s\":", key.c_str()); - fprintf(output, "{"); - auto it = value.begin(); - while (it != value.end()) { - OutputJsonPair(output, it->first, it->second, it == value.begin()); - it++; + if (fprintf(output, "\"%s\":{", key.c_str()) != -1) { + auto it = value.begin(); + while (it != value.end()) { + OutputJsonPair(output, it->first, it->second, it == value.begin()); + it++; + } + if (fprintf(output, "}") < 0) { + return; + } } - fprintf(output, "}"); } template @@ -177,10 +189,14 @@ struct ReportFuncMapItem { std::string_view funcName_; void OutputJson(FILE *output) const { - fprintf(output, "{"); + if (fprintf(output, "{") < 0) { + return; + } OutputJsonPair(output, "file", libId_, true); OutputJsonPair(output, "symbol", funcName_); - fprintf(output, "}"); + if (fprintf(output, "}") < 0) { + return; + } } ReportFuncMapItem(int libId, std::string_view funcName) : libId_(libId), funcName_(funcName) {} }; @@ -194,11 +210,15 @@ struct ReportFuncItem { ReportFuncItem(int functionId) : functionId_(functionId) {} void OutputJson(FILE *output) const { - fprintf(output, "{"); + if (fprintf(output, "{") < 0) { + return; + } OutputJsonPair(output, "symbol", functionId_, true); OutputJsonVectorList(output, "counts", std::vector {sampleCount_, eventCount_, subTreeEventCount_}); - fprintf(output, "}"); + if (fprintf(output, "}") < 0) { + return; + } } }; @@ -214,7 +234,9 @@ struct ReportCallNodeItem { void OutputJson(FILE *output) const { - fprintf(output, "{"); + if (fprintf(output, "{") < 0) { + return; + } OutputJsonPair(output, "selfEvents", selfEventCount_, true); OutputJsonPair(output, "subEvents", subTreeEventCount_); OutputJsonPair(output, "symbol", functionId_); @@ -224,7 +246,9 @@ struct ReportCallNodeItem { OutputJsonPair(output, "reversed", reverseCaller_); } OutputJsonMapList(output, "callStack", childrenMap); - fprintf(output, "}"); + if (fprintf(output, "}") < 0) { + return; + } } uint64_t UpdateChildrenEventCount() @@ -252,11 +276,15 @@ struct ReportLibItem { std::map funcs_; void OutputJson(FILE *output) const { - fprintf(output, "{"); + if (fprintf(output, "{") < 0) { + return; + } OutputJsonPair(output, "fileId", libId_, true); OutputJsonPair(output, "eventCount", eventCount_); OutputJsonMapList(output, "functions", funcs_); - fprintf(output, "}"); + if (fprintf(output, "}") < 0) { + return; + } } }; @@ -269,14 +297,18 @@ struct ReportThreadItem { ReportCallNodeItem callNodeReverse; void OutputJson(FILE *output) const { - fprintf(output, "{"); + if (fprintf(output, "{") < 0) { + return; + } OutputJsonPair(output, "tid", tid_, true); OutputJsonPair(output, "eventCount", eventCount_); OutputJsonPair(output, "sampleCount", sampleCount_); OutputJsonMapList(output, "libs", libs_); OutputJsonPair(output, "CallOrder", callNode); OutputJsonPair(output, "CalledOrder", callNodeReverse); - fprintf(output, "}"); + if (fprintf(output, "}") < 0) { + return; + } } ReportThreadItem(pid_t id) : tid_(id), callNode(-1), callNodeReverse(-1) {} }; @@ -287,11 +319,15 @@ struct ReportProcessItem { std::map threads_; void OutputJson(FILE *output) const { - fprintf(output, "{"); + if (fprintf(output, "{") < 0) { + return; + } OutputJsonPair(output, "pid", pid_, true); OutputJsonPair(output, "eventCount", eventCount_); OutputJsonMapList(output, "threads", threads_); - fprintf(output, "}"); + if (fprintf(output, "}") < 0) { + return; + } } ReportProcessItem(pid_t pid) : pid_(pid) {} }; @@ -303,11 +339,15 @@ struct ReportConfigItem { std::map processes_; void OutputJson(FILE *output) const { - fprintf(output, "{"); + if (fprintf(output, "{") < 0) { + return; + } OutputJsonPair(output, "eventConfigName", eventName_, true); OutputJsonPair(output, "eventCount", eventCount_); OutputJsonMapList(output, "processes", processes_); - fprintf(output, "}"); + if (fprintf(output, "}") < 0) { + return; + } } ReportConfigItem(int index, std::string eventName) : index_(index), eventName_(eventName) {} }; diff --git a/include/ring_buffer.h b/include/ring_buffer.h index b4f2f90..ac69083 100755 --- a/include/ring_buffer.h +++ b/include/ring_buffer.h @@ -15,7 +15,6 @@ #ifndef HIPERF_RING_BUFFER_H #define HIPERF_RING_BUFFER_H -#include #include namespace OHOS { diff --git a/include/subcommand.h b/include/subcommand.h index ba68bd4..9531057 100755 --- a/include/subcommand.h +++ b/include/subcommand.h @@ -15,13 +15,9 @@ #ifndef HIPERF_SUBCOMMAND_H_ #define HIPERF_SUBCOMMAND_H_ -#include "utilities.h" #include -#include -#include -#include #include -#include +#include "utilities.h" namespace OHOS { namespace Developtools { diff --git a/include/tracked_command.h b/include/tracked_command.h index 62e7fdf..92e5109 100755 --- a/include/tracked_command.h +++ b/include/tracked_command.h @@ -17,10 +17,6 @@ #include #include -#include -#include - -#include "noncopyable.h" #include namespace OHOS { namespace Developtools { diff --git a/src/report_json_file.cpp b/src/report_json_file.cpp index 70a80d5..a89810c 100755 --- a/src/report_json_file.cpp +++ b/src/report_json_file.cpp @@ -14,11 +14,9 @@ */ #define HILOG_TAG "Report" +#include #include "report_json_file.h" -#include -#include - #if is_mingw #include #else diff --git a/src/subcommand.cpp b/src/subcommand.cpp index c4b3529..ffd0fb1 100755 --- a/src/subcommand.cpp +++ b/src/subcommand.cpp @@ -15,10 +15,6 @@ #include "subcommand.h" -#include -#include -#include - #include "debug_logger.h" #include "option.h" #include "subcommand_help.h" diff --git a/src/subcommand_stat.cpp b/src/subcommand_stat.cpp index 956cf05..ce1c0dc 100644 --- a/src/subcommand_stat.cpp +++ b/src/subcommand_stat.cpp @@ -19,14 +19,12 @@ #include #include -#include - #include "debug_logger.h" #include "subcommand_stat.h" #include "utilities.h" -#define ONE_HUNDRED 100 -#define THOUSNADS_SEPARATOR 3 +const uint16_t ONE_HUNDRED = 100; +const uint16_t THOUSNADS_SEPARATOR = 3; namespace OHOS { namespace Developtools { namespace HiPerf { diff --git a/test/fuzztest/ElfParser_fuzzer/ElfParser_fuzzer.h b/test/fuzztest/ElfParser_fuzzer/ElfParser_fuzzer.h index 18a0219..2a05099 100755 --- a/test/fuzztest/ElfParser_fuzzer/ElfParser_fuzzer.h +++ b/test/fuzztest/ElfParser_fuzzer/ElfParser_fuzzer.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include -- Gitee