#include "mstime.h"
-int64_t timespec_as_nanoseconds (struct timespec ts)
+mstime_t timespec_as_microseconds (struct timespec ts)
{
- return ts.tv_sec * 1000000000 + ts.tv_nsec ;
+ return ts.tv_sec * 1000000 + ts.tv_nsec / 1000 ;
}
-int64_t sys_timestamp (void)
+mstime_t sys_timestamp (void)
{
struct timespec ts;
clock_gettime (CLOCK_REALTIME, &ts);
- return timespec_as_nanoseconds (ts);
+ return timespec_as_microseconds (ts);
}
-/* microsecond time */
+/* microsecond time module */
#ifndef __MSTIME_H__
#define __MSTIME_H__
/* depend: */
/* cflags: */
-/* linker: mstime.o stat.o -lpthread -lm */
+/* linker: nstime.o stat.o -lpthread -lm */
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <unistd.h>
-#include "mstime.h"
+#include "nstime.h"
#include "stat.h"
/* static variables */
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int shared_flag = 0;
-mstime_t timestamp1, timestamp2;
+nstime_t timestamp1, timestamp2;
int try = 0;
void *mutex_giver_task (__attribute__((unused)) void *arg)
void *mutex_taker_task (__attribute__((unused)) void *arg)
{
- mstime_t *deltas = (mstime_t *) calloc (nb_measurements, sizeof (mstime_t));
+ nstime_t *deltas = (nstime_t *) calloc (nb_measurements, sizeof (nstime_t));
assert (deltas);
while (try < nb_measurements) {
}
if (do_stat) {
+ printf ("Results are in nanosecond\n");
compute_statistics (deltas, nb_measurements, hist_bin);
}
--- /dev/null
+#include <time.h>
+
+#include "nstime.h"
+
+nstime_t timespec_as_nanoseconds (struct timespec ts)
+{
+ return ts.tv_sec * 1000000000 + ts.tv_nsec;
+}
+
+nstime_t sys_timestamp (void)
+{
+ struct timespec ts;
+ clock_gettime (CLOCK_REALTIME, &ts);
+ return timespec_as_nanoseconds (ts);
+}
--- /dev/null
+/* nanosecond time module */
+
+#ifndef __NSTIME_H__
+#define __NSTIME_H__
+
+#include "inttypes.h"
+
+typedef int64_t nstime_t;
+
+nstime_t sys_timestamp (void);
+
+#endif /* __NSTIME_H__ */
-/* Statistic module */
+/* statistic module */
#include <assert.h>
+#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-#include "mstime.h"
-
#include "stat.h"
-void compute_statistics (mstime_t *points, int nb, int bins)
+void compute_statistics (int64_t *points, int nb, int bins)
{
+ printf ("Nb of points = %d\n", nb);
+
/* compute average, minimum and maximum */
double avg = 0;
int change_done = 0;
for (int i = 1; i < nb - 1; i++) {
if (points[i + 1] < points[i]) {
- mstime_t tmp = points[i];
+ int64_t tmp = points[i];
points[i] = points[i + 1];
points[i + 1] = tmp;
change_done = 1;
assert (hist);
double gap = (max - min) / bins;
- for (int i = 0; i < nb; i++) {
- hist[(int)((points[i] - min) / gap)]++;
+ for (int i = 0; i < nb - 1; i++) {
+ hist[(int)((points[i] - min) * bins / (max -min))]++;
}
+ hist[bins - 1]++;
printf ("Histogram\n");
- for (int i = 0; i < bins - 1; i++) {
+ for (int i = 0; i < bins; i++) {
printf (" [%.2lf - %.2lf] = %d\n", min + i * gap, min + (i + 1) * gap, hist[i]);
}
- printf (" [%.2lf - %.2lf] = %d\n", min + (bins - 1) * gap, max, hist[bins - 1]);
free (hist);
-/* Statistic module */
+/* statistic module */
#ifndef __STAT_H__
#define __STAT_H__
-#include "mstime.h"
+#include <inttypes.h>
-void compute_statistics (mstime_t *points, int nb, int bins);
+void compute_statistics (int64_t *points, int nb, int bins);
#endif /* __STAT_H__ */