- char valuestr[100];
- char nowstr[100], nowdeltastr[100];
- char timekey[100], valuekey[100], variablekey[100];
- char *lastvariable = NULL;
- char *lasttime = NULL;
- char *lastvalue = NULL;
- char *nowdeltastr_cpy = NULL;
- char *valuestr_cpy = NULL;
- char *variable_cpy = NULL;
-
- /*
- * The following code replaces the code above with the objective
- * to decrease the size of file because of unnecessary add/sub on
- * variables. It should be re-checked before put in production.
- */
-
- snprintf (valuestr, 100, "%f", value);
- snprintf (nowstr, 100, "%f", now);
- snprintf (nowdeltastr, 100, "%f", now+delta);
- snprintf (timekey, 100, "%s%cTime", resource, VARIABLE_SEPARATOR);
- snprintf (valuekey, 100, "%s%cValue", resource, VARIABLE_SEPARATOR);
- snprintf (variablekey, 100, "%s%cVariable", resource, VARIABLE_SEPARATOR);
-
- lastvariable = xbt_dict_get_or_null (method_b_dict, variablekey);
- if (lastvariable == NULL){
- __TRACE_surf_check_variable_set_to_zero (now, variable, resource);
- pajeAddVariable (now, variable, resource, valuestr);
- nowdeltastr_cpy = xbt_strdup (nowdeltastr);
- valuestr_cpy = xbt_strdup (valuestr);
- variable_cpy = xbt_strdup (variable);
- xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free);
- xbt_dict_set (method_b_dict, valuekey, valuestr_cpy, xbt_free);
- xbt_dict_set (method_b_dict, variablekey, variable_cpy, xbt_free);
- }else{
- lasttime = xbt_dict_get_or_null (method_b_dict, timekey);
- lastvalue = xbt_dict_get_or_null (method_b_dict, valuekey);
-
- /* check if it is the same variable */
- if (strcmp(lastvariable, variable) == 0){ /* same variable */
- /* check if lasttime equals now */
- if (atof(lasttime) == now){ /* lastime == now */
- /* check if lastvalue equals valuestr */
- if (atof(lastvalue) == value){ /* lastvalue == value (good, just advance time) */
- char *nowdeltastr_cpy = xbt_strdup (nowdeltastr);
- xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free);
- }else{ /* value has changed */
- /* value has changed, subtract previous value, add new one */
- pajeSubVariable (atof(lasttime), variable, resource, lastvalue);
- pajeAddVariable (atof(nowstr), variable, resource, valuestr);
- nowdeltastr_cpy = xbt_strdup (nowdeltastr);
- valuestr_cpy = xbt_strdup (valuestr);
- xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free);
- xbt_dict_set (method_b_dict, valuekey, valuestr_cpy, xbt_free);
- }
- }else{ /* lasttime != now */
- /* the last time is different from new starting time, subtract to lasttime and add from nowstr */
- pajeSubVariable (atof(lasttime), variable, resource, lastvalue);
- pajeAddVariable (atof(nowstr), variable, resource, valuestr);
- nowdeltastr_cpy = xbt_strdup (nowdeltastr);
- valuestr_cpy = xbt_strdup (valuestr);
- xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free);
- xbt_dict_set (method_b_dict, valuekey, valuestr_cpy, xbt_free);
- }
- }else{ /* variable has changed */
- pajeSubVariable (atof(lasttime), lastvariable, resource, lastvalue);
- __TRACE_surf_check_variable_set_to_zero (now, variable, resource);
- pajeAddVariable (now, variable, resource, valuestr);
- nowdeltastr_cpy = xbt_strdup (nowdeltastr);
- valuestr_cpy = xbt_strdup (valuestr);
- variable_cpy = xbt_strdup (variable);
- xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free);
- xbt_dict_set (method_b_dict, valuekey, valuestr_cpy, xbt_free);
- xbt_dict_set (method_b_dict, variablekey, variable_cpy, xbt_free);