File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 88#include <stdlib.h>
99#include <string.h>
1010#include <time.h>
11+ #ifdef _WIN32
12+ #define WIN32_LEAN_AND_MEAN
13+ #include <windows.h>
14+ #endif
1115
1216/* This example simulates gathering wall and allocation samples. Roughly every
1317 * minute it will export the data, assumes an http://localhost:8126/ location
@@ -63,6 +67,18 @@ static struct ddog_Timespec now_wall(void) {
6367 return dd ;
6468}
6569
70+ // Cross-platform sleep with millisecond precision (sufficient for ~10ms accuracy)
71+ static void sleep_ms (unsigned int ms ) {
72+ #ifdef _WIN32
73+ Sleep (ms );
74+ #else
75+ struct timespec req ;
76+ req .tv_sec = ms / 1000 ;
77+ req .tv_nsec = (long )((ms % 1000 ) * 1000000L );
78+ nanosleep (& req , NULL );
79+ #endif
80+ }
81+
6682static int64_t rand_range_i64 (int64_t min_inclusive , int64_t max_inclusive ) {
6783 if (max_inclusive <= min_inclusive )
6884 return min_inclusive ;
@@ -284,8 +300,7 @@ int main(void) {
284300 }
285301
286302 // Sleep ~10ms, obviously this will drift, this is just an example.
287- struct timespec req = {.tv_sec = 0 , .tv_nsec = WALL_TICK_NS };
288- nanosleep (& req , NULL );
303+ sleep_ms ((unsigned )(WALL_TICK_NS / 1000000 ));
289304 }
290305
291306 printf ("[profiles.c] shutting down\n" );
You can’t perform that action at this time.
0 commit comments