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

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 234b498  [util] add scheduling priority metric for a server
234b498 is described below

commit 234b498943c51e9801e00703ae6e2de21180919a
Author: Alexey Serbin <[email protected]>
AuthorDate: Wed Jan 12 17:14:50 2022 -0800

    [util] add scheduling priority metric for a server
    
    This patch introduces a new metric: the scheduling priority for a Kudu
    server process.  The new metric's key is "scheduling_priority" for the
    JSON output, and the value is what getpriority(PRIO_PROCESS, getpid())
    returns.  With the new metric it's possible to tell whether Kudu masters
    and tablet servers are being run with altered scheduling priority
    (e.g., using the nice/renice tools).
    
    Change-Id: I985511636a9099779a811eabe6785cf765ec04b7
    Reviewed-on: http://gerrit.cloudera.org:8080/18144
    Reviewed-by: Andrew Wong <[email protected]>
    Tested-by: Alexey Serbin <[email protected]>
---
 src/kudu/util/thread.cc | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/kudu/util/thread.cc b/src/kudu/util/thread.cc
index 1db8579..79d3e85 100644
--- a/src/kudu/util/thread.cc
+++ b/src/kudu/util/thread.cc
@@ -111,6 +111,12 @@ METRIC_DEFINE_gauge_uint64(server, 
involuntary_context_switches,
                            kudu::MetricLevel::kInfo,
                            kudu::EXPOSE_AS_COUNTER);
 
+METRIC_DEFINE_gauge_int32(server, scheduling_priority,
+                          "Scheduling Priority",
+                          kudu::MetricUnit::kState,
+                          "The scheduling priority of the process",
+                          kudu::MetricLevel::kDebug);
+
 DEFINE_int32(thread_inject_start_latency_ms, 0,
              "Number of ms to sleep when starting a new thread. (For tests).");
 TAG_FLAG(thread_inject_start_latency_ms, hidden);
@@ -142,6 +148,19 @@ static uint64_t GetInVoluntaryContextSwitches() {
   return ru.ru_nivcsw;
 }
 
+static int32_t GetSchedulingPriority() {
+  const int saved_errno = errno;
+  SCOPED_CLEANUP({
+    errno = saved_errno;
+  });
+  errno = 0;
+  int prio = getpriority(PRIO_PROCESS, getpid());
+  // No errors expected here per the manual page for the getpriority() syscall:
+  // see https://man7.org/linux/man-pages/man2/setpriority.2.html.
+  PCHECK(errno == 0);
+  return prio;
+}
+
 class ThreadMgr;
 
 __thread Thread* Thread::tls_ = nullptr;
@@ -301,6 +320,9 @@ Status ThreadMgr::StartInstrumentation(const 
scoped_refptr<MetricEntity>& metric
   metrics->NeverRetire(
       METRIC_involuntary_context_switches.InstantiateFunctionGauge(
           metrics, []() { return GetInVoluntaryContextSwitches(); }));
+  metrics->NeverRetire(
+      METRIC_scheduling_priority.InstantiateFunctionGauge(
+          metrics, []() { return GetSchedulingPriority(); }));
 
   if (web) {
     DCHECK_NOTNULL(web)->RegisterPathHandler(

Reply via email to