On 03/24/10 18:52, Andrew Beekhof wrote:
> On Wed, Mar 24, 2010 at 10:02 AM, Yan Gao <y...@novell.com> wrote:
>> Hi,
>> A suggestion/request was raised with regard to the utilization feature:
>> The ability to see the remaining capacity of nodes, and how the load is
>> distributed right now.
>>
>> I've added a new option "--show-utilization" of ptest to achieve that.
> 
> Could you make the short option -U and add it to crm_simulate too please?
Done and attached.

> 
>> Attached the patch. Please help review it. Thanks a lot!
>>
>> btw, because the following change:
>> http://hg.clusterlabs.org/pacemaker/1.1/rev/c23bbc5262b2
>>
>> was only merged into 1.1 branch. The attached patch depends on that, so
>> it cannot be applied to devel branch by now. Will they be merged into
>> devel branch later, or is there any consideration?
> 
> I just tried to merge them in but there were conflicts in the shell directory.
> I've asked Dejan to take a look so that I don't break anything.
OK, thanks!

Regards,
  Yan
-- 
Yan Gao <y...@novell.com>
Software Engineer
China Server Team, OPS Engineering, Novell, Inc.
# HG changeset patch
# User Yan Gao <y...@novell.com>
# Date 1269433522 -28800
# Node ID 4ba915f5236077a2480e6f5a8584eda5e2c8b1a0
# Parent  53be04557e146ab4e600fc6e3d1700181fee8f8a
Dev: PE: (bnc#589873) Show utilization/capacity information

diff -r 53be04557e14 -r 4ba915f52360 lib/pengine/utils.c
--- a/lib/pengine/utils.c	Tue Mar 23 17:15:22 2010 +0100
+++ b/lib/pengine/utils.c	Wed Mar 24 20:25:22 2010 +0800
@@ -388,6 +388,64 @@
     }
 }
 
+static void
+append_dump_text(gpointer key, gpointer value, gpointer user_data)
+{
+    char **dump_text = user_data;
+    int len = 0;
+    char *new_text = NULL;
+
+    len = strlen(*dump_text) + strlen(" ") + strlen(key) + strlen("=") + strlen(value) + 1;
+    crm_malloc0(new_text, len);
+    sprintf(new_text, "%s %s=%s", *dump_text, (char *)key, (char *)value);
+
+    free(*dump_text);
+    *dump_text = new_text;
+}
+
+void
+dump_node_capacity(int level, const char *comment, node_t *node)
+{
+    int len = 0;
+    char *dump_text = NULL;
+
+    len = strlen(comment) + strlen(": ") + strlen(node->details->uname) + strlen(" capacity:") + 1;
+    crm_malloc0(dump_text, len);
+    sprintf(dump_text, "%s: %s capacity:", comment, node->details->uname);
+	
+    g_hash_table_foreach(node->details->utilization, append_dump_text, &dump_text);
+
+    if(level == 0) {
+	fprintf(stdout, "%s\n", dump_text);
+    } else {
+	do_crm_log_unlikely(level, "%s", dump_text);
+    }
+
+    crm_free(dump_text);
+}
+
+void
+dump_rsc_utilization(int level, const char *comment, resource_t *rsc, node_t *node) 
+{
+    int len = 0;
+    char *dump_text = NULL;
+
+    len = strlen(comment) + strlen(": ") + strlen(rsc->id) + strlen(" utilization on ")
+	    + strlen(node->details->uname) + strlen(":") + 1;
+    crm_malloc0(dump_text, len);
+    sprintf(dump_text, "%s: %s utilization on %s:", comment, rsc->id, node->details->uname);
+
+    g_hash_table_foreach(rsc->utilization, append_dump_text, &dump_text);
+
+    if(level == 0) {
+	fprintf(stdout, "%s\n", dump_text);
+    } else {
+	do_crm_log_unlikely(level, "%s", dump_text);
+    }
+
+    crm_free(dump_text);
+}
+
 gint sort_rsc_index(gconstpointer a, gconstpointer b)
 {
 	const resource_t *resource1 = (const resource_t*)a;
diff -r 53be04557e14 -r 4ba915f52360 lib/pengine/utils.h
--- a/lib/pengine/utils.h	Tue Mar 23 17:15:22 2010 +0100
+++ b/lib/pengine/utils.h	Wed Mar 24 20:25:22 2010 +0800
@@ -54,6 +54,9 @@
 
 extern void dump_node_scores(int level, resource_t *rsc, const char *comment, GListPtr nodes);
 
+extern void dump_node_capacity(int level, const char *comment, node_t *node);
+extern void dump_rsc_utilization(int level, const char *comment, resource_t *rsc, node_t *node);
+
 /* Sorting functions */
 extern gint sort_rsc_priority(gconstpointer a, gconstpointer b);
 extern gint sort_rsc_index(gconstpointer a, gconstpointer b);
diff -r 53be04557e14 -r 4ba915f52360 pengine/allocate.c
--- a/pengine/allocate.c	Tue Mar 23 17:15:22 2010 +0100
+++ b/pengine/allocate.c	Wed Mar 24 20:25:22 2010 +0800
@@ -835,12 +835,22 @@
 gboolean
 stage5(pe_working_set_t *data_set)
 {
+	slist_iter(
+		node, node_t, data_set->nodes, lpc,
+		dump_node_capacity(show_utilization?0:utilization_log_level, "Original", node);
+		);
+
 	/* Take (next) highest resource, assign it and create its actions */
 	slist_iter(
 		rsc, resource_t, data_set->resources, lpc,
 		rsc->cmds->color(rsc, data_set);
 		);
 
+	slist_iter(
+		node, node_t, data_set->nodes, lpc,
+		dump_node_capacity(show_utilization?0:utilization_log_level, "Remaining", node);
+		);
+
 	probe_resources(data_set);
 	
 	slist_iter(
diff -r 53be04557e14 -r 4ba915f52360 pengine/pengine.c
--- a/pengine/pengine.c	Tue Mar 23 17:15:22 2010 +0100
+++ b/pengine/pengine.c	Wed Mar 24 20:25:22 2010 +0800
@@ -39,6 +39,8 @@
 
 gboolean show_scores = FALSE;
 int scores_log_level = LOG_DEBUG_2;
+gboolean show_utilization = FALSE;
+int utilization_log_level = LOG_DEBUG_2;
 extern int transition_id;
 
 #define get_series() 	was_processing_error?1:was_processing_warning?2:3
diff -r 53be04557e14 -r 4ba915f52360 pengine/pengine.h
--- a/pengine/pengine.h	Tue Mar 23 17:15:22 2010 +0100
+++ b/pengine/pengine.h	Wed Mar 24 20:25:22 2010 +0800
@@ -168,6 +168,8 @@
 
 extern gboolean show_scores;
 extern int scores_log_level;
+extern gboolean show_utilization;
+extern int utilization_log_level;
 extern const char* transition_idle_timeout;
 
 #endif
diff -r 53be04557e14 -r 4ba915f52360 pengine/ptest.c
--- a/pengine/ptest.c	Tue Mar 23 17:15:22 2010 +0100
+++ b/pengine/ptest.c	Wed Mar 24 20:25:22 2010 +0800
@@ -124,6 +124,7 @@
 
     {"simulate",    0, 0, 'S', "Simulate the transition's execution to find invalid graphs\n"},
     {"show-scores", 0, 0, 's', "Display resource allocation scores"},
+    {"show-utilization", 0, 0, 'U', "Display utilization information"},
     {"all-actions", 0, 0, 'a', "Display all possible actions - even ones not part of the transition graph"},
 
     {"live-check",  0, 0, 'L', "Connect to the CIB and use the current contents as input"},
@@ -175,7 +176,7 @@
         g_mem_set_vtable(&vtable);
 
 	crm_log_init("ptest", LOG_CRIT, FALSE, FALSE, 0, NULL);
-	crm_set_options("V?$XD:G:I:Lwx:d:aSs", "[-?Vv] -[Xxp] {other options}", long_options,
+	crm_set_options("V?$XD:G:I:Lwx:d:aSsU", "[-?Vv] -[Xxp] {other options}", long_options,
 			"Calculate the cluster's response to the supplied cluster state\n");
 	
 	while (1) {
@@ -200,6 +201,9 @@
 			case 's':
 				show_scores = TRUE;
 				break;
+			case 'U':
+				show_utilization = TRUE;
+				break;
 			case 'x':
 				xml_file = optarg;
 				break;
@@ -322,8 +326,12 @@
 	}
 
 	if(process) {
-	    if(show_scores) {
+	    if(show_scores && show_utilization) {
+		fprintf(stdout, "Allocation scores and utilization information:\n");
+	    } else if(show_scores) {
 		fprintf(stdout, "Allocation scores:\n");
+	    } else if(show_utilization) {
+		fprintf(stdout, "Utilization information:\n");
 	    }
 	    do_calculations(&data_set, cib_object, a_date);
 	}
diff -r 53be04557e14 -r 4ba915f52360 pengine/utils.c
--- a/pengine/utils.c	Tue Mar 23 17:15:22 2010 +0100
+++ b/pengine/utils.c	Wed Mar 24 20:25:22 2010 +0800
@@ -332,8 +332,8 @@
 
 struct calculate_data
 {
-        node_t *node;
-        gboolean allocate;
+	node_t *node;
+	gboolean allocate;
 };
 
 static void
@@ -366,6 +366,10 @@
 	data.allocate = allocate;
 
 	g_hash_table_foreach(rsc->utilization, do_calculate_utilization, &data);
+
+	if (allocate) {
+		dump_rsc_utilization(show_utilization?0:utilization_log_level, __FUNCTION__, rsc, node);
+	}
 }
 
 gboolean
diff -r 53be04557e14 -r 4ba915f52360 tools/crm_inject.c
--- a/tools/crm_inject.c	Tue Mar 23 17:15:22 2010 +0100
+++ b/tools/crm_inject.c	Wed Mar 24 20:25:22 2010 +0800
@@ -814,6 +814,7 @@
     {"simulate",      0, 0, 'S', "Simulate the transition's execution and display the resulting cluster status"},
     {"in-place",      0, 0, 'X', "Simulate the transition's execution and store the result back to the input file"},
     {"show-scores",   0, 0, 's', "Show allocation scores"},
+    {"show-utilization",   0, 0, 'U', "Show utilization information"},
 
     {"-spacer-",     0, 0, '-', "\nSynthetic Cluster Events:"},
     {"node-up",      1, 0, 'u', "\tBring a node online"},
@@ -875,7 +876,7 @@
     xmlNode *input = NULL;
 
     crm_log_init("crm_simulate", LOG_ERR, FALSE, FALSE, argc, argv);
-    crm_set_options("?$VQx:Lpu:d:f:i:RSXD:G:I:O:saF:t:", "datasource operation [additional options]",
+    crm_set_options("?$VQx:Lpu:d:f:i:RSXD:G:I:O:sUaF:t:", "datasource operation [additional options]",
 		    long_options, "Tool for simulating the cluster's response to events");
 
     if(argc < 2) {
@@ -944,6 +945,10 @@
 		process = TRUE;
 		show_scores = TRUE;
 		break;
+	    case 'U':
+		process = TRUE;
+		show_utilization = TRUE;
+		break;
 	    case 'S':
 		process = TRUE;
 		simulate = TRUE;
@@ -1035,8 +1040,12 @@
 
     rc = 0;
     if(process || simulate) {
-	if(show_scores) {
+	if(show_scores && show_utilization) {
+	    printf("Allocation scores and utilization information:\n");
+	} else if(show_scores) {
 	    printf("Allocation scores:\n");
+	} else if(show_utilization) {
+	    printf("Utilization information:\n");
 	}
 	
 	do_calculations(&data_set, input, a_date);
@@ -1062,7 +1071,7 @@
 	}
 
 	if(quiet == FALSE && verbose == FALSE) {
-	    quiet_log("%sTransition Summary:\n", show_scores||modified?"\n":"");
+	    quiet_log("%sTransition Summary:\n", show_scores||show_utilization||modified?"\n":"");
 	    fflush(stdout);
 
 	    crm_log_level = LOG_NOTICE;
_______________________________________________
Pacemaker mailing list
Pacemaker@oss.clusterlabs.org
http://oss.clusterlabs.org/mailman/listinfo/pacemaker

Reply via email to