Browse Source

Add missing timestamps.c and timestamps.h files, various clenaup

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1571 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/0.67
sletz 18 years ago
parent
commit
b12ad7960c
3 changed files with 132 additions and 7 deletions
  1. +13
    -7
      common/JackTime.h
  2. +79
    -0
      common/timestamps.c
  3. +40
    -0
      common/timestamps.h

+ 13
- 7
common/JackTime.h View File

@@ -33,18 +33,20 @@ extern "C"
#if defined(__APPLE__)

#include <mach/mach_time.h>
#include <unistd.h>
#include <unistd.h>

extern double __jack_time_ratio;

static inline jack_time_t GetMicroSeconds(void) {
static inline jack_time_t GetMicroSeconds(void)
{
return (jack_time_t) (mach_absolute_time () * __jack_time_ratio);
}

/* This should only be called ONCE per process. */
extern void InitTime();

static inline void JackSleep(long usec) {
static inline void JackSleep(long usec)
{
usleep(usec);
}

@@ -58,7 +60,8 @@ extern "C"

extern void InitTime();

static void JackSleep(long usec) {
static void JackSleep(long usec)
{
Sleep(usec / 1000);
}

@@ -68,7 +71,8 @@ extern "C"

#include <unistd.h>

static inline void JackSleep(long usec) {
static inline void JackSleep(long usec)
{
usleep(usec);
}

@@ -77,13 +81,15 @@ extern "C"
extern jack_time_t __jack_cpu_mhz;
extern jack_time_t GetMhz();
extern void InitTime();
static inline jack_time_t GetMicroSeconds (void) {
static inline jack_time_t GetMicroSeconds(void)
{
return get_cycles() / __jack_cpu_mhz;
}
#else
#include <time.h>
extern void InitTime();
static inline jack_time_t GetMicroSeconds (void) {
static inline jack_time_t GetMicroSeconds(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (jack_time_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;


+ 79
- 0
common/timestamps.c View File

@@ -0,0 +1,79 @@
/*
Copyright (C) 2002-2003 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/

#include <stdlib.h>
#include <string.h>
#include "timestamps.h"
#include "JackTime.h"

typedef struct {
jack_time_t when;
const char *what;
} jack_timestamp_t;

static jack_timestamp_t *timestamps = 0;
static unsigned long timestamp_cnt = 0;
static unsigned long timestamp_index;

void
jack_init_timestamps (unsigned long howmany)
{
if (timestamps) {
free (timestamps);
}
timestamps = (jack_timestamp_t *)
malloc (howmany * sizeof(jack_timestamp_t));
timestamp_cnt = howmany;
memset (timestamps, 0, sizeof(jack_timestamp_t) * howmany);
timestamp_index = 0;
}

void
jack_timestamp (const char *what)
{
if (timestamp_index < timestamp_cnt) {
timestamps[timestamp_index].when = GetMicroSeconds();
timestamps[timestamp_index].what = what;
++timestamp_index;
}
}

void
jack_dump_timestamps (FILE *out)
{
unsigned long i;

for (i = 0; i < timestamp_index; ++i) {
fprintf (out, "%-.32s %" PRIu64 " %" PRIu64,
timestamps[i].what, timestamps[i].when,
timestamps[i].when - timestamps[0].when);
if (i > 0) {
fprintf (out, " %" PRIu64,
timestamps[i].when - timestamps[i-1].when);
}
fputc ('\n', out);
}
}

void
jack_reset_timestamps ()
{
timestamp_index = 0;
}


+ 40
- 0
common/timestamps.h View File

@@ -0,0 +1,40 @@
/*
Copyright (C) 2002 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/

#ifndef __jack_timestamps_h__
#define __jack_timestamps_h__

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

void jack_init_timestamps (unsigned long howmany);
void jack_timestamp (const char *what);
void jack_dump_timestamps (FILE *out);
void jack_reset_timestamps ();

#ifdef __cplusplus
}
#endif

#endif /* __jack_timestamps_h__ */



Loading…
Cancel
Save