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-12-13 17:35:54 +01:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
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-12-13 17:35:54 +01:00
|
|
|
#include <unistd.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-12-13 17:35:54 +01:00
|
|
|
int filter_tid = -1;
|
|
|
|
char *tracedir;
|
|
|
|
|
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-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-12-16 13:31:07 +01:00
|
|
|
printf("%s.%d.%d %ld %c%c%c",
|
2021-12-16 13:30:26 +01:00
|
|
|
stream->loom->hostname,
|
|
|
|
stream->proc->pid,
|
|
|
|
stream->thread->tid,
|
2021-12-16 13:31:07 +01:00
|
|
|
clock,
|
2021-12-16 13:30:26 +01:00
|
|
|
ev->header.model,
|
|
|
|
ev->header.category,
|
2021-12-16 13:31:07 +01:00
|
|
|
ev->header.value);
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
payloadsize = ovni_payload_size(ev);
|
2021-12-16 13:31:07 +01:00
|
|
|
if(payloadsize > 0)
|
2021-07-19 15:11:41 +02:00
|
|
|
{
|
2021-12-16 13:31:07 +01:00
|
|
|
printf(" ");
|
|
|
|
for(i=0; i<payloadsize; i++)
|
|
|
|
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-12-13 17:35:54 +01:00
|
|
|
|
|
|
|
/* It can be inactive if it has been disabled by the
|
|
|
|
* thread TID filter */
|
|
|
|
if(stream->active)
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 17:35:54 +01:00
|
|
|
static void
|
|
|
|
usage(int argc, char *argv[])
|
2021-07-19 15:11:41 +02:00
|
|
|
{
|
2021-12-13 17:35:54 +01:00
|
|
|
UNUSED(argc);
|
|
|
|
UNUSED(argv);
|
|
|
|
|
|
|
|
err("Usage: ovnidump [-t TID] tracedir\n");
|
|
|
|
err("\n");
|
|
|
|
err("Dumps the events of the trace to the standard output.\n");
|
|
|
|
err("\n");
|
|
|
|
err("Options:\n");
|
|
|
|
err(" -t TID Only events from the given TID are shown\n");
|
|
|
|
err("\n");
|
|
|
|
err(" tracedir The trace directory generated by ovni.\n");
|
|
|
|
err("\n");
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2021-09-23 10:38:44 +02:00
|
|
|
|
2021-12-13 17:35:54 +01:00
|
|
|
static void
|
|
|
|
parse_args(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int opt;
|
2021-09-23 10:38:44 +02:00
|
|
|
|
2021-12-13 17:35:54 +01:00
|
|
|
while((opt = getopt(argc, argv, "t:")) != -1)
|
2021-09-23 10:38:44 +02:00
|
|
|
{
|
2021-12-13 17:35:54 +01:00
|
|
|
switch(opt)
|
|
|
|
{
|
|
|
|
case 't':
|
|
|
|
filter_tid = atoi(optarg);
|
|
|
|
break;
|
|
|
|
default: /* '?' */
|
|
|
|
usage(argc, argv);
|
|
|
|
}
|
2021-09-23 10:38:44 +02:00
|
|
|
}
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-12-13 17:35:54 +01:00
|
|
|
if(optind >= argc)
|
2021-07-19 15:11:41 +02:00
|
|
|
{
|
2021-12-13 17:35:54 +01:00
|
|
|
err("missing tracedir\n");
|
|
|
|
usage(argc, argv);
|
2021-07-19 15:11:41 +02:00
|
|
|
}
|
|
|
|
|
2021-12-13 17:35:54 +01:00
|
|
|
tracedir = argv[optind];
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
parse_args(argc, argv);
|
|
|
|
|
|
|
|
struct ovni_trace *trace = calloc(1, sizeof(struct ovni_trace));
|
2021-07-19 15:11:41 +02:00
|
|
|
|
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-12-13 17:35:54 +01:00
|
|
|
if(filter_tid != -1)
|
|
|
|
{
|
|
|
|
for(size_t i=0; i<trace->nstreams; i++)
|
|
|
|
{
|
|
|
|
struct ovni_stream *stream;
|
|
|
|
stream = &trace->stream[i];
|
|
|
|
if(stream->tid != filter_tid)
|
|
|
|
stream->active = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|