You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by ja...@apache.org on 2022/08/27 05:03:17 UTC

[incubator-brpc] branch master updated: fix some warnings for clang and revert changes on ALIGNAS/ALIGNOF

This is an automated email from the ASF dual-hosted git repository.

jamesge pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 261f5b23 fix some warnings for clang and revert changes on ALIGNAS/ALIGNOF
261f5b23 is described below

commit 261f5b23caf885f84374ed1f5695182d42909c3b
Author: gejun <ge...@bytedance.com>
AuthorDate: Sat Aug 27 13:03:03 2022 +0800

    fix some warnings for clang and revert changes on ALIGNAS/ALIGNOF
---
 src/brpc/builtin/hotspots_service.cpp |  5 +++--
 src/butil/compiler_specific.h         | 24 ++++++++----------------
 test/baidu_time_unittest.cpp          |  2 +-
 test/brpc_protobuf_json_unittest.cpp  |  8 --------
 test/find_cstr_unittest.cpp           |  2 +-
 test/flat_map_unittest.cpp            |  9 +++++----
 test/rand_util_unittest.cc            |  2 +-
 7 files changed, 19 insertions(+), 33 deletions(-)

diff --git a/src/brpc/builtin/hotspots_service.cpp b/src/brpc/builtin/hotspots_service.cpp
index 9d53881a..e6bb8944 100644
--- a/src/brpc/builtin/hotspots_service.cpp
+++ b/src/brpc/builtin/hotspots_service.cpp
@@ -409,7 +409,6 @@ static void DisplayResult(Controller* cntl,
     const bool show_ccount = cntl->http_request().uri().GetQuery("ccount");
     const std::string* base_name = cntl->http_request().uri().GetQuery("base");
     const std::string* display_type_query = cntl->http_request().uri().GetQuery("display_type");
-    const char* flamegraph_tool = getenv("FLAMEGRAPH_PL_PATH");
     DisplayType display_type = DisplayType::kDot;
     if (display_type_query) {
         display_type = StringToDisplayType(*display_type_query);
@@ -417,6 +416,7 @@ static void DisplayResult(Controller* cntl,
             return cntl->SetFailed(EINVAL, "Invalid display_type=%s", display_type_query->c_str());
         }
 #if defined(OS_LINUX)
+        const char* flamegraph_tool = getenv("FLAMEGRAPH_PL_PATH");
         if (display_type == DisplayType::kFlameGraph && !flamegraph_tool) {
             return cntl->SetFailed(EINVAL, "Failed to find environment variable "
                 "FLAMEGRAPH_PL_PATH, please read cpu_profiler doc"
@@ -888,7 +888,8 @@ static void StartProfiling(ProfilingType type,
             return cntl->SetFailed(EINVAL, "Invalid display_type=%s", display_type_query->c_str());
         }
 #if defined(OS_LINUX)
-        if (display_type == DisplayType::kFlameGraph && !getenv("FLAMEGRAPH_PL_PATH")) {
+        const char* flamegraph_tool = getenv("FLAMEGRAPH_PL_PATH");
+        if (display_type == DisplayType::kFlameGraph && !flamegraph_tool) {
             return cntl->SetFailed(EINVAL, "Failed to find environment variable "
                 "FLAMEGRAPH_PL_PATH, please read cpu_profiler doc"
                 "(https://github.com/brpc/brpc/blob/master/docs/cn/cpu_profiler.md)");
diff --git a/src/butil/compiler_specific.h b/src/butil/compiler_specific.h
index 9da98a4a..d05da9dc 100644
--- a/src/butil/compiler_specific.h
+++ b/src/butil/compiler_specific.h
@@ -124,14 +124,10 @@
 // Use like:
 //   class ALIGNAS(16) MyClass { ... }
 //   ALIGNAS(16) int array[4];
-#if defined(BUTIL_CXX11_ENABLED)
-# define ALIGNAS(byte_alignment) alignas(byte_alignment)
-#else
-# if defined(COMPILER_MSVC)
-#  define ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
-# elif defined(COMPILER_GCC)
-#  define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
-# endif
+#if defined(COMPILER_MSVC)
+# define ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
+#elif defined(COMPILER_GCC)
+# define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
 #endif
 
 // Return the byte alignment of the given type (available at compile time).  Use
@@ -139,14 +135,10 @@
 // http://goo.gl/isH0C
 // Use like:
 //   ALIGNOF(int32_t)  // this would be 4
-#if defined(BUTIL_CXX11_ENABLED)
-# define ALIGNOF(type) alignof(type)
-#else
-# if defined(COMPILER_MSVC)
-#  define ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
-# elif defined(COMPILER_GCC)
-#  define ALIGNOF(type) __alignof__(type)
-# endif
+#if defined(COMPILER_MSVC)
+# define ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
+#elif defined(COMPILER_GCC)
+# define ALIGNOF(type) __alignof__(type)
 #endif
 
 // Annotate a virtual method indicating it must be overriding a virtual
diff --git a/test/baidu_time_unittest.cpp b/test/baidu_time_unittest.cpp
index 4af509a3..d5741895 100644
--- a/test/baidu_time_unittest.cpp
+++ b/test/baidu_time_unittest.cpp
@@ -99,7 +99,7 @@ TEST(BaiduTimeTest, cost_of_timer) {
         s += butil::monotonic_time_ns();
     }
     t1.stop();
-    printf("monotonic_time_ns takes %" PRId64 "ns\n", t1.n_elapsed() / N);
+    printf("monotonic_time_ns takes %" PRId64 "ns s=%ld\n", t1.n_elapsed() / N, s);
 
     for (size_t i = 0; i < arraysize(clock_desc); ++i) {
 #if defined(OS_LINUX)
diff --git a/test/brpc_protobuf_json_unittest.cpp b/test/brpc_protobuf_json_unittest.cpp
index 1469f498..3565772e 100644
--- a/test/brpc_protobuf_json_unittest.cpp
+++ b/test/brpc_protobuf_json_unittest.cpp
@@ -1393,16 +1393,12 @@ TEST_F(ProtobufJsonTest, pb_to_json_complex_perf_case) {
 
     butil::Timer timer;
     bool res;
-    float avg_time1 = 0;
     float avg_time2 = 0;
     const int times = 10000;
     gss::message::gss_us_res_t data;
     json2pb::Json2PbOptions option;
     option.base64_to_bytes = false;
-    timer.start();
     res = JsonToProtoMessage(info3, &data, option, &error);
-    timer.stop();
-    avg_time1 += timer.u_elapsed();
     ASSERT_TRUE(res) << error;
     ProfilerStart("pb_to_json_complex_perf.prof");
     for (int i = 0; i < times; i++) { 
@@ -1433,16 +1429,12 @@ TEST_F(ProtobufJsonTest, pb_to_json_to_string_complex_perf_case) {
   
     butil::Timer timer;
     bool res;
-    float avg_time1 = 0;
     float avg_time2 = 0;
     const int times = 10000;
     gss::message::gss_us_res_t data;
     json2pb::Json2PbOptions option;
     option.base64_to_bytes = false;
-    timer.start();
     res = JsonToProtoMessage(info3, &data, option, &error);
-    timer.stop();
-    avg_time1 += timer.u_elapsed();
     ASSERT_TRUE(res);
     ProfilerStart("pb_to_json_to_string_complex_perf.prof");
     for (int i = 0; i < times; i++) { 
diff --git a/test/find_cstr_unittest.cpp b/test/find_cstr_unittest.cpp
index ae2a47d7..340ae0b2 100644
--- a/test/find_cstr_unittest.cpp
+++ b/test/find_cstr_unittest.cpp
@@ -91,7 +91,7 @@ TEST_F(FindCstrTest, perf) {
     tm.stop();
     int64_t elp2 = tm.n_elapsed();
 
-    LOG(INFO) << "elp1=" << elp1 / N << " elp2=" << elp2 / N;
+    LOG(INFO) << "elp1=" << elp1 / N << " elp2=" << elp2 / N << " sum=" << sum;
 }
 
 }
diff --git a/test/flat_map_unittest.cpp b/test/flat_map_unittest.cpp
index b8f0372d..ac1b9bb6 100644
--- a/test/flat_map_unittest.cpp
+++ b/test/flat_map_unittest.cpp
@@ -237,7 +237,7 @@ TEST_F(FlatMapTest, __builtin_ctzl_perf) {
         s += __builtin_ctzl(i);
     }
     tm1.stop();
-    LOG(INFO) << "__builtin_ctzl takes " << tm1.n_elapsed()/(double)N << "ns";
+    LOG(INFO) << "__builtin_ctzl takes " << tm1.n_elapsed()/(double)N << "ns s=" << s;
 }
 
 TEST_F(FlatMapTest, case_ignored_map) {
@@ -408,7 +408,7 @@ TEST_F(FlatMapTest, flat_map_of_string) {
 
     LOG(INFO) << "finding c_strings takes " << tm1.n_elapsed()/N
               << " " << tm2.n_elapsed()/N << " " << tm3.n_elapsed()/N
-              << " " << tm1_2.n_elapsed()/N;
+              << " " << tm1_2.n_elapsed()/N << " sum=" << sum;
     
     for (size_t i = 0; i < N; ++i) {
         ASSERT_EQ(i, m1[keys[i]]) << "i=" << i;
@@ -796,7 +796,7 @@ TEST_F(FlatMapTest, perf_cmp_with_map_storing_pointers) {
         sum += (m3.find(r[i]) != m3.end());
     }
     tm.stop();
-    LOG(INFO) << "std::set takes " << tm.n_elapsed()/r.size();
+    LOG(INFO) << "std::set takes " << tm.n_elapsed()/r.size() << " sum=" << sum;
 
     for (size_t i = 0; i < ARRAY_SIZE(ptr); ++i) {
         delete ptr[i];
@@ -1265,7 +1265,8 @@ template <typename T> void perf_seek(const T& value) {
                   << id_tm.n_elapsed() / keys.size()
                   << "/" << std_tm.n_elapsed() / keys.size()
                   << "/" << pooled_tm.n_elapsed() / keys.size()
-                  << "/" << hash_tm.n_elapsed() / keys.size();
+                  << "/" << hash_tm.n_elapsed() / keys.size()
+                  << " sum=" << sum;
     }
 }
 
diff --git a/test/rand_util_unittest.cc b/test/rand_util_unittest.cc
index 17891c3a..eba1842d 100644
--- a/test/rand_util_unittest.cc
+++ b/test/rand_util_unittest.cc
@@ -209,7 +209,7 @@ TEST(RandUtilTest, fast_rand_perf) {
     }
     tm.stop();
     LOG(INFO) << "Each fast_rand_less_than took " << tm.n_elapsed() / kTestIterations
-              << " ns, "
+              << " ns, s=" << s
 #if !defined(NDEBUG)
               << " (debugging version)";
 #else


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org