Add high-resolution timestamp support
This commit is contained in:
parent
afa3600aaa
commit
cf45384a93
@ -26,6 +26,17 @@ LINKFLAGS=-lm
|
||||
|
||||
ifeq (SunOS,$(uname_S))
|
||||
LINKFLAGS+=-lsocket -lnsl
|
||||
UV_OS_FILE=uv-sunos.c
|
||||
endif
|
||||
|
||||
ifeq (Darwin,$(uname_S))
|
||||
LINKFLAGS+=-framework CoreServices
|
||||
UV_OS_FILE=uv-darwin.c
|
||||
endif
|
||||
|
||||
ifeq (Linux,$(uname_S))
|
||||
LINKFLAGS+=-lrt
|
||||
UV_OS_FILE=uv-linux.c
|
||||
endif
|
||||
|
||||
# Need _GNU_SOURCE for strdup?
|
||||
@ -35,8 +46,11 @@ RUNNER_LINKFLAGS=$(LINKFLAGS) -pthread
|
||||
RUNNER_LIBS=
|
||||
RUNNER_SRC=test/runner-unix.c
|
||||
|
||||
uv.a: uv-unix.o uv-common.o ev/ev.o c-ares/ares_query.o
|
||||
$(AR) rcs uv.a uv-unix.o uv-common.o ev/ev.o c-ares/*.o
|
||||
uv.a: uv-unix.o uv-common.o uv-platform.o ev/ev.o c-ares/ares_query.o
|
||||
$(AR) rcs uv.a uv-unix.o uv-platform.o uv-common.o ev/ev.o c-ares/*.o
|
||||
|
||||
uv-platform.o: $(UV_OS_FILE) uv.h uv-unix.h
|
||||
$(CC) $(CFLAGS) -c $(UV_OS_FILE) -o uv-platform.o
|
||||
|
||||
uv-unix.o: uv-unix.c uv.h uv-unix.h
|
||||
$(CC) $(CFLAGS) -c uv-unix.c -o uv-unix.o
|
||||
|
||||
34
uv-darwin.c
Normal file
34
uv-darwin.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "uv.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
uint64_t uv_get_hrtime() {
|
||||
uint64_t time;
|
||||
Nanoseconds enano;
|
||||
time = mach_absolute_time();
|
||||
enano = AbsoluteToNanoseconds(*(AbsoluteTime *)&time);
|
||||
return (*(uint64_t *)&enano);
|
||||
}
|
||||
35
uv-linux.c
Normal file
35
uv-linux.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "uv.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <time.h>
|
||||
|
||||
/*
|
||||
* There's probably some way to get time from Linux than gettimeofday(). What
|
||||
* it is, I don't know.
|
||||
*/
|
||||
uint64_t uv_get_hrtime() {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (ts.tv_sec * NANOSEC + ts.tv_nsec);
|
||||
}
|
||||
28
uv-sunos.c
Normal file
28
uv-sunos.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "uv.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
uint64_t uv_get_hrtime() {
|
||||
return (gethrtime());
|
||||
}
|
||||
5
uv-win.c
5
uv-win.c
@ -1764,3 +1764,8 @@ done:
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_get_hrtime(void) {
|
||||
assert(0 && "implement me");
|
||||
}
|
||||
|
||||
28
uv.h
28
uv.h
@ -372,7 +372,6 @@ struct sockaddr_in uv_ip4_addr(const char* ip, int port);
|
||||
/* Gets the executable path */
|
||||
int uv_get_exepath(char* buffer, size_t* size);
|
||||
|
||||
|
||||
/* the presence of this union forces similar struct layout */
|
||||
union uv_any_handle {
|
||||
uv_tcp_t tcp;
|
||||
@ -397,6 +396,33 @@ typedef struct {
|
||||
|
||||
uv_counters_t* uv_counters();
|
||||
|
||||
#ifndef SEC
|
||||
#define SEC 1
|
||||
#endif
|
||||
|
||||
#ifndef MILLISEC
|
||||
#define MILLISEC 1000
|
||||
#endif
|
||||
|
||||
#ifndef MICROSEC
|
||||
#define MICROSEC 1000000
|
||||
#endif
|
||||
|
||||
#ifndef NANOSEC
|
||||
#define NANOSEC 1000000000
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Returns the current high-resolution real time. This is expressed in
|
||||
* nanoseconds. It is relative to an arbitrary time in the past. It is not
|
||||
* related to the time of day and therefore not subject to clock drift. The
|
||||
* primary use is for measuring performance between intervals.
|
||||
*
|
||||
* Note not every platform can support nanosecond resolution; however, this
|
||||
* value will always be in nanoseconds.
|
||||
*/
|
||||
extern uint64_t uv_get_hrtime(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user