2021-10-26 18:42:41 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-07-19 15:11:41 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <linux/limits.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdatomic.h>
|
2021-07-19 19:05:26 +02:00
|
|
|
#include <dirent.h>
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
#include "ovni.h"
|
2021-11-18 11:55:28 +01:00
|
|
|
#include "trace.h"
|
2021-07-28 11:56:35 +02:00
|
|
|
#include "emu.h"
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-10-18 12:44:43 +02:00
|
|
|
//static void
|
|
|
|
//hexdump(uint8_t *buf, size_t size)
|
|
|
|
//{
|
|
|
|
// size_t i, j;
|
|
|
|
//
|
|
|
|
// //printf("writing %ld bytes in cpu=%d\n", size, rthread.cpu);
|
|
|
|
//
|
|
|
|
// for(i=0; i<size; i+=16)
|
|
|
|
// {
|
|
|
|
// for(j=0; j<16 && i+j < size; j++)
|
|
|
|
// {
|
|
|
|
// fprintf(stderr, "%02x ", buf[i+j]);
|
|
|
|
// }
|
|
|
|
// fprintf(stderr, "\n");
|
|
|
|
// }
|
|
|
|
//}
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
static void
|
2021-10-18 12:44:43 +02:00
|
|
|
emit(struct ovni_stream *stream, struct ovni_ev *ev)
|
2021-07-19 15:11:41 +02:00
|
|
|
{
|
2021-07-21 18:27:58 +02:00
|
|
|
int64_t delta;
|
2021-07-24 10:53:41 +02:00
|
|
|
uint64_t clock;
|
|
|
|
int i, payloadsize;
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
//printf("sizeof(*ev) = %d\n", sizeof(*ev));
|
|
|
|
//hexdump((uint8_t *) ev, sizeof(*ev));
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
clock = ovni_ev_get_clock(ev);
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
delta = clock - stream->lastclock;
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-09-28 19:21:22 +02:00
|
|
|
printf("%d.%d.%d %c %c %c % 20ld % 15ld ",
|
2021-07-24 10:53:41 +02:00
|
|
|
stream->loom, stream->proc, stream->tid,
|
2021-10-11 15:46:49 +02:00
|
|
|
ev->header.model, ev->header.category, ev->header.value, clock, delta);
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
payloadsize = ovni_payload_size(ev);
|
|
|
|
for(i=0; i<payloadsize; i++)
|
2021-07-19 15:11:41 +02:00
|
|
|
{
|
2021-07-28 11:56:35 +02:00
|
|
|
printf("%02x ", ev->payload.u8[i]);
|
2021-07-19 15:11:41 +02:00
|
|
|
}
|
2021-07-24 10:53:41 +02:00
|
|
|
printf("\n");
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
stream->lastclock = clock;
|
2021-07-19 15:11:41 +02:00
|
|
|
}
|
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-10-18 12:44:43 +02:00
|
|
|
static void
|
|
|
|
dump_events(struct ovni_trace *trace)
|
2021-07-19 15:11:41 +02:00
|
|
|
{
|
2021-10-18 12:44:43 +02:00
|
|
|
size_t i;
|
|
|
|
ssize_t f;
|
2021-07-19 15:11:41 +02:00
|
|
|
uint64_t minclock, lastclock;
|
2021-07-24 10:53:41 +02:00
|
|
|
struct ovni_ev *ev;
|
|
|
|
struct ovni_stream *stream;
|
2021-07-19 15:11:41 +02:00
|
|
|
|
|
|
|
/* Load events */
|
|
|
|
for(i=0; i<trace->nstreams; i++)
|
|
|
|
{
|
|
|
|
stream = &trace->stream[i];
|
2021-07-24 10:53:41 +02:00
|
|
|
ovni_load_next_event(stream);
|
2021-07-19 15:11:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lastclock = 0;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
f = -1;
|
|
|
|
minclock = 0;
|
|
|
|
|
|
|
|
/* Select next event based on the clock */
|
|
|
|
for(i=0; i<trace->nstreams; i++)
|
|
|
|
{
|
|
|
|
stream = &trace->stream[i];
|
|
|
|
|
|
|
|
if(!stream->active)
|
|
|
|
continue;
|
|
|
|
|
2021-07-30 20:08:40 +02:00
|
|
|
ev = stream->cur_ev;
|
2021-07-24 10:53:41 +02:00
|
|
|
if(f < 0 || ovni_ev_get_clock(ev) < minclock)
|
2021-07-19 15:11:41 +02:00
|
|
|
{
|
|
|
|
f = i;
|
2021-07-24 10:53:41 +02:00
|
|
|
minclock = ovni_ev_get_clock(ev);
|
2021-07-19 15:11:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//fprintf(stderr, "f=%d minclock=%u\n", f, minclock);
|
|
|
|
|
|
|
|
if(f < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
stream = &trace->stream[f];
|
|
|
|
|
2021-07-30 20:08:40 +02:00
|
|
|
if(lastclock > ovni_ev_get_clock(stream->cur_ev))
|
2021-07-19 15:11:41 +02:00
|
|
|
{
|
2021-07-22 12:35:38 +02:00
|
|
|
fprintf(stdout, "warning: backwards jump in time %lu -> %lu\n",
|
2021-07-30 20:08:40 +02:00
|
|
|
lastclock, ovni_ev_get_clock(stream->cur_ev));
|
2021-07-19 15:11:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit current event */
|
2021-07-30 20:08:40 +02:00
|
|
|
emit(stream, stream->cur_ev);
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-30 20:08:40 +02:00
|
|
|
lastclock = ovni_ev_get_clock(stream->cur_ev);
|
2021-07-19 15:11:41 +02:00
|
|
|
|
|
|
|
/* Read the next one */
|
2021-07-24 10:53:41 +02:00
|
|
|
ovni_load_next_event(stream);
|
2021-07-19 15:11:41 +02:00
|
|
|
|
|
|
|
/* Unset the index */
|
|
|
|
f = -1;
|
|
|
|
minclock = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *tracedir;
|
2021-09-23 10:38:44 +02:00
|
|
|
struct ovni_trace *trace;
|
|
|
|
|
|
|
|
trace = calloc(1, sizeof(struct ovni_trace));
|
|
|
|
|
|
|
|
if(trace == NULL)
|
|
|
|
{
|
|
|
|
perror("calloc");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2021-07-19 15:11:41 +02:00
|
|
|
|
|
|
|
if(argc != 2)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "missing tracedir\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
tracedir = argv[1];
|
|
|
|
|
2021-09-23 10:38:44 +02:00
|
|
|
if(ovni_load_trace(trace, tracedir))
|
2021-07-19 15:11:41 +02:00
|
|
|
return 1;
|
|
|
|
|
2021-09-23 10:38:44 +02:00
|
|
|
if(ovni_load_streams(trace))
|
2021-07-19 15:11:41 +02:00
|
|
|
return 1;
|
|
|
|
|
2021-09-23 10:38:44 +02:00
|
|
|
dump_events(trace);
|
|
|
|
|
|
|
|
ovni_free_streams(trace);
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-09-23 10:38:44 +02:00
|
|
|
free(trace);
|
2021-07-19 15:11:41 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|