예제 #1
0
static void assembly_create(xmlNode *cur_node)
{
	struct assembly *assembly;
	char *name;
	char *uuid;
	xmlNode *child_node;
	char *escalation_failures;
	char *escalation_period;

	qb_enter();

	assembly = calloc(1, sizeof (struct assembly));
	name = (char*)xmlGetProp(cur_node, BAD_CAST "name");
	assembly->name = strdup(name);
	uuid = (char*)xmlGetProp(cur_node, BAD_CAST "uuid");
	assembly->uuid = strdup(uuid);
	assembly->resource_map = qb_skiplist_create();
	assembly->sw_instance_create = qb_util_stopwatch_create();
	assembly->sw_instance_connected = qb_util_stopwatch_create();
	assembly->application = application;

	escalation_failures = (char*)xmlGetProp(cur_node, BAD_CAST "escalation_failures");
	escalation_period = (char*)xmlGetProp(cur_node, BAD_CAST "escalation_period");

	recover_init(&assembly->recover,
		    escalation_failures, escalation_period,
		    node_recover_restart,
		    node_recover_escalate,
		    node_state_change_event);
	assembly->recover.instance = assembly;

	instance_create(assembly);
	qb_map_put(assembly_map, name, assembly);

	for (child_node = cur_node->children; child_node;
		child_node = child_node->next) {
		if (child_node->type != XML_ELEMENT_NODE) {
			continue;
		}
		if (strcmp((char*)child_node->name, "services") == 0) {
			resources_create(child_node->children, assembly);
		}
	}

	qb_leave();
}
예제 #2
0
END_TEST

START_TEST(test_check_normal)
{
	uint64_t res;
	uint32_t last;
	qb_util_stopwatch_t *sw = qb_util_stopwatch_create();

	qb_util_stopwatch_split_ctl(sw, 3, 0);

	qb_util_stopwatch_start(sw);
	usleep(33000);
	/* 1 */
	res = qb_util_stopwatch_split(sw);
	assert_int_between(res, 30000, 36000);
	last = qb_util_stopwatch_split_last(sw);
	ck_assert_int_eq(last, 0);

	usleep(10000);
	/* 2 */
	res = qb_util_stopwatch_split(sw);
	assert_int_between(res, 9000, 11000);

	usleep(20000);
	/* 3 */
	res = qb_util_stopwatch_split(sw);
	assert_int_between(res, 19000, 21000);

	/* no more space */
	res = qb_util_stopwatch_split(sw);
	ck_assert_int_eq(res, 0);

	/*
	 * split should be 30000 (10000 + 20000) usec
	 */
	last = qb_util_stopwatch_split_last(sw);
	ck_assert_int_eq(last, 2);
	res = qb_util_stopwatch_time_split_get(sw, last, 0);
	assert_int_between(res, 25000, 35000);

	/* ask for a split that has beyond the max.
	 */
	res = qb_util_stopwatch_time_split_get(sw, 3, 2);
	ck_assert_int_eq(res, 0);

	/* iterating
	 */
	last = qb_util_stopwatch_split_last(sw);
	do {
		res = qb_util_stopwatch_time_split_get(sw, last, last);
		qb_log(LOG_INFO, "normal split %d is %"PRIu64"", last, res);
		last--;
	} while (res > 0);

	qb_util_stopwatch_free(sw);
}
예제 #3
0
파일: bmcpt.c 프로젝트: AnchorCat/libqb
static void bmc_connect(struct bm_ctx *ctx)
{
	ctx->sw = qb_util_stopwatch_create();
	ctx->conn = qb_ipcc_connect("bm1", QB_MAX(1000 * (100 + THREADS),
						  1024*1024));
	if (ctx->conn == NULL) {
		perror("qb_ipcc_connect");
		exit(-1);
	}
}
예제 #4
0
파일: ipcclient.c 프로젝트: AnchorCat/libqb
static void
do_throughput_benchmark(qb_ipcc_connection_t *conn)
{
	ssize_t size = 64;
	int i;

	signal (SIGALRM, sigalrm_handler);
	sw =  qb_util_stopwatch_create();

	for (i = 0; i < 10; i++) { /* number of repetitions - up to 50k */
		_benchmark (conn, size);
		signal (SIGALRM, sigalrm_handler);
		size *= 5;
		if (size >= (ONE_MEG - 100)) {
			break;
		}
	}
}
예제 #5
0
static void
test_this_one(const char *name, snprintf_like_func func)
{
	int i;
	qb_util_stopwatch_t *sw = qb_util_stopwatch_create();
	float elapsed = 452.245252343;
	float ops_per_sec = 0.345624523;

	qb_util_stopwatch_start(sw);
	for (i = 0; i < ITERATIONS; i++) {
		func("%d %s %llu %9.3f", i, "hello", 3425ULL, elapsed);
		func("[%10s] %.32x -> %p", "hello", i, func);
		func("Client %s.%.9s wants to fence (%s) '%s' with device '%3.5f'",
		     "bla", "foooooooooooooooooo",
		     name, "target", ops_per_sec);
		func("Node %s now has process list: %.32x (was %.32x)",
		     "18builder", 2, 0);
	}
	qb_util_stopwatch_stop(sw);
	elapsed = qb_util_stopwatch_sec_elapsed_get(sw);
	ops_per_sec = ((float)ITERATIONS) / elapsed;
	printf("%s] Duration: %9.3f OPs/sec: %9.3f\n", name, elapsed, ops_per_sec);
	qb_util_stopwatch_free(sw);
}
예제 #6
0
static gboolean
exec_rsc_action(crm_graph_t *graph, crm_action_t *action)
{
	lrm_op_t *op = NULL;
	struct pe_operation *pe_op;
	const char *target_rc_s = crm_meta_value(action->params, XML_ATTR_TE_TARGET_RC);
	xmlNode *action_rsc = first_named_child(action->xml, XML_CIB_TAG_RESOURCE);
	char *node = crm_element_value_copy(action->xml, XML_LRM_ATTR_TARGET);
	char *uuid;
	const char *tmp_provider;
	xmlNode *params_all;

	qb_enter();

	if (safe_str_eq(crm_element_value(action->xml, "operation"), "probe_complete")) {
		crm_free(node);
		action->confirmed = TRUE;
		update_graph(graph, action);
		graph_updated = TRUE;
		qb_leave();
		return TRUE;
	}

	if (action_rsc == NULL) {
		crm_log_xml_err(action->xml, "Bad");
		crm_free(node);
		qb_leave();
		return FALSE;
	}
	uuid = crm_element_value_copy(action->xml, XML_LRM_ATTR_TARGET_UUID);

	pe_op = calloc(1, sizeof(struct pe_operation));
	pe_op->refcount = 1;
	pe_op->hostname = node;
	pe_op->node_uuid = uuid;
	pe_op->user_data = run_user_data;
	pe_op->rname = strdup(ID(action_rsc));
	pe_op->rclass = strdup(crm_element_value(action_rsc, XML_AGENT_ATTR_CLASS));
	tmp_provider = crm_element_value(action_rsc, XML_AGENT_ATTR_PROVIDER);
	if (tmp_provider) {
		pe_op->rprovider = strdup(tmp_provider);
	}
	pe_op->rtype = strdup(crm_element_value(action_rsc, XML_ATTR_TYPE));

	if (target_rc_s != NULL) {
		pe_op->target_outcome = crm_parse_int(target_rc_s, "0");
	}
	op = convert_graph_action(NULL, action, 0, pe_op->target_outcome);

	params_all = create_xml_node(NULL, XML_TAG_PARAMS);
	g_hash_table_foreach(op->params, hash2field, params_all);
/*
 * TODO at some point.
	g_hash_table_foreach(action->extra, hash2field, params_all);
	g_hash_table_foreach(rsc->parameters, hash2field, params_all);
	g_hash_table_foreach(action->meta, hash2metafield, params_all);
*/
	filter_action_parameters(params_all, PE_CRM_VERSION);
	pe_op->op_digest = calculate_operation_digest(params_all, PE_CRM_VERSION);

	pe_op->method = strdup(op->op_type);

	pe_op->params = qb_skiplist_create();
	if (op->params != NULL) {
		g_hash_table_foreach(op->params, dup_attr, pe_op->params);
	}

	pe_op->interval = op->interval;
	pe_op->timeout = op->timeout;
	if (pe_op->timeout == 0) {
		if (pe_op->interval == 0) {
			pe_op->timeout = PE_DEFAULT_TIMEOUT;
		} else {
			pe_op->timeout = pe_op->interval / 2;
		}
	}
	pe_op->action = action;
	pe_op->graph = graph;
	pe_op->action_id = action->id;
	pe_op->graph_id = graph->id;
	pe_op->time_execed = qb_util_stopwatch_create();

	free_lrm_op(op);
	free_xml(params_all);

	run_fn(pe_op);

	qb_leave();

	return TRUE;
}