+static void sanitize_name(gchar *name)
+{
+ while(*name != '\0') {
+ if(*name == '/') *name = '_';
+ name++;
+ }
+
+}
+
+
+static void compute_tracefile(LttTracefile *tracefile, void *hook_data)
+{
+ GString *filename;
+ guint nb_equal, nb_block, offset;
+ guint64 tsc;
+ FILE *fp;
+ LttTime time, previous_time;
+ LttEvent *event = ltt_tracefile_get_event(tracefile);
+ LttFacility *facility;
+ LttEventType *event_type;
+ int err;
+ gchar mod_name[PATH_MAX];
+
+ /* start_count is always initialized in this function _if_ there is always
+ * a block_start before a block_end.
+ */
+ long long unsigned cycle_count, start_count=0, delta_cycle;
+
+
+ filename = g_string_new("");
+ strcpy(mod_name, g_quark_to_string(ltt_tracefile_name(tracefile)));
+
+ sanitize_name(mod_name);
+
+ g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile)));
+ g_string_printf(filename, "%s.%s.%u.trace", a_dump_tracefiles,
+ mod_name, ltt_tracefile_num(tracefile));
+ fp = fopen(filename->str, "w");
+ if(fp == NULL) g_error("Cannot open %s", filename->str);
+ g_string_free(filename, TRUE);
+ err = ltt_tracefile_seek_time(tracefile, ltt_time_zero);
+ if(err) goto close;
+
+ previous_time = ltt_time_zero;
+ nb_equal = 0;
+
+ do {
+ LttTracefile *tf_pos;
+ facility = ltt_event_facility(event);
+ event_type = ltt_event_eventtype(event);
+ time = ltt_event_time(event);
+ ltt_event_position(event, a_event_position);
+ ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc);
+ //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
+ fprintf(fp, "%s.%s: %llu %lu.%09lu position %u/%u, tracefile %s\n",
+ g_quark_to_string(ltt_facility_name(facility)),
+ g_quark_to_string(ltt_eventtype_name(event_type)),
+ tsc, (unsigned long)time.tv_sec,
+ (unsigned long)time.tv_nsec,
+ nb_block, offset,
+ g_quark_to_string(ltt_tracefile_name(tracefile)));
+
+ if(ltt_time_compare(time, previous_time) < 0) {
+ g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/%u",
+ g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))),
+ g_quark_to_string(ltt_tracefile_name(tracefile)),
+ ltt_tracefile_num(tracefile), nb_block, offset);
+ g_warning("last time %lu.%lu vs current %lu.%lu",
+ previous_time.tv_sec, previous_time.tv_nsec,
+ time.tv_sec, time.tv_nsec);
+ }
+
+#if 0 //FIXME
+ if(ltt_eventtype_name(event_type) == QUARK_BLOCK_START) {
+ start_count = cycle_count;
+ start_time = time;
+ }
+ else if(ltt_eventtype_name(event_type) == QUARK_BLOCK_END) {
+ delta_cycle = cycle_count - start_count;
+ end_nsec_sec = (long long unsigned)time.tv_sec * (long long unsigned)1000000000;
+ end_nsec_nsec = time.tv_nsec;
+ end_nsec = end_nsec_sec + end_nsec_nsec;
+ start_nsec = (long long unsigned)start_time.tv_sec * (long long unsigned)1000000000 + (long long unsigned)start_time.tv_nsec;
+ delta_nsec = end_nsec - start_nsec;
+ cycle_per_nsec = (double)delta_cycle / (double)delta_nsec;
+ nsec_per_cycle = (double)delta_nsec / (double)delta_cycle;
+ added_nsec = (double)delta_cycle * nsec_per_cycle;
+ interpolated_nsec = start_nsec + added_nsec;
+ added_nsec2 = (double)delta_cycle / cycle_per_nsec;
+ interpolated_nsec2 = start_nsec + added_nsec2;
+
+ fprintf(fp,"Time: start_count %llu, end_count %llu, delta_cycle %llu, start_nsec %llu, end_nsec_sec %llu, end_nsec_nsec %llu, end_nsec %llu, delta_nsec %llu, cycle_per_nsec %.25f, nsec_per_cycle %.25f, added_nsec %llu, added_nsec2 %llu, interpolated_nsec %llu, interpolated_nsec2 %llu\n", start_count, cycle_count, delta_cycle, start_nsec, end_nsec_sec, end_nsec_nsec, end_nsec, delta_nsec, cycle_per_nsec, nsec_per_cycle, added_nsec, added_nsec2, interpolated_nsec, interpolated_nsec2);
+ }
+ else {
+#endif //0
+ if(ltt_time_compare(time, previous_time) == 0) nb_equal++;
+ else if(nb_equal > 0) {
+ g_warning("Consecutive %d events with time %lu.%09lu",
+ nb_equal + 1, previous_time.tv_sec, previous_time.tv_nsec);
+ nb_equal = 0;
+ }
+ previous_time = time;
+ //}
+ } while((!ltt_tracefile_read(tracefile)));
+
+close:
+ fclose(fp);
+}
+