#include <mono/utils/mono-threads.h>
#include <mono/utils/os-event.h>
#include <mono/utils/mono-state.h>
+#include <mono/utils/mono-time.h>
#include <mono/mini/debugger-state-machine.h>
#include "mini.h"
g_error ("%s: mach_port_deallocate () returned %d", __func__, ret);
}
-static guint64
-clock_get_time_ns (void)
-{
- kern_return_t ret;
- mach_timespec_t mach_ts;
-
- do {
- ret = clock_get_time (sampling_clock_service, &mach_ts);
- } while (ret == KERN_ABORTED);
-
- if (ret != KERN_SUCCESS)
- g_error ("%s: clock_get_time () returned %d", __func__, ret);
-
- return ((guint64) mach_ts.tv_sec * 1000000000) + (guint64) mach_ts.tv_nsec;
-}
-
static void
clock_sleep_ns_abs (guint64 ns_abs)
{
{
}
-static guint64
-clock_get_time_ns (void)
-{
- struct timespec ts;
-
- if (clock_gettime (sampling_posix_clock, &ts) == -1)
- g_error ("%s: clock_gettime () returned -1, errno = %d", __func__, errno);
-
- return ((guint64) ts.tv_sec * 1000000000) + (guint64) ts.tv_nsec;
-}
-
static void
clock_sleep_ns_abs (guint64 ns_abs)
{
* nanoseconds).
*/
do {
- diff = (gint64) ns_abs - (gint64) clock_get_time_ns ();
+ diff = (gint64) ns_abs - (gint64) mono_clock_get_time_ns ();
if (diff <= 0)
break;
clock_init (mode);
- for (guint64 sleep = clock_get_time_ns (); mono_atomic_load_i32 (&sampling_thread_running); clock_sleep_ns_abs (sleep)) {
+ for (guint64 sleep = mono_clock_get_time_ns (); mono_atomic_load_i32 (&sampling_thread_running); clock_sleep_ns_abs (sleep)) {
uint32_t freq;
MonoProfilerSampleMode new_mode;
#include <mono/utils/mono-compiler.h>
#include <mono/utils/mono-proclib.h>
#include <mono/utils/mono-state.h>
+#include <mono/utils/mono-time.h>
#include <mono/metadata/w32handle.h>
#include <mono/metadata/threadpool.h>
} JitCodeLoadRecord;
static void add_file_header_info (FileHeader *header);
-static guint64 get_time_stamp_ns (void);
static void add_basic_JitCodeLoadRecord_info (JitCodeLoadRecord *record);
void
header->elf_mach = ELF_MACHINE;
header->pad1 = 0;
header->pid = perf_dump_pid;
- header->timestamp = get_time_stamp_ns ();
+ header->timestamp = mono_clock_get_time_ns ();
header->flags = 0;
}
-static guint64
-get_time_stamp_ns (void)
-{
- struct timespec ts;
- int result = clock_gettime (CLOCK_MONOTONIC, &ts);
- return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
-}
-
void
mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code)
{
// TODO: write debugInfo and unwindInfo immediately before the JitCodeLoadRecord (while lock is held).
- record.header.timestamp = get_time_stamp_ns ();
+ record.header.timestamp = mono_clock_get_time_ns ();
fwrite (&record, sizeof (record), 1, perf_dump_file);
fwrite (jinfo->d.method->name, nameLen + 1, 1, perf_dump_file);
add_basic_JitCodeLoadRecord_info (JitCodeLoadRecord *record)
{
record->header.id = JIT_CODE_LOAD;
- record->header.timestamp = get_time_stamp_ns ();
+ record->header.timestamp = mono_clock_get_time_ns ();
record->pid = perf_dump_pid;
record->tid = syscall (SYS_gettid);
}
#endif
+#ifdef HOST_DARWIN
+
+static clock_serv_t sampling_clock_service;
+
+guint64
+mono_clock_get_time_ns (void)
+{
+ kern_return_t ret;
+ mach_timespec_t mach_ts;
+
+ do {
+ ret = clock_get_time (sampling_clock_service, &mach_ts);
+ } while (ret == KERN_ABORTED);
+
+ if (ret != KERN_SUCCESS)
+ g_error ("%s: clock_get_time () returned %d", __func__, ret);
+
+ return ((guint64) mach_ts.tv_sec * 1000000000) + (guint64) mach_ts.tv_nsec;
+}
+
+#else
+
+static clockid_t sampling_posix_clock;
+
+guint64
+mono_clock_get_time_ns (void)
+{
+ struct timespec ts;
+
+ if (clock_gettime (sampling_posix_clock, &ts) == -1)
+ g_error ("%s: clock_gettime () returned -1, errno = %d", __func__, errno);
+
+ return ((guint64) ts.tv_sec * 1000000000) + (guint64) ts.tv_nsec;
+}
+
+#endif
gint64 mono_100ns_datetime_from_timeval (struct timeval tv);
#endif
+guint64 mono_clock_get_time_ns (void);
+
/* Stopwatch class for internal runtime use */
typedef struct {
gint64 start, stop;