]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
utils_proc_pids: moved to utils directory
authorAleksinski, MichalX <michalx.aleksinski@intel.com>
Wed, 20 Feb 2019 12:32:50 +0000 (12:32 +0000)
committerAleksinski, MichalX <michalx.aleksinski@intel.com>
Wed, 6 Mar 2019 07:04:16 +0000 (07:04 +0000)
Change-Id: Ia7c9bf5dca2b871b05c9ed3876059e6d34bd943e

Makefile.am
src/intel_rdt.c
src/utils/proc_pids/proc_pids.c [moved from src/utils_proc_pids.c with 84% similarity]
src/utils/proc_pids/proc_pids.h [moved from src/utils_proc_pids.h with 79% similarity]
src/utils/proc_pids/proc_pids_test.c [moved from src/utils_proc_pids_test.c with 94% similarity]

index b4195c1353674189750e0a446aad4b594b9d6131..7a64fbfdb14bd3eeb7e3c8437cecd544014a519f 100644 (file)
@@ -378,7 +378,7 @@ test_utils_config_cores_SOURCES = \
 test_utils_config_cores_LDADD = libplugin_mock.la
 
 test_utils_proc_pids_SOURCES = \
-       src/utils_proc_pids_test.c \
+       src/utils/proc_pids/proc_pids_test.c \
        src/testing.h
 test_utils_proc_pids_LDADD = libplugin_mock.la
 
@@ -1071,8 +1071,8 @@ if BUILD_PLUGIN_INTEL_RDT
 pkglib_LTLIBRARIES += intel_rdt.la
 intel_rdt_la_SOURCES = \
        src/intel_rdt.c \
-       src/utils_proc_pids.c \
-       src/utils_proc_pids.h \
+       src/utils/proc_pids/proc_pids.c \
+       src/utils/proc_pids/proc_pids.h \
        src/utils/config_cores/config_cores.h \
        src/utils/config_cores/config_cores.c
 intel_rdt_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBPQOS_CPPFLAGS)
@@ -1082,7 +1082,7 @@ intel_rdt_la_LIBADD = $(BUILD_WITH_LIBPQOS_LIBS)
 test_plugin_intel_rdt_SOURCES = \
        src/intel_rdt_test.c \
        src/utils/config_cores/config_cores.c \
-       src/utils_proc_pids.c \
+       src/utils/proc_pids/proc_pids.c \
        src/daemon/configfile.c \
        src/daemon/types_list.c
 test_plugin_intel_rdt_CPPFLAGS = $(AM_CPPFLAGS)
index 736482082f06555ae3dcde3f502d228d14886c2a..003f71abd0027468b2dfad7182b7195f7a5d2d99 100644 (file)
@@ -31,7 +31,7 @@
 #include "collectd.h"
 #include "utils/common/common.h"
 #include "utils/config_cores/config_cores.h"
-#include "utils_proc_pids.h"
+#include "utils/proc_pids/proc_pids.h"
 #include <pqos.h>
 
 #define RDT_PLUGIN "intel_rdt"
@@ -526,7 +526,7 @@ static int rdt_config_ngroups(rdt_ctx_t *rdt, const oconfig_item_t *item) {
          name_idx++) {
       DEBUG(RDT_PLUGIN ":    checking process name [%zu]: %s", name_idx,
             rdt->ngroups[group_idx].names[name_idx]);
-      if (!is_proc_name_valid(rdt->ngroups[group_idx].names[name_idx])) {
+      if (!proc_pids_is_name_valid(rdt->ngroups[group_idx].names[name_idx])) {
         ERROR(RDT_PLUGIN ": Process name group '%s' contains invalid name '%s'",
               rdt->ngroups[group_idx].desc,
               rdt->ngroups[group_idx].names[name_idx]);
@@ -798,7 +798,7 @@ static int read_pids_data() {
 #endif /* COLLECT_DEBUG */
 
 groups_refresh:
-  ret = update_proc_pids(RDT_PROC_PATH, g_rdt->proc_pids, g_rdt->num_proc_pids);
+  ret = proc_pids_update(RDT_PROC_PATH, g_rdt->proc_pids, g_rdt->num_proc_pids);
   if (0 != ret) {
     ERROR(RDT_PLUGIN ": Initial update of proc pids failed");
     return ret;
@@ -839,8 +839,8 @@ static void rdt_init_pids_monitoring() {
      * PIDs statistics detection.
      */
     rdt_name_group_t *ng = &g_rdt->ngroups[group_idx];
-    int init_result = initialize_proc_pids((const char **)ng->names,
-                                           ng->num_names, &ng->proc_pids);
+    int init_result =
+        proc_pids_init((const char **)ng->names, ng->num_names, &ng->proc_pids);
     if (0 != init_result) {
       ERROR(RDT_PLUGIN
             ": Initialization of proc_pids for group %zu failed. Error: %d",
@@ -865,7 +865,7 @@ static void rdt_init_pids_monitoring() {
   }
 
   int update_result =
-      update_proc_pids(RDT_PROC_PATH, g_rdt->proc_pids, g_rdt->num_proc_pids);
+      proc_pids_update(RDT_PROC_PATH, g_rdt->proc_pids, g_rdt->num_proc_pids);
   if (0 != update_result)
     ERROR(RDT_PLUGIN ": Initial update of proc pids failed");
 
similarity index 84%
rename from src/utils_proc_pids.c
rename to src/utils/proc_pids/proc_pids.c
index 0fbea530f969874ae4978471e4b013d43f00ec4e..336a9964410584682eb8417c15c77ce2912f7425 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * collectd - src/utils_config_pids.c
+ * collectd - src/utils/proc_pids/proc_pids.c
  *
  * Copyright(c) 2018-2019 Intel Corporation. All rights reserved.
  *
@@ -29,7 +29,7 @@
 
 #include "collectd.h"
 #include "utils/common/common.h"
-#include "utils_proc_pids.h"
+#include "utils/proc_pids/proc_pids.h"
 
 #define UTIL_NAME "utils_proc_pids"
 
@@ -40,7 +40,7 @@ void pids_list_free(pids_list_t *list) {
   sfree(list);
 }
 
-int is_proc_name_valid(const char *name) {
+int proc_pids_is_name_valid(const char *name) {
 
   if (name != NULL) {
     unsigned len = strlen(name);
@@ -123,8 +123,27 @@ int pids_list_contains_pid(pids_list_t *list, const pid_t pid) {
   return 0;
 }
 
-int read_proc_name(const char *procfs_path, const struct dirent *pid_entry,
-                   char *name, const size_t out_size) {
+/*
+ * NAME
+ *   read_proc_name
+ *
+ * DESCRIPTION
+ *   Reads process name from given pid directory.
+ *   Strips new-line character (\n).
+ *
+ * PARAMETERS
+ *   `procfs_path' Path to systems proc directory (e.g. /proc)
+ *   `pid_entry'   Dirent for PID directory
+ *   `name'        Output buffer for process name, recommended proc_comm.
+ *   `out_size'    Output buffer size, recommended sizeof(proc_comm)
+ *
+ * RETURN VALUE
+ *   On success, the number of read bytes (includes stripped \n).
+ *   -1 on file open error
+*/
+static int read_proc_name(const char *procfs_path,
+                          const struct dirent *pid_entry, char *name,
+                          const size_t out_size) {
   assert(pid_entry);
   assert(name);
   assert(out_size);
@@ -155,7 +174,22 @@ int read_proc_name(const char *procfs_path, const struct dirent *pid_entry,
   return read_length;
 }
 
-int get_pid_number(struct dirent *entry, pid_t *pid) {
+/*
+ * NAME
+ *   get_pid_number
+ *
+ * DESCRIPTION
+ *   Gets pid number for given /proc/pid directory entry or
+ *   returns error if input directory does not hold PID information.
+ *
+ * PARAMETERS
+ *   `entry'    Dirent for PID directory
+ *   `pid'      PID number to be filled
+ *
+ * RETURN VALUE
+ *   0 on success. -1 on error.
+ */
+static int get_pid_number(struct dirent *entry, pid_t *pid) {
   char *tmp_end; /* used for strtoul error check*/
 
   if (pid == NULL || entry == NULL)
@@ -173,9 +207,9 @@ int get_pid_number(struct dirent *entry, pid_t *pid) {
   return 0;
 }
 
-int initialize_proc_pids(const char **procs_names_array,
-                         const size_t procs_names_array_size,
-                         proc_pids_t **proc_pids[]) {
+int proc_pids_init(const char **procs_names_array,
+                   const size_t procs_names_array_size,
+                   proc_pids_t **proc_pids[]) {
 
   proc_pids_t **proc_pids_array;
   assert(proc_pids);
@@ -190,7 +224,7 @@ int initialize_proc_pids(const char **procs_names_array,
   for (size_t i = 0; i < procs_names_array_size; ++i) {
     proc_pids_array[i] = calloc(1, sizeof(**proc_pids_array));
     if (NULL == proc_pids_array[i])
-      goto initialize_proc_pids_error;
+      goto proc_pids_init_error;
 
     sstrncpy(proc_pids_array[i]->process_name, procs_names_array[i],
              STATIC_ARRAY_SIZE(proc_pids_array[i]->process_name));
@@ -201,7 +235,7 @@ int initialize_proc_pids(const char **procs_names_array,
   *proc_pids = proc_pids_array;
 
   return 0;
-initialize_proc_pids_error:
+proc_pids_init_error:
   if (NULL != proc_pids_array) {
     for (size_t i = 0; i < procs_names_array_size; ++i) {
       free(proc_pids_array[i]);
@@ -219,7 +253,7 @@ static void swap_proc_pids(proc_pids_t **proc_pids, size_t proc_pids_num) {
   }
 }
 
-int update_proc_pids(const char *procfs_path, proc_pids_t **proc_pids,
+int proc_pids_update(const char *procfs_path, proc_pids_t **proc_pids,
                      size_t proc_pids_num) {
   assert(procfs_path);
   assert(proc_pids);
similarity index 79%
rename from src/utils_proc_pids.h
rename to src/utils/proc_pids/proc_pids.h
index a2a668dda6b5b69d7e24154bfec4116208d3b38a..8b19497c21c0724ea35c8ae5dce8ed22c0439b11 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * collectd - src/utils_config_pids.h
+ * collectd - src/utils/proc_pids/proc_pids.h
  *
  * Copyright(c) 2018-2019 Intel Corporation. All rights reserved.
  *
@@ -67,22 +67,6 @@ typedef struct proc_pids_s {
  */
 void pids_list_free(pids_list_t *list);
 
-/*
- * NAME
- *   is_proc_name_valid
- *
- * DESCRIPTION
- *   Checks if given string as valid process name.
- *
- * PARAMETERS
- *   `name'     null-terminated char array
- *
- * RETURN VALUE
- *   If given name is a valid process name, returns 1,
- *   Otherwise returns 0.
- */
-int is_proc_name_valid(const char *name);
-
 /*
  * NAME
  *   pids_list_add_pid
@@ -132,7 +116,6 @@ int pids_list_clear(pids_list_t *list);
  *   On success, returns 0.
  *   -1 on memory allocation error.
  */
-#
 int pids_list_add_list(pids_list_t *dst, pids_list_t *src);
 
 /*
@@ -154,45 +137,39 @@ int pids_list_contains_pid(pids_list_t *list, const pid_t pid);
 
 /*
  * NAME
- *   read_proc_name
+ *   pids_list_diff
  *
  * DESCRIPTION
- *   Reads process name from given pid directory.
- *   Strips new-line character (\n).
+ *   Searches for differences in two given lists
  *
  * PARAMETERS
- *   `procfs_path' Path to systems proc directory (e.g. /proc)
- *   `pid_entry'   Dirent for PID directory
- *   `name'        Output buffer for process name, recommended proc_comm.
- *   `out_size'    Output buffer size, recommended sizeof(proc_comm)
- *
+ *   `proc'            List of pids
+ *   `added'           New pids which appeared
+ *   `removed'         Result array storing pids which disappeared
  * RETURN VALUE
- *   On success, the number of read bytes (includes stripped \n).
- *   -1 on file open error
+ *   0 on success. Negative number on error.
  */
-int read_proc_name(const char *procfs_path, const struct dirent *pid_entry,
-                   char *name, const size_t out_size);
+int pids_list_diff(proc_pids_t *proc, pids_list_t *added, pids_list_t *removed);
 
 /*
  * NAME
- *   get_pid_number
+ *   proc_pids_is_name_valid
  *
  * DESCRIPTION
- *   Gets pid number for given /proc/pid directory entry or
- *   returns error if input directory does not hold PID information.
+ *   Checks if given string is valid process name.
  *
  * PARAMETERS
- *   `entry'    Dirent for PID directory
- *   `pid'      PID number to be filled
+ *   `name'     null-terminated char array
  *
  * RETURN VALUE
- *   0 on success. -1 on error.
+ *   If given name is a valid process name, returns 1,
+ *   Otherwise returns 0.
  */
-int get_pid_number(struct dirent *entry, pid_t *pid);
+int proc_pids_is_name_valid(const char *name);
 
 /*
  * NAME
- *   initialize_proc_pids
+ *   proc_pids_init
  *
  * DESCRIPTION
  *   Helper function to properly initialize array of proc_pids.
@@ -209,13 +186,13 @@ int get_pid_number(struct dirent *entry, pid_t *pid);
  *   0 on success. Negative number on error:
  *   -1: allocation error
  */
-int initialize_proc_pids(const char **procs_names_array,
-                         const size_t procs_names_array_size,
-                         proc_pids_t **proc_pids[]);
+int proc_pids_init(const char **procs_names_array,
+                   const size_t procs_names_array_size,
+                   proc_pids_t **proc_pids[]);
 
 /*
  * NAME
- *   update_proc_pids
+ *   proc_pids_update
  *
  * DESCRIPTION
  *   Updates PIDs matching processes's names.
@@ -229,25 +206,9 @@ int initialize_proc_pids(const char **procs_names_array,
  * RETURN VALUE
  *   0 on success. -1 on error.
  */
-int update_proc_pids(const char *procfs_path, proc_pids_t *proc_pids[],
+int proc_pids_update(const char *procfs_path, proc_pids_t *proc_pids[],
                      size_t proc_pids_num);
 
-/*
- * NAME
- *   pids_list_diff
- *
- * DESCRIPTION
- *   Searches for differences in two given lists
- *
- * PARAMETERS
- *   `proc'            List of pids
- *   `added'           New pids which appeared
- *   `removed'         Result array storing pids which disappeared
- * RETURN VALUE
- *   0 on success. Negative number on error.
- */
-int pids_list_diff(proc_pids_t *proc, pids_list_t *added, pids_list_t *removed);
-
 /*
  * NAME
  *   proc_pids_free
similarity index 94%
rename from src/utils_proc_pids_test.c
rename to src/utils/proc_pids/proc_pids_test.c
index 21c8b34968530c9d2a1b81d6d712a06cc31ba63f..06b8d39b8cdc10e94907ee14ba646a825747d5da 100644 (file)
@@ -1,5 +1,5 @@
 #include "testing.h"
-#include "utils_proc_pids.c" /* sic */
+#include "utils/proc_pids/proc_pids.c" /* sic */
 #include <sys/stat.h>
 
 /***************************************************************************
@@ -88,15 +88,15 @@ int stub_procfs_teardown() {
 /***************************************************************************
  * tests
  */
-DEF_TEST(initialize_proc_pids__on_nullptr) {
+DEF_TEST(proc_pids_init__on_nullptr) {
   /* setup */
   const char *procs_names_array[] = {"proc1", "proc2", "proc3"};
   const size_t procs_names_array_size = STATIC_ARRAY_SIZE(procs_names_array);
   proc_pids_t **proc_pids_array = NULL;
 
   /* check */
-  int result = initialize_proc_pids(procs_names_array, procs_names_array_size,
-                                    &proc_pids_array);
+  int result = proc_pids_init(procs_names_array, procs_names_array_size,
+                              &proc_pids_array);
   EXPECT_EQ_INT(0, result);
   for (size_t i = 0; i < procs_names_array_size; ++i)
     EXPECT_EQ_STR(procs_names_array[i], proc_pids_array[i]->process_name);
@@ -259,7 +259,7 @@ DEF_TEST(read_proc_name__invalid_name) {
   return 0;
 }
 
-DEF_TEST(update_proc_pids__one_proc_many_pid) {
+DEF_TEST(proc_pids_update__one_proc_many_pid) {
   /* setup */
   const char *proc_names[] = {"proc1"};
   stub_proc_pid_t pp_stubs[] = {{"proc1", 1007},
@@ -271,12 +271,12 @@ DEF_TEST(update_proc_pids__one_proc_many_pid) {
   int result;
   stub_procfs_setup(pp_stubs, STATIC_ARRAY_SIZE(pp_stubs));
 
-  result = initialize_proc_pids(proc_names, STATIC_ARRAY_SIZE(proc_names),
-                                &proc_pids);
+  result =
+      proc_pids_init(proc_names, STATIC_ARRAY_SIZE(proc_names), &proc_pids);
   EXPECT_EQ_INT(0, result);
 
   /* check */
-  result = update_proc_pids(proc_fs, proc_pids, STATIC_ARRAY_SIZE(proc_names));
+  result = proc_pids_update(proc_fs, proc_pids, STATIC_ARRAY_SIZE(proc_names));
   EXPECT_EQ_INT(0, result);
 
   /* proc name check */
@@ -299,7 +299,7 @@ DEF_TEST(update_proc_pids__one_proc_many_pid) {
   return 0;
 }
 
-DEF_TEST(update_proc_pids__many_proc_many_pid) {
+DEF_TEST(proc_pids_update__many_proc_many_pid) {
   /* setup */
   const char *proc_names[] = {"proc1", "proc2", "proc3"};
   stub_proc_pid_t pp_stubs[] = {
@@ -311,12 +311,12 @@ DEF_TEST(update_proc_pids__many_proc_many_pid) {
   int result;
   stub_procfs_setup(pp_stubs, STATIC_ARRAY_SIZE(pp_stubs));
 
-  result = initialize_proc_pids(proc_names, STATIC_ARRAY_SIZE(proc_names),
-                                &proc_pids);
+  result =
+      proc_pids_init(proc_names, STATIC_ARRAY_SIZE(proc_names), &proc_pids);
   EXPECT_EQ_INT(0, result);
 
   /* check */
-  result = update_proc_pids(proc_fs, proc_pids, STATIC_ARRAY_SIZE(proc_names));
+  result = proc_pids_update(proc_fs, proc_pids, STATIC_ARRAY_SIZE(proc_names));
   EXPECT_EQ_INT(0, result);
 
   for (size_t i = 0; i < STATIC_ARRAY_SIZE(proc_names); ++i) {
@@ -485,7 +485,7 @@ DEF_TEST(pids_list_diff__one_removed) {
 
 int main(void) {
   stub_procfs_teardown();
-  RUN_TEST(initialize_proc_pids__on_nullptr);
+  RUN_TEST(proc_pids_init__on_nullptr);
   RUN_TEST(pid_list_add_pid__empty_list);
   RUN_TEST(pid_list_add_pid__non_empty_list);
   RUN_TEST(pids_list_add_pids_list__non_empty_lists);
@@ -494,8 +494,8 @@ int main(void) {
   RUN_TEST(get_pid_number__invalid_dir_name);
   RUN_TEST(read_proc_name__valid_name);
   RUN_TEST(read_proc_name__invalid_name);
-  RUN_TEST(update_proc_pids__one_proc_many_pid);
-  RUN_TEST(update_proc_pids__many_proc_many_pid);
+  RUN_TEST(proc_pids_update__one_proc_many_pid);
+  RUN_TEST(proc_pids_update__many_proc_many_pid);
   RUN_TEST(pids_list_diff__all_changed);
   RUN_TEST(pids_list_diff__nothing_changed);
   RUN_TEST(pids_list_diff__one_added);