- double integral = 0.0;
- int i;
- long index;
- int top_level = 0;
- long l_bounds[TRACE_NB_LEVELS];
- long u_bounds[TRACE_NB_LEVELS];
- double a_divided_by_spacing;
- double current_spacing;
- DEBUG2("Computing simple integral on [%.2f , %.2f]\n", a, b);
-
- /* Sanity checks */
- if ((a < 0.0) || (b < a) || (a > trace->last_time)
- || (b > trace->last_time)) {
- CRITICAL2
- ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.",
- a, b);
- xbt_abort();
- }
- if (b == a) {
- return 0.0;
- }
-
- for (i = 0; i < trace->nb_levels; i++) {
- a_divided_by_spacing = a / trace->levels[i]->spacing;
- if (ceil(a_divided_by_spacing) == a_divided_by_spacing)
- l_bounds[i] = 1 + (long) ceil(a_divided_by_spacing);
- else
- l_bounds[i] = (long) (ceil(a_divided_by_spacing));
- if (b == trace->last_time) {
- u_bounds[i] = (long) (floor(b / trace->levels[i]->spacing)) - 1;
- } else {
- u_bounds[i] = (long) (floor(b / trace->levels[i]->spacing));
- }
- DEBUG3("level %d: l%ld u%ld\n", i, l_bounds[i], u_bounds[i]);
-
- if (l_bounds[i] <= u_bounds[i])
- top_level = i;
- }
- DEBUG1("top_level=%d\n", top_level);
-
- /* Are a and b BOTH in the same chunk of level 0 ? */
- if (l_bounds[0] > u_bounds[0]) {
- return (b - a) * (trace->levels[0]->values[u_bounds[0]]);
- }
-
- /* first sub-level amount */
- integral += ((l_bounds[0]) * (trace->levels[0]->spacing) - a) *
- (trace->levels[0]->values[l_bounds[0] - 1]);
-
- DEBUG1("Initial level 0 amount is %.2f\n", integral);
-
- /* first n-1 levels */
- for (i = 0; i < top_level; i++) {
-
- if (l_bounds[i] >= u_bounds[i])
- break;
-
- current_spacing = trace->levels[i]->spacing;
- index = l_bounds[i];
-
- DEBUG1("L%d:", i);
-
- while (double_positive
- (l_bounds[i + 1] * trace->levels[i + 1]->spacing -
- index * current_spacing)) {
- integral += current_spacing * trace->levels[i]->values[index];
- DEBUG2("%.2f->%.2f|",
- index * (trace->levels[i]->spacing),
- (index + 1) * (trace->levels[i]->spacing));
- index++;
- }
-
- DEBUG0("\n");
- }
-
- DEBUG1("After going up: %.2f\n", integral);
-
- /* n-th level */
- current_spacing = trace->levels[top_level]->spacing;
- index = l_bounds[top_level];
-
- DEBUG1("L%d:", top_level);
-
- while (index < u_bounds[top_level]) {
- integral += current_spacing * trace->levels[top_level]->values[index];
-
- DEBUG2("%.2f->%.2f|",
- index * (trace->levels[top_level]->spacing),
- (index + 1) * (trace->levels[top_level]->spacing));
-
- index++;
- }
-
- DEBUG0("\n");
- DEBUG1("After steady : %.2f\n", integral);
-
- /* And going back down */
- for (i = top_level - 1; i >= 0; i--) {
- if (l_bounds[i] > u_bounds[i])
- break;
-
- current_spacing = trace->levels[i]->spacing;
- index = u_bounds[i + 1] * (trace->levels[i + 1]->spacing /
- current_spacing);
- DEBUG1("L%d:", i);
- while (double_positive
- ((u_bounds[i]) * current_spacing - index * current_spacing)) {
- integral += current_spacing * trace->levels[i]->values[index];
- DEBUG2("%.2f->%.2f|",
- index * (trace->levels[i]->spacing),
- (index + 1) * (trace->levels[i]->spacing));
- index++;
- }
- }
-
- DEBUG1("After going down : %.2f", integral);
-
-
- /* Little piece at the end */
- integral += (b - u_bounds[0] * (trace->levels[0]->spacing)) *
- (trace->levels[0]->values[u_bounds[0]]);