#include <stdio.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

int main() {
    int fd;
    int status;
    unsigned long long start, end;

    fd = open("/dev/xdma_instr", O_RDONLY);
    if (fd < 0) {
        perror("open");
        exit(1);
    }
    status = read(fd, &start, sizeof(start));
    if (status != sizeof(start)) {
        perror("1st read");
    }

    sleep(1);
    status = read(fd, &end, sizeof(end));
    if (status != sizeof(start)) {
        perror("2nd read");
    }

    printf("%llu ticks in %d s (%lluMHz)\n", end - start, 1, (end - start)/1000000);
}
