EINA_INLIST_FOREACH(bench->runs, run)
{
Eina_Counter *counter;
+ char *result;
int i;
snprintf(buffer, PATH_MAX, "bench_%s_%s.%s.data", bench->name, bench->run, run->name);
eina_counter_stop(counter, i);
}
- eina_counter_dump(counter, current_data);
+ result = eina_counter_dump(counter);
+ if (result)
+ {
+ fprintf(current_data, "%s", result);
+ free(result);
+ }
eina_counter_delete(counter);
}
#endif /* _WIN2 */
+static char *
+_eina_counter_asiprintf(char *base, int *position, const char *format, ...)
+{
+ char *tmp, *result;
+ int size = 32;
+ int n;
+ va_list ap;
+
+ tmp = realloc(base, sizeof (char) * (*position + size));
+ if (!tmp) return base;
+ result = tmp;
+
+ while (1)
+ {
+ va_start(ap, format);
+ n = vsnprintf(result + *position, size, format, ap);
+ va_end(ap);
+
+ if (n > -1 && n < size)
+ {
+ /* If we always have glibc > 2.2, we could just return *position += n. */
+ *position += strlen(result + *position);
+ return result;
+ }
+
+ if (n > -1) size = n + 1;
+ else size <<= 1;
+
+ tmp = realloc(result, sizeof (char) * (*position + size));
+ if (!tmp) return result;
+ result = tmp;
+ }
+}
+
/**
* @endcond
*/
/**
* @brief Dump the result of all clocks of a counter to a stream.
*
+ * @return A string with a summary of the test.
* @param counter The counter.
- * @param out The stream to dump the clocks.
*
* This function dump all the valid clocks of @p counter to the stream
* @p out. If @p counter or @p out are @c NULL, the functions exits
*
* The unit of time is the nanosecond.
*/
-EAPI void
-eina_counter_dump(Eina_Counter *counter, FILE *out)
+EAPI char *
+eina_counter_dump(Eina_Counter *counter)
{
Eina_Clock *clk;
+ char *result = NULL;
+ int position = 0;
- if (!counter || !out) return;
+ if (!counter) return NULL;
- fprintf(out, "# specimen\texperiment time\tstarting time\tending time\n");
+ result = _eina_counter_asiprintf(result, &position, "# specimen\texperiment time\tstarting time\tending time\n");
+ if (!result) return NULL;
EINA_INLIST_REVERSE_FOREACH(counter->clocks, clk)
{
diff = (long int)(((long long int)(clk->end.QuadPart - clk->start.QuadPart) * 1000000000LL) / (long long int)_eina_counter_frequency.QuadPart);
#endif /* _WIN2 */
- fprintf(out, "%i\t%li\t%li\t%li\n",
- clk->specimen,
- diff,
- start,
- end);
+ result = _eina_counter_asiprintf(result, &position,
+ "%i\t%li\t%li\t%li\n",
+ clk->specimen,
+ diff,
+ start,
+ end);
}
+
+ return result;
}
/**
START_TEST(eina_counter_simple)
{
Eina_Counter *cnt;
+ char *dump;
int i;
eina_counter_init();
eina_counter_stop(cnt, i);
- eina_counter_dump(cnt, stderr);
+ dump = eina_counter_dump(cnt);
+ fail_if(!dump);
+
+ free(dump);
eina_counter_delete(cnt);
START_TEST(eina_counter_break)
{
Eina_Counter *cnt;
+ char *dump;
eina_counter_init();
eina_counter_delete(cnt);
- eina_counter_dump(NULL, stderr);
+ dump = eina_counter_dump(NULL);
+ fail_if(dump);
+
+ free(dump);
eina_counter_shutdown();
}