You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by wa...@apache.org on 2023/06/21 04:24:48 UTC

[incubator-pegasus] 35/38: fix(new_metrics): profiled tasks are measured by the wrong metrics (#1528)

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

wangdan pushed a commit to branch migrate-metrics-dev
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git

commit d238f5e5f072fbcdc2ce6198550df90d05fa11b7
Author: Dan Wang <wa...@apache.org>
AuthorDate: Tue Jun 13 11:50:10 2023 +0800

    fix(new_metrics): profiled tasks are measured by the wrong metrics (#1528)
    
    https://github.com/apache/incubator-pegasus/issues/1527
    
    Maintained in an array that includes all of the profilers, each profiler is
    indexed and accessed by its task code. Therefore, `TASK_CODE_INVALID`,
    albeit meaningless, should also be pushed into this array; otherwise, all
    of the profiled tasks would be indexed by the wrong task code, then also
    measured by the wrong metrics.
---
 src/runtime/profiler.cpp      | 17 +++++++++++++++++
 src/runtime/profiler_header.h |  1 +
 2 files changed, 18 insertions(+)

diff --git a/src/runtime/profiler.cpp b/src/runtime/profiler.cpp
index b506d11ea..1a6a2bb7b 100644
--- a/src/runtime/profiler.cpp
+++ b/src/runtime/profiler.cpp
@@ -398,6 +398,13 @@ task_spec_profiler::task_spec_profiler(int code)
         return;
     }
 
+    LOG_INFO("register task into profiler: task_code={}, task_name={}, section_name={}, "
+             "task_type={}",
+             code,
+             _task_name,
+             section_name,
+             enum_to_string(spec->type));
+
     if (dsn_config_get_value_bool(
             section_name.c_str(),
             "profiler::inqueue",
@@ -512,13 +519,23 @@ void profiler::install(service_spec &)
     task_ext_for_profiler::register_ext();
     message_ext_for_profiler::register_ext();
 
+    s_spec_profilers.clear();
+    s_spec_profilers.reserve(s_task_code_max + 1);
+    LOG_INFO("begin to choose the tasks that will be registered into profilers among "
+             "all of the {} tasks",
+             s_task_code_max + 1);
     for (int code = 0; code <= s_task_code_max; ++code) {
         if (code == TASK_CODE_INVALID) {
+            // Though the task code `TASK_CODE_INVALID` is meaningless, it should still be pushed
+            // into the `s_spec_profilers` by default constructor of `task_spec_profiler`, since
+            // `task_spec_profiler` is indexed by the task code in `s_spec_profilers`.
+            s_spec_profilers.emplace_back();
             continue;
         }
 
         s_spec_profilers.emplace_back(code);
     }
+    CHECK_EQ(s_spec_profilers.size(), s_task_code_max + 1);
 }
 
 profiler::profiler(const char *name) : toollet(name) {}
diff --git a/src/runtime/profiler_header.h b/src/runtime/profiler_header.h
index a32935804..2507503ec 100644
--- a/src/runtime/profiler_header.h
+++ b/src/runtime/profiler_header.h
@@ -40,6 +40,7 @@ struct task_spec_profiler
     bool is_profile;
     std::unique_ptr<std::atomic<int64_t>[]> call_counts;
 
+    task_spec_profiler() = default;
     task_spec_profiler(int code);
     const metric_entity_ptr &profiler_metric_entity() const;
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org