فهرست منبع

cmapctl: Add option to clear the stats

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
Christine Caulfield 8 سال پیش
والد
کامیت
b3c62c160d
2فایلهای تغییر یافته به همراه34 افزوده شده و 1 حذف شده
  1. 3 0
      man/corosync-cmapctl.8
  2. 31 1
      tools/corosync-cmapctl.c

+ 3 - 0
man/corosync-cmapctl.8

@@ -87,6 +87,9 @@ corosync\-cmapctl [\-b] \fB\-t\fR key_name
 .SS "Track changes on keys with key prefix:"
 .SS "Track changes on keys with key prefix:"
 .IP
 .IP
 corosync\-cmapctl [\-b] \fB\-T\fR key_prefix
 corosync\-cmapctl [\-b] \fB\-T\fR key_prefix
+.SS "Clear statistics (-mstats is implied)"
+.IP
+corosync\-cmapctl \fB\-C\fR [ipc|totem|knet|all]
 
 
 .SH "SEE ALSO"
 .SH "SEE ALSO"
 .BR cmap_overview (8),
 .BR cmap_overview (8),

+ 31 - 1
tools/corosync-cmapctl.c

@@ -56,6 +56,7 @@ enum user_action {
 	ACTION_PRINT_PREFIX,
 	ACTION_PRINT_PREFIX,
 	ACTION_TRACK,
 	ACTION_TRACK,
 	ACTION_LOAD,
 	ACTION_LOAD,
+	ACTION_CLEARSTATS,
 };
 };
 
 
 struct name_to_type_item {
 struct name_to_type_item {
@@ -739,6 +740,14 @@ static void read_in_config_file(cmap_handle_t handle, char * filename)
 	fclose (fh);
 	fclose (fh);
 }
 }
 
 
+static void clear_stats(cmap_handle_t handle, char *clear_opt)
+{
+	char key_name[CMAP_KEYNAME_MAXLEN + 1];
+
+	sprintf(key_name, "stats.clear.%s", clear_opt);
+	cmap_set_uint32(handle, key_name, 1);
+}
+
 int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 {
 	enum user_action action;
 	enum user_action action;
@@ -752,12 +761,13 @@ int main(int argc, char *argv[])
 	int track_prefix;
 	int track_prefix;
 	int map_set = 0;
 	int map_set = 0;
 	int no_retries;
 	int no_retries;
+	char * clear_opt = NULL;
 	char * settings_file = NULL;
 	char * settings_file = NULL;
 
 
 	action = ACTION_PRINT_PREFIX;
 	action = ACTION_PRINT_PREFIX;
 	track_prefix = 1;
 	track_prefix = 1;
 
 
-	while ((c = getopt(argc, argv, "m:hgsdDtTbp:")) != -1) {
+	while ((c = getopt(argc, argv, "m:hgsdDtTbp:C:")) != -1) {
 		switch (c) {
 		switch (c) {
 		case 'h':
 		case 'h':
 			return print_help();
 			return print_help();
@@ -781,6 +791,22 @@ int main(int argc, char *argv[])
 			settings_file = optarg;
 			settings_file = optarg;
 			action = ACTION_LOAD;
 			action = ACTION_LOAD;
 			break;
 			break;
+		case 'C':
+			if (strcmp(optarg, "knet") == 0 ||
+			    strcmp(optarg, "totem") == 0 ||
+			    strcmp(optarg, "ipc") == 0 ||
+			    strcmp(optarg, "all") == 0) {
+				action = ACTION_CLEARSTATS;
+				clear_opt = optarg;
+
+				/* Force the map to be STATS */
+				map = CMAP_MAP_STATS;
+			}
+			else {
+				fprintf(stderr, "argument to -C should be 'knet', 'totem', 'ipc' or 'all'\n");
+				return (EXIT_FAILURE);
+			}
+			break;
 		case 't':
 		case 't':
 			action = ACTION_TRACK;
 			action = ACTION_TRACK;
 			track_prefix = 0;
 			track_prefix = 0;
@@ -817,6 +843,7 @@ int main(int argc, char *argv[])
 
 
 	if (argc == 0 &&
 	if (argc == 0 &&
 	    action != ACTION_LOAD &&
 	    action != ACTION_LOAD &&
+	    action != ACTION_CLEARSTATS &&
 	    action != ACTION_PRINT_PREFIX) {
 	    action != ACTION_PRINT_PREFIX) {
 		fprintf(stderr, "Expected key after options\n");
 		fprintf(stderr, "Expected key after options\n");
 		return (EXIT_FAILURE);
 		return (EXIT_FAILURE);
@@ -883,6 +910,9 @@ int main(int argc, char *argv[])
 
 
 		set_key(handle, argv[0], argv[1], argv[2]);
 		set_key(handle, argv[0], argv[1], argv[2]);
 		break;
 		break;
+	case ACTION_CLEARSTATS:
+		clear_stats(handle, clear_opt);
+		break;
 
 
 	}
 	}