From 5e6a4f71a69ce27dae513133ee74c2551cf72fb8 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 5 Sep 2016 10:26:50 +0200 Subject: [PATCH] hugepages plugin: Run clang-format. --- src/hugepages.c | 89 ++++++++++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/src/hugepages.c b/src/hugepages.c index c3060fef..8573fc34 100644 --- a/src/hugepages.c +++ b/src/hugepages.c @@ -4,15 +4,15 @@ * * Copyright(c) 2016 Intel Corporation. All rights reserved. * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -36,8 +36,7 @@ static const char g_cfg_rpt_numa[] = "ReportPerNodeHP"; static const char g_cfg_rpt_mm[] = "ReportRootHP"; static const char *g_config_keys[] = { - g_cfg_rpt_numa, - g_cfg_rpt_mm, + g_cfg_rpt_numa, g_cfg_rpt_mm, }; static size_t g_config_keys_num = STATIC_ARRAY_SIZE(g_config_keys); static int g_flag_rpt_numa = 1; @@ -48,8 +47,7 @@ struct entry_info { const char *node; }; -static int huge_config_callback(const char *key, const char *val) -{ +static int huge_config_callback(const char *key, const char *val) { DEBUG("%s: HugePages config key='%s', val='%s'", g_plugin_name, key, val); if (strcasecmp(key, g_cfg_rpt_numa) == 0) { @@ -65,8 +63,8 @@ static int huge_config_callback(const char *key, const char *val) } static void submit_hp(const char *plug_inst, const char *type, - const char *type_instance, gauge_t free_value, gauge_t used_value) -{ + const char *type_instance, gauge_t free_value, + gauge_t used_value) { value_list_t vl = VALUE_LIST_INIT; value_t values[] = { { .gauge = free_value }, @@ -75,24 +73,23 @@ static void submit_hp(const char *plug_inst, const char *type, vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); - sstrncpy (vl.plugin, g_plugin_name, sizeof (vl.plugin)); - sstrncpy (vl.plugin_instance, plug_inst, sizeof (vl.plugin_instance)); - sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy(vl.host, hostname_g, sizeof(vl.host)); + sstrncpy(vl.plugin, g_plugin_name, sizeof(vl.plugin)); + sstrncpy(vl.plugin_instance, plug_inst, sizeof(vl.plugin_instance)); + sstrncpy(vl.type, type, sizeof(vl.type)); if (type_instance != NULL) { - sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); } DEBUG("submit_hp pl_inst:%s, inst_type %s, type %s, free=%lf, used=%lf", - plug_inst, type_instance, type, free_value, used_value); + plug_inst, type_instance, type, free_value, used_value); - plugin_dispatch_values (&vl); + plugin_dispatch_values(&vl); } static int read_hugepage_entry(const char *path, const char *entry, - void *e_info) -{ + void *e_info) { char path2[PATH_MAX]; static const char type[] = "hugepages"; static const char partial_type_inst[] = "free_used"; @@ -112,7 +109,7 @@ static int read_hugepage_entry(const char *path, const char *entry, return -1; } - if (fscanf(fh, "%lf", &value) !=1) { + if (fscanf(fh, "%lf", &value) != 1) { ERROR("%s: cannot parse file %s", g_plugin_name, path2); fclose(fh); return -1; @@ -139,10 +136,11 @@ static int read_hugepage_entry(const char *path, const char *entry, */ strin = strchr(hpsize_plinst->d_name, 0x2D); if (strin != NULL) { - ssnprintf(type_instance, sizeof(type_instance), "%s%s", partial_type_inst, strin); + ssnprintf(type_instance, sizeof(type_instance), "%s%s", partial_type_inst, + strin); } else { ssnprintf(type_instance, sizeof(type_instance), "%s%s", partial_type_inst, - hpsize_plinst->d_name); + hpsize_plinst->d_name); } submit_hp(hpsize_plinst->node, type, type_instance, free_hp, used_hp); @@ -156,8 +154,7 @@ static int read_hugepage_entry(const char *path, const char *entry, return 0; } -static int read_syshugepages(const char* path, const char* node) -{ +static int read_syshugepages(const char *path, const char *node) { static const char hugepages_dir[] = "hugepages"; DIR *dir; struct dirent *result; @@ -185,14 +182,14 @@ static int read_syshugepages(const char* path, const char* node) /* read "hugepages-XXXXXkB" entries */ while ((result = readdir(dir)) != NULL) { - if (strncmp(result->d_name, hugepages_dir, sizeof(hugepages_dir)-1)) { + if (strncmp(result->d_name, hugepages_dir, sizeof(hugepages_dir) - 1)) { /* not node dir */ errno = 0; continue; } /* /sys/devices/system/node/node?/hugepages/ */ - ssnprintf(path2, (size_t) lim, "%s/%s", path, result->d_name); + ssnprintf(path2, (size_t)lim, "%s/%s", path, result->d_name); e_info.d_name = result->d_name; e_info.node = node; @@ -202,20 +199,20 @@ static int read_syshugepages(const char* path, const char* node) /* Check if NULL return from readdir() was an error */ if (errno != 0) { - ERROR("%s: readdir failed", g_plugin_name); - closedir(dir); - return -1; + ERROR("%s: readdir failed", g_plugin_name); + closedir(dir); + return -1; } closedir(dir); return 0; } -static int read_nodes(void) -{ +static int read_nodes(void) { static const char sys_node[] = "/sys/devices/system/node"; static const char node_string[] = "node"; - static const char sys_node_hugepages[] = "/sys/devices/system/node/%s/hugepages"; + static const char sys_node_hugepages[] = + "/sys/devices/system/node/%s/hugepages"; DIR *dir; struct dirent *result; char path[PATH_MAX]; @@ -240,31 +237,29 @@ static int read_nodes(void) } while ((result = readdir(dir)) != NULL) { - if (strncmp(result->d_name, node_string, sizeof(node_string)-1)) { + if (strncmp(result->d_name, node_string, sizeof(node_string) - 1)) { /* not node dir */ errno = 0; continue; } - ssnprintf(path, (size_t) lim, sys_node_hugepages, result->d_name); + ssnprintf(path, (size_t)lim, sys_node_hugepages, result->d_name); read_syshugepages(path, result->d_name); errno = 0; } /* Check if NULL return from readdir() was an error */ if (errno != 0) { - ERROR("%s: readdir failed", g_plugin_name); - closedir(dir); - return -1; + ERROR("%s: readdir failed", g_plugin_name); + closedir(dir); + return -1; } closedir(dir); return 0; } - -static int huge_read(void) -{ +static int huge_read(void) { static const char sys_mm_hugepages[] = "/sys/kernel/mm/hugepages"; if (g_flag_rpt_mm) { @@ -281,10 +276,8 @@ static int huge_read(void) return 0; } -void module_register(void) -{ +void module_register(void) { plugin_register_config(g_plugin_name, huge_config_callback, g_config_keys, - g_config_keys_num); + g_config_keys_num); plugin_register_read(g_plugin_name, huge_read); } - -- 2.11.0