- /* check if we have to set it to 0 */
- if (!xbt_dict_get_or_null(platform_variables, resource)) {
- xbt_dynar_t array = xbt_dynar_new(sizeof(char *), xbt_free);
- char *var_cpy = xbt_strdup(variable);
- xbt_dynar_push(array, &var_cpy);
- if (TRACE_categorized ())
- pajeSetVariable(now, variable, resource, "0");
- xbt_dict_set(platform_variables, resource, array,
- xbt_dynar_free_voidp);
- } else {
- xbt_dynar_t array = xbt_dict_get(platform_variables, resource);
- unsigned int i;
- char *cat;
- int flag = 0;
- xbt_dynar_foreach(array, i, cat) {
- if (strcmp(variable, cat) == 0) {
- flag = 1;
- }
- }
- if (flag == 0) {
- char *var_cpy = xbt_strdup(variable);
- xbt_dynar_push(array, &var_cpy);
- if (TRACE_categorized ())
- pajeSetVariable(now, variable, resource, "0");
- }
- }
- /* end of check */
-}
-
-#define A_METHOD
-//A
-static void __TRACE_A_alloc(void)
-{
-}
-
-static void __TRACE_A_release(void)
-{
-}
-
-static void __TRACE_A_start(smx_action_t action)
-{
-}
-
-static void __TRACE_A_event(smx_action_t action, double now, double delta,
- const char *variable, const char *resource,
- double value)
-{
- char valuestr[100];
- snprintf(valuestr, 100, "%f", value);
-
- __TRACE_surf_check_variable_set_to_zero(now, variable, resource);
- pajeAddVariable(now, variable, resource, valuestr);
- pajeSubVariable(now + delta, variable, resource, valuestr);
-}
-
-static void __TRACE_A_end(smx_action_t action)
-{
-}
-
-#define B_METHOD
-//B
-
-static void __TRACE_B_alloc(void)
-{
- method_b_dict = xbt_dict_new();
-}
-
-static void __TRACE_B_release(void)
-{
- char *key, *time;
- xbt_dict_cursor_t cursor = NULL;
- xbt_dict_foreach(method_b_dict, cursor, key, time) {
- char resource[INSTR_DEFAULT_STR_SIZE];
- char variable[INSTR_DEFAULT_STR_SIZE];
- char what[INSTR_DEFAULT_STR_SIZE];
- sscanf (key, "%s %s %s", resource, variable, what);
- if (strcmp(what, "time")==0){
- char key_value[INSTR_DEFAULT_STR_SIZE];
- snprintf (key_value, INSTR_DEFAULT_STR_SIZE, "%s %s value", resource, variable);
- char *value = xbt_dict_get_or_null (method_b_dict, key_value);
- pajeSubVariable(atof(time), variable, resource, value);
- }
- }
- xbt_dict_free(&method_b_dict);
-}
-
-static void __TRACE_B_start(smx_action_t action)
-{
-}
-
-static void __TRACE_B_event(smx_action_t action, double now, double delta,
- const char *variable, const char *resource,
- double value)
-{
- char key_time[INSTR_DEFAULT_STR_SIZE];
- char key_value[INSTR_DEFAULT_STR_SIZE];
- char nowstr[INSTR_DEFAULT_STR_SIZE];
- char valuestr[INSTR_DEFAULT_STR_SIZE];
- char nowdeltastr[INSTR_DEFAULT_STR_SIZE];
-
- snprintf (key_time, INSTR_DEFAULT_STR_SIZE, "%s %s time", resource, variable);
- snprintf (key_value, INSTR_DEFAULT_STR_SIZE, "%s %s value", resource, variable);
- snprintf (nowstr, INSTR_DEFAULT_STR_SIZE, "%f", now);
- snprintf (valuestr, INSTR_DEFAULT_STR_SIZE, "%f", value);
- snprintf (nowdeltastr, INSTR_DEFAULT_STR_SIZE, "%f", now+delta);
-
- char *lasttimestr = xbt_dict_get_or_null(method_b_dict, key_time);
- char *lastvaluestr = xbt_dict_get_or_null(method_b_dict, key_value);
- if (lasttimestr == NULL){
- __TRACE_surf_check_variable_set_to_zero(now, variable, resource);
- pajeAddVariable(now, variable, resource, valuestr);
- xbt_dict_set(method_b_dict, key_time, xbt_strdup(nowdeltastr), xbt_free);
- xbt_dict_set(method_b_dict, key_value, xbt_strdup(valuestr), xbt_free);
- }else{
- double lasttime = atof (lasttimestr);
- double lastvalue = atof (lastvaluestr);
-
- if (lastvalue == value){
- double dif = fabs(now - lasttime);
- if (dif < 0.000001){
- //perfect, just go on
- }else{
- //time changed, have to update
- pajeSubVariable(lasttime, variable, resource, lastvaluestr);
- pajeAddVariable(now, variable, resource, valuestr);
- }
- }else{
- //value changed, have to update
- pajeSubVariable(lasttime, variable, resource, lastvaluestr);
- pajeAddVariable(now, variable, resource, valuestr);
- }
- xbt_dict_set(method_b_dict, key_time, xbt_strdup(nowdeltastr), xbt_free);
- xbt_dict_set(method_b_dict, key_value, xbt_strdup(valuestr), xbt_free);
+ /*
+ * To trace resource utilization, we use pajeAddVariable and pajeSubVariable only.
+ * The Paje simulator needs a pajeSetVariable in the first place so it knows
+ * the initial value of all variables for subsequent adds/subs. If we don't do
+ * so, the first pajeAddVariable is added to a non-determined value within
+ * the Paje simulator, causing analysis problems.
+ */
+
+ // create a key considering the resource and variable
+ int n = strlen(variable)+strlen(resource)+1;
+ char *key = (char*)xbt_malloc(n*sizeof(char));
+ snprintf (key, n, "%s%s", resource, variable);
+
+ // check if key exists: if it doesn't, set the variable to zero and mark this in the dict
+ if (!xbt_dict_get_or_null(platform_variables, key)) {
+ container_t container = PJ_container_get (resource);
+ type_t type = PJ_type_get (variable, container->type);
+ new_pajeSetVariable (now, container, type, 0);
+ xbt_dict_set(platform_variables, key, (char*)"", NULL);