Esempio n. 1
0
void rmsummary_print(FILE *stream, struct rmsummary *s, struct jx *verbatim_fields)
{
	struct jx *jsum = rmsummary_to_json(s, 0);

	if(verbatim_fields) {
		if(!jx_istype(verbatim_fields, JX_OBJECT)) {
			fatal("Vebatim fields are not a json object.");
		}
		struct jx_pair *head = verbatim_fields->u.pairs;

		while(head) {
			jx_insert(jsum, jx_copy(head->key), jx_copy(head->value));
			head = head->next;
		}
	}

	jx_pretty_print_stream(jsum, stream);
	jx_delete(jsum);
}
Esempio n. 2
0
struct jx *rmsummary_to_json(struct rmsummary *s, int only_resources) {
	struct jx *output = jx_object(NULL);
	struct jx *array;

	if(s->disk > -1) {
		array = jx_arrayv(jx_integer(s->disk), jx_string("MB"), NULL);
		jx_insert(output, jx_string("disk"), array);
	}

	if(s->total_files > -1)
		jx_insert_integer(output, "total_files",   s->total_files);

	if(s->bytes_written > -1) {
		array = jx_arrayv(jx_integer(s->bytes_written), jx_string("MB"), NULL);
		jx_insert(output, jx_string("bytes_written"), array);
	}

	if(s->bytes_read > -1) {
		array = jx_arrayv(jx_integer(s->bytes_read), jx_string("MB"), NULL);
		jx_insert(output, jx_string("bytes_read"), array);
	}

	if(s->swap_memory > -1) {
		array = jx_arrayv(jx_integer(s->swap_memory), jx_string("MB"), NULL);
		jx_insert(output, jx_string("swap_memory"), array);
	}

	if(s->memory > -1) {
		array = jx_arrayv(jx_integer(s->memory), jx_string("MB"), NULL);
		jx_insert(output, jx_string("memory"), array);
	}

	if(s->virtual_memory > -1) {
		array = jx_arrayv(jx_integer(s->virtual_memory), jx_string("MB"), NULL);
		jx_insert(output, jx_string("virtual_memory"), array);
	}

	if(s->total_processes > -1)
		jx_insert_integer(output, "total_processes",   s->total_processes);

	if(s->max_concurrent_processes > -1)
		jx_insert_integer(output, "max_concurrent_processes",   s->max_concurrent_processes);

	if(s->cores > -1)
		jx_insert_integer(output, "cores",   s->cores);

	if(s->cpu_time > -1) {
		array = jx_arrayv(jx_integer(s->cpu_time), jx_string("us"), NULL);
		jx_insert(output, jx_string("cpu_time"), array);
	}

	if(s->wall_time > -1) {
		array = jx_arrayv(jx_integer(s->wall_time), jx_string("us"), NULL);
		jx_insert(output, jx_string("wall_time"), array);
	}

	if(s->end > -1) {
		array = jx_arrayv(jx_integer(s->end), jx_string("us"), NULL);
		jx_insert(output, jx_string("end"), array);
	}

	if(s->start > -1) {
		array = jx_arrayv(jx_integer(s->start), jx_string("us"), NULL);
		jx_insert(output, jx_string("start"), array);
	}

	if(!only_resources) {
		if(s->exit_type)
		{
			if( strcmp(s->exit_type, "signal") == 0 ) {
				jx_insert_integer(output, "signal", s->signal);
			} else if( strcmp(s->exit_type, "limits") == 0 ) {
				if(s->limits_exceeded) {
					struct jx *lim = rmsummary_to_json(s->limits_exceeded, 1);
					jx_insert(output, jx_string("limits_exceeded"), lim);
				}
				jx_insert_string(output, "exit_type", "limits");
			}
		}

		if(s->last_error)
			jx_insert_integer(output, "last_error", s->last_error);

		jx_insert_integer(output, "exit_status", s->exit_status);

		if(s->command)
			jx_insert_string(output, "command",   s->command);

		if(s->category)
			jx_insert_string(output, "category",  s->category);
	}

	return output;
}
Esempio n. 3
0
int category_update_first_allocation(struct category *c, const struct rmsummary *max_worker) {
	/* buffer used only for debug output. */
	static buffer_t *b = NULL;
	if(!b) {
		b = malloc(sizeof(buffer_t));
		buffer_init(b);
	}

	if(c->allocation_mode == CATEGORY_ALLOCATION_MODE_FIXED)
		return 0;

	if(c->total_tasks < 1)
		return 0;

	struct rmsummary *top = rmsummary_create(-1);
	rmsummary_merge_override(top, max_worker);
	rmsummary_merge_override(top, c->max_resources_seen);
	rmsummary_merge_override(top, c->max_allocation);

	if(!c->first_allocation) {
		c->first_allocation = rmsummary_create(-1);
	}

	update_first_allocation_field(c, top, 1, cpu_time);
	update_first_allocation_field(c, top, 1, wall_time);
	update_first_allocation_field(c, top, c->time_peak_independece, cores);
	update_first_allocation_field(c, top, c->time_peak_independece, virtual_memory);
	update_first_allocation_field(c, top, c->time_peak_independece, memory);
	update_first_allocation_field(c, top, c->time_peak_independece, swap_memory);
	update_first_allocation_field(c, top, c->time_peak_independece, bytes_read);
	update_first_allocation_field(c, top, c->time_peak_independece, bytes_written);
	update_first_allocation_field(c, top, c->time_peak_independece, bytes_received);
	update_first_allocation_field(c, top, c->time_peak_independece, bytes_sent);
	update_first_allocation_field(c, top, c->time_peak_independece, bandwidth);
	update_first_allocation_field(c, top, c->time_peak_independece, total_files);
	update_first_allocation_field(c, top, c->time_peak_independece, disk);
	update_first_allocation_field(c, top, c->time_peak_independece, max_concurrent_processes);
	update_first_allocation_field(c, top, c->time_peak_independece, total_processes);

	/* From here on we only print debugging info. */
	struct jx *jsum = rmsummary_to_json(c->first_allocation, 1);
	if(jsum) {
		char *str = jx_print_string(jsum);
		debug(D_DEBUG, "Updating first allocation '%s':", c->name);
		debug(D_DEBUG, "%s", str);
		jx_delete(jsum);
		free(str);
	}

	jsum = rmsummary_to_json(top, 1);
	if(jsum) {
		char *str = jx_print_string(jsum);
		debug(D_DEBUG, "From max resources '%s':", c->name);
		debug(D_DEBUG, "%s", str);
		jx_delete(jsum);
		free(str);
	}

	rmsummary_delete(top);

	return 1;
}