MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_thread_cpu_time_ns

Function cbm_thread_cpu_time_ns

src/foundation/compat.c:342–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340/* ── Per-thread CPU time ──────────────────────────────────────── */
341
342uint64_t cbm_thread_cpu_time_ns(void) {
343#ifdef _WIN32
344 FILETIME creation, exit_time, kernel, user;
345 if (!GetThreadTimes(GetCurrentThread(), &creation, &exit_time, &kernel, &user)) {
346 return 0;
347 }
348 /* kernel/user each carry a 64-bit count of 100-ns ticks split across a
349 * FILETIME's two DWORDs; recombine, sum, and scale to nanoseconds. The
350 * shift-combine avoids casting to ULARGE_INTEGER (alignment-unsafe per
351 * MSDN, and its union members trip cppcheck's unreadVariable). */
352 uint64_t kernel_ticks = ((uint64_t)kernel.dwHighDateTime << 32) | kernel.dwLowDateTime;
353 uint64_t user_ticks = ((uint64_t)user.dwHighDateTime << 32) | user.dwLowDateTime;
354 return (kernel_ticks + user_ticks) * 100ULL;
355#else
356 struct timespec ts;
357 if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0) {
358 return 0;
359 }
360 return (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec;
361#endif
362}
363
364/* ── getline (Windows lacks it) ───────────────────────────────── */
365

Callers 3

cbm_timeout_cbFunction · 0.85
extract_cpp_branch_viewsFunction · 0.85
extract_file_ex_bodyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected