diff --git a/module/common/include/oops/format.h b/module/common/include/oops/format.h index d5dfc48..fd13bae 100644 --- a/module/common/include/oops/format.h +++ b/module/common/include/oops/format.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -12,18 +13,18 @@ namespace oops { template class FFloatPoint { static_assert(::std::is_floating_point_v); - enum Format : uint8_t { FIXED, SCI }; + enum Format : std::uint8_t { FIXED, SCI }; public: explicit FFloatPoint(F f) : f_{f} {} FFloatPoint &Sci(); FFloatPoint &Fixed(); - FFloatPoint &SetPrecision(uint8_t precision); - void Output(::std::ostream &out) const; + FFloatPoint &SetPrecision(std::uint8_t precision); + void Output(std::ostream &out) const; private: Format format_{FIXED}; - uint8_t precision_{2}; + std::uint8_t precision_{2}; F f_; }; @@ -32,18 +33,18 @@ using FDouble = FFloatPoint; class FTable { public: - enum Align : uint8_t { LEFT, CENTER, RIGHT }; + enum Align : std::uint8_t { LEFT, CENTER, RIGHT }; struct Prop { Align align{LEFT}; - size_t left_margin{0}; - size_t right_margin{0}; - size_t min_width{0}; + std::size_t left_margin{0}; + std::size_t right_margin{0}; + std::size_t min_width{0}; }; FTable &SetDelim(const ::std::string &delim); FTable &SetProp(const Prop &prop); - FTable &SetProp(size_t j, const Prop &prop); + FTable &SetProp(std::size_t j, const Prop &prop); template FTable &AppendRow(const Args &...args) { @@ -63,7 +64,7 @@ class FTable { void Output(::std::ostream &out) const; private: - const Prop &GetProp(size_t j) const; + const Prop &GetProp(std::size_t j) const; ::std::string delim_{" "}; ::std::vector<::std::vector<::std::string>> table_{{}}; diff --git a/module/common/include/oops/once.h b/module/common/include/oops/once.h index 2e6ef55..2ee6e44 100644 --- a/module/common/include/oops/once.h +++ b/module/common/include/oops/once.h @@ -24,11 +24,11 @@ namespace oops { namespace detail { -template +template struct Only { template static bool F(Lambda &&) { - static size_t count{0}; + static std::size_t count{0}; if (count < N) { ++count; return true; @@ -58,12 +58,12 @@ struct Only<0> { } }; -template +template struct Every { static_assert(N > 0); template static bool F(Lambda &&) { - static size_t count{0}; + static std::size_t count{0}; if (count >= N) { count = 0; } diff --git a/module/common/src/format.cpp b/module/common/src/format.cpp index 90f634a..a176f6e 100644 --- a/module/common/src/format.cpp +++ b/module/common/src/format.cpp @@ -15,7 +15,7 @@ FFloatPoint &FFloatPoint::Fixed() { } template -FFloatPoint &FFloatPoint::SetPrecision(uint8_t precision) { +FFloatPoint &FFloatPoint::SetPrecision(std::uint8_t precision) { precision_ = precision; return *this; } @@ -48,7 +48,7 @@ FTable &FTable::SetProp(const Prop &prop) { return *this; } -FTable &FTable::SetProp(size_t j, const Prop &prop) { +FTable &FTable::SetProp(std::size_t j, const Prop &prop) { if (j > col_prop_vec_.size()) { col_prop_vec_.resize(j + 1); } @@ -57,25 +57,25 @@ FTable &FTable::SetProp(size_t j, const Prop &prop) { } void FTable::Output(std::ostream &out) const { - std::vector col_width_vec; - for (size_t i{0}; i < table_.size() - 1; ++i) { + std::vector col_width_vec; + for (std::size_t i{0}; i < table_.size() - 1; ++i) { auto &row{table_[i]}; - for (size_t j{0}; j < row.size(); ++j) { - for (size_t n{col_width_vec.size()}; n < j + 1; ++n) { + for (std::size_t j{0}; j < row.size(); ++j) { + for (std::size_t n{col_width_vec.size()}; n < j + 1; ++n) { const Prop &prop{GetProp(n)}; - size_t default_width{std::max(prop.left_margin + prop.right_margin, prop.min_width)}; + std::size_t default_width{std::max(prop.left_margin + prop.right_margin, prop.min_width)}; col_width_vec.push_back(default_width); } const Prop &prop{GetProp(j)}; col_width_vec[j] = std::max(col_width_vec[j], row[j].size() + prop.left_margin + prop.right_margin); } } - for (size_t i{0}; i < table_.size() - 1; ++i) { + for (std::size_t i{0}; i < table_.size() - 1; ++i) { auto &row{table_[i]}; - for (size_t j{0}; j < row.size(); ++j) { + for (std::size_t j{0}; j < row.size(); ++j) { const Prop &prop{GetProp(j)}; - size_t space_num{col_width_vec[j] - row[j].size()}; - size_t left_space_num{0}; + std::size_t space_num{col_width_vec[j] - row[j].size()}; + std::size_t left_space_num{0}; switch (prop.align) { case Align::LEFT: { left_space_num = prop.left_margin; @@ -99,7 +99,7 @@ void FTable::Output(std::ostream &out) const { } } -const FTable::Prop &FTable::GetProp(size_t j) const { +const FTable::Prop &FTable::GetProp(std::size_t j) const { if (j < col_prop_vec_.size()) { return col_prop_vec_[j]; } diff --git a/module/matrix/include/oops/coo.h b/module/matrix/include/oops/coo.h index 0391c72..1822ee3 100644 --- a/module/matrix/include/oops/coo.h +++ b/module/matrix/include/oops/coo.h @@ -39,8 +39,8 @@ class CooIterator { using iterator_category = std::bidirectional_iterator_tag; using difference_type = std::ptrdiff_t; using value_type = TripletProxy; - using pointer = value_type *; - using reference = value_type &; + using pointer = TripletProxy *; + using reference = TripletProxy &; CooIterator() = default; CooIterator(StoreType &store, std::size_t i) : store_{store}, i_{i} {} diff --git a/module/matrix/include/oops/matrix_type.h b/module/matrix/include/oops/matrix_type.h index be8436c..d318bbc 100644 --- a/module/matrix/include/oops/matrix_type.h +++ b/module/matrix/include/oops/matrix_type.h @@ -11,9 +11,9 @@ #include "oops/type_list.h" namespace oops { -enum class MatrixFormat : uint8_t { SPARSE_COO, SPARSE_CSR, SPARSE_CSC, DENSE_ROW_MAJOR, DENSE_COL_MAJOR }; -enum class MatrixNumeric : uint8_t { REAL, COMPLEX, INTEGER, PATTERN, OTHER }; -enum class MatrixSymmetric : uint8_t { +enum class MatrixFormat : std::uint8_t { SPARSE_COO, SPARSE_CSR, SPARSE_CSC, DENSE_ROW_MAJOR, DENSE_COL_MAJOR }; +enum class MatrixNumeric : std::uint8_t { REAL, COMPLEX, INTEGER, PATTERN, OTHER }; +enum class MatrixSymmetric : std::uint8_t { GENERAL, SYMMETRIC_LOWER, SYMMETRIC_UPPER, diff --git a/module/matrix/test/test_matrix_type.cpp b/module/matrix/test/test_matrix_type.cpp index d071a71..6bd964a 100644 --- a/module/matrix/test/test_matrix_type.cpp +++ b/module/matrix/test/test_matrix_type.cpp @@ -39,10 +39,10 @@ struct A { other_moved = 0; } - inline static size_t self_copied{}; - inline static size_t self_moved{}; - inline static size_t other_copied{}; - inline static size_t other_moved{}; + inline static std::size_t self_copied{}; + inline static std::size_t self_moved{}; + inline static std::size_t other_copied{}; + inline static std::size_t other_moved{}; }; } // namespace diff --git a/module/profiling/include/oops/system_info.h b/module/profiling/include/oops/system_info.h index 3d2b4c3..46d6fca 100644 --- a/module/profiling/include/oops/system_info.h +++ b/module/profiling/include/oops/system_info.h @@ -35,21 +35,21 @@ using oops::operator|; // 支持Field和FieldMask或运算ADL // 当前只解析内存部分 struct Info { - std::optional vm_peak; - std::optional vm_size; - std::optional vm_lck; - std::optional vm_pin; - std::optional vm_hwm; - std::optional vm_rss; - std::optional rss_anon; - std::optional rss_file; - std::optional rss_shmem; - std::optional vm_data; - std::optional vm_stk; - std::optional vm_exe; - std::optional vm_lib; - std::optional vm_pte; - std::optional vm_swap; + std::optional vm_peak; + std::optional vm_size; + std::optional vm_lck; + std::optional vm_pin; + std::optional vm_hwm; + std::optional vm_rss; + std::optional rss_anon; + std::optional rss_file; + std::optional rss_shmem; + std::optional vm_data; + std::optional vm_stk; + std::optional vm_exe; + std::optional vm_lib; + std::optional vm_pte; + std::optional vm_swap; }; [[nodiscard]] Info Get(); @@ -102,11 +102,11 @@ using oops::operator|; // 支持Field和FieldMask或运算ADL struct Info { std::optional architecture; - std::optional cpus; - std::optional threads_per_core; - std::optional cores_per_socket; - std::optional sockets; - std::optional numa_nodes; + std::optional cpus; + std::optional threads_per_core; + std::optional cores_per_socket; + std::optional sockets; + std::optional numa_nodes; std::optional model_name; std::optional cpu_mhz; }; diff --git a/module/profiling/include/oops/trace.h b/module/profiling/include/oops/trace.h index 0da8121..3263112 100644 --- a/module/profiling/include/oops/trace.h +++ b/module/profiling/include/oops/trace.h @@ -88,8 +88,8 @@ namespace oops { // TARCE mask参数配置 -constexpr size_t MEM = 1; -constexpr size_t MEM_ONCE = 1ul << 1; +constexpr std::size_t MEM = 1; +constexpr std::size_t MEM_ONCE = 1ul << 1; // 全局配置 class TraceConfig { @@ -154,17 +154,17 @@ struct Memory { double GetHwmGiB() const { return 1.0 * hwm / 1024 / 1024; } double GetSwapGiB() const { return 1.0 * swap / 1024 / 1024; } - size_t rss{}; - size_t hwm{}; - size_t swap{}; + std::size_t rss{}; + std::size_t hwm{}; + std::size_t swap{}; }; struct Sample : public Location, TimeInterval, Memory {}; std::ostream &operator<<(std::ostream &out, const Sample &sample); struct Record : public Sample { - size_t count{}; // Node中获取 - size_t depth{}; // 递归时获取 + std::size_t count{}; // Node中获取 + std::size_t depth{}; // 递归时获取 }; struct RecordTable { @@ -196,7 +196,7 @@ class TraceStore { private: const void *location_id_{}; - size_t count_{}; + std::size_t count_{}; // 统计数据成员 TimeInterval time_inverval_; @@ -220,7 +220,7 @@ class TraceStore { void TraceScopeBegin(const void *location_id); void TraceScopeEnd(); - void Trace(const void *location_id, size_t mask); + void Trace(const void *location_id, std::size_t mask); void Trace(const void *location_id, const detail::TraceVaArgs &va_args); RecordTable GetRecordTable(const char *label) const; @@ -232,9 +232,9 @@ class TraceStore { void SetupSameLevelNode(const void *location_id); TimeInterval GetRootItv() const; - TimeInterval GetRecordTableImpl(int node_i, size_t depth, RecordTable &record_table) const; - Record GetRecord(const Node &node, size_t depth) const; - Record GetRecord(const TimeInterval &itv, size_t depth) const; + TimeInterval GetRecordTableImpl(int node_i, std::size_t depth, RecordTable &record_table) const; + Record GetRecord(const Node &node, std::size_t depth) const; + Record GetRecord(const TimeInterval &itv, std::size_t depth) const; std::thread::id thread_id_{std::this_thread::get_id()}; std::vector nodes_{Node{nullptr}}; @@ -267,7 +267,7 @@ class ParallelTraceStore { void TraceScopeBegin(const void *location_id) { GetLocalImpl().TraceScopeBegin(location_id); } void TraceScopeEnd() { GetLocalImpl().TraceScopeEnd(); } - void Trace(const void *location_id, size_t mask) { GetLocalImpl().Trace(location_id, mask); } + void Trace(const void *location_id, std::size_t mask) { GetLocalImpl().Trace(location_id, mask); } void Trace(const void *location_id, const detail::TraceVaArgs &va_args) { GetLocalImpl().Trace(location_id, va_args); } @@ -314,7 +314,7 @@ class TraceScope : public TraceScopeBase { // 做成类成员函数以便在编译器找到部分SCOPE和TRACE不匹配的问题 template - void Trace(Lambda &&, const char *label, const char *file, int line, size_t mask) { + void Trace(Lambda &&, const char *label, const char *file, int line, std::size_t mask) { static unsigned char location{}; thread_local unsigned char count{0}; if (is_active_) { diff --git a/module/profiling/src/system_info.cpp b/module/profiling/src/system_info.cpp index e927767..c6f9b66 100644 --- a/module/profiling/src/system_info.cpp +++ b/module/profiling/src/system_info.cpp @@ -23,7 +23,7 @@ namespace oops { // 获取命令输出 std::string GetCmdOutput(const std::string &cmd) { - std::unique_ptr p{popen(cmd.c_str(), "r"), &pclose}; + std::unique_ptr p{popen(cmd.c_str(), "r"), &pclose}; std::string output; if (!p) { return output; @@ -162,7 +162,7 @@ void OutputPairedInfo( namespace proc { namespace status { -using MemberPtrVar = std::variant Info::*>; // 定义所有类型的成员变量指针 +using MemberPtrVar = std::variant Info::*>; // 定义所有类型的成员变量指针 constexpr auto PARSE{oops::Parse}; constexpr auto FORMAT{oops::Format}; @@ -204,7 +204,7 @@ namespace numa_maps { namespace lscpu { using MemberPtrVar = std::variant< - std::optional Info::*, std::optional Info::*, + std::optional Info::*, std::optional Info::*, std::optional Info::*>; // 定义所有类型的成员变量指针 constexpr auto PARSE{oops::Parse}; constexpr auto FORMAT{oops::Format}; diff --git a/module/profiling/src/trace.cpp b/module/profiling/src/trace.cpp index 84f7504..78928b6 100644 --- a/module/profiling/src/trace.cpp +++ b/module/profiling/src/trace.cpp @@ -175,7 +175,7 @@ int TraceStore::GetOrCreateNode(int parent_i, const void *location_id) { return node_i; } } - size_t node_i{nodes_.size()}; + std::size_t node_i{nodes_.size()}; nodes_.emplace_back(location_id); nodes_[parent_i].children_.push_back(node_i); // vector::emplace_back后,parent引用可能失效 return node_i; @@ -207,7 +207,7 @@ void TraceStore::TraceScopeEnd() { node_stack_.pop_back(); } -void TraceStore::Trace(const void *location_id, size_t mask) { +void TraceStore::Trace(const void *location_id, std::size_t mask) { // 更新旧节点 Node &node{nodes_[node_stack_.back()]}; // 更新数据的节点对应的location_id没有设置过location,可能是TRACE_SCOPE for { TRACE }场景,外层应该抛异常 @@ -257,7 +257,7 @@ void TraceStore::SetupSameLevelNode(const void *location_id) { node_stack_.back() = node_i; } -Record TraceStore::GetRecord(const Node &node, size_t depth) const { +Record TraceStore::GetRecord(const Node &node, std::size_t depth) const { Record record{GetRecord(node.time_inverval_, depth)}; static_cast(record) = node.memory_; static_cast(record) = node.GetLocation(); @@ -265,7 +265,7 @@ Record TraceStore::GetRecord(const Node &node, size_t depth) const { return record; } -Record TraceStore::GetRecord(const TimeInterval &itv, size_t depth) const { +Record TraceStore::GetRecord(const TimeInterval &itv, std::size_t depth) const { Record record; record.depth = depth; record.count = 1; @@ -275,9 +275,9 @@ Record TraceStore::GetRecord(const TimeInterval &itv, size_t depth) const { RecordTable TraceStore::GetRecordTable(const char *) const { return GetRecordTable(); } -TimeInterval TraceStore::GetRecordTableImpl(int node_i, size_t depth, RecordTable &record_table) const { +TimeInterval TraceStore::GetRecordTableImpl(int node_i, std::size_t depth, RecordTable &record_table) const { const Node &node{nodes_[node_i]}; - auto traverse_children = [&](size_t depth) { + auto traverse_children = [&](std::size_t depth) { TimeInterval child_itv; for (int child_i : node.children_) { child_itv += GetRecordTableImpl(child_i, depth, record_table); diff --git a/module/profiling/test/test_trace.cpp b/module/profiling/test/test_trace.cpp index 391e164..2f8a5e0 100644 --- a/module/profiling/test/test_trace.cpp +++ b/module/profiling/test/test_trace.cpp @@ -29,12 +29,12 @@ void cpu_burn_us(uint64_t us) { } TEST(ProfilingTrace, TraceBase) { - constexpr size_t LOOP_N{10}; + constexpr std::size_t LOOP_N{10}; { TRACE_SCOPE(INFO); std::this_thread::sleep_for(std::chrono::milliseconds(100)); TRACE("step1"); - for (size_t i{0}; i < LOOP_N; ++i) { + for (std::size_t i{0}; i < LOOP_N; ++i) { TRACE_SCOPE(VERBOSE); std::this_thread::sleep_for(std::chrono::milliseconds(10)); TRACE("step2_1"); @@ -42,7 +42,7 @@ TEST(ProfilingTrace, TraceBase) { TRACE("step2_2"); } TRACE("step2"); - for (size_t i{0}; i < LOOP_N; ++i) { + for (std::size_t i{0}; i < LOOP_N; ++i) { TRACE_SCOPE(INFO); if (i % 3 == 0) { @@ -74,7 +74,7 @@ TEST(ProfilingTrace, BAD) { OOPS_TRACE_STORE::Get().Clear(); TRACE_SCOPE(INFO); Func(); - for (size_t i = 0; i < 1; ++i) { + for (std::size_t i = 0; i < 1; ++i) { TRACE_SCOPE(INFO); Func(); TRACE("FOR_DONE"); @@ -86,9 +86,9 @@ TEST(ProfilingTrace, BAD) { TEST(ProfilingTrace, InternalCost) { OOPS_TRACE_STORE::Get().Clear(); - constexpr size_t LOOP_N{10}; + constexpr std::size_t LOOP_N{10}; TRACE_SCOPE(INFO); - for (size_t i{0}; i < LOOP_N; ++i) { + for (std::size_t i{0}; i < LOOP_N; ++i) { TRACE_SCOPE(INFO); cpu_burn_us(100); TRACE("step1"); @@ -100,7 +100,7 @@ TEST(ProfilingTrace, InternalCost) { TEST(ProfilingTrace, Bad) { OOPS_TRACE_STORE::Get().Clear(); TRACE_SCOPE(INFO); - for (size_t i = 0; i < 2; ++i) { + for (std::size_t i = 0; i < 2; ++i) { try { TRACE("step1"); } catch (...) { @@ -113,7 +113,7 @@ TEST(ProfilingTrace, Bad) { TEST(ProfilingTrace, Bad2) { OOPS_TRACE_STORE::Get().Clear(); - for (size_t i = 0; i < 10; ++i) { + for (std::size_t i = 0; i < 10; ++i) { TRACE_SCOPE(INFO); if (i % 2 == 0) { TRACE("step_n0"); @@ -130,7 +130,7 @@ TEST(ProfilingTrace, Bad2) { TEST(ProfilingTrace, Bad3) { OOPS_TRACE_STORE::Get().Clear(); - for (size_t i = 0; i < 10; ++i) { + for (std::size_t i = 0; i < 10; ++i) { TRACE_SCOPE(INFO); if (i % 2 == 0) { try { @@ -181,7 +181,7 @@ TEST(ProfilingTrace, Parallel) { }; TRACE_SCOPE(INFO); std::vector threads; - for (size_t i{0}; i < 8; ++i) { + for (std::size_t i{0}; i < 8; ++i) { threads.emplace_back(func); } TRACE("Launched"); @@ -208,7 +208,7 @@ TEST(ProfilingTrace, ParallelBusy) { }; TRACE_SCOPE(INFO); std::vector threads; - for (size_t i{0}; i < 8; ++i) { + for (std::size_t i{0}; i < 8; ++i) { threads.emplace_back(func); } TRACE("Launched"); @@ -234,14 +234,14 @@ TEST(ProfilingTrace, TraceCost) { tp_time.emplace_back(); cpu_time.emplace_back(); auto t1 = std::chrono::steady_clock::now(); - for (size_t i = 0; i < 10000; ++i) { + for (std::size_t i = 0; i < 10000; ++i) { tp_time.back() = std::chrono::steady_clock::now(); cpu_time.back() = GetCpuTimePoint(); tp_time.back() = std::chrono::steady_clock::now(); cpu_time.back() = GetCpuTimePoint(); } auto t2 = std::chrono::steady_clock::now(); - for (size_t i = 0; i < 10000; ++i) { + for (std::size_t i = 0; i < 10000; ++i) { TRACE_SCOPE(INFO); TRACE("LOOP"); }