Changes to get Perfetto tracing in Chrome for Windows

A thin compatibility layer and some #ifdefs are enough to let the code
compile. Wrappers for writev are added, and getuid and geteuid just
return 0. SleepMicroseconds is added to replace usleep and a useconds_t
type is added.

This is sufficient to get Chrome building with Perfetto tracing
enabled, on Windows.

Bug: 78878306
Change-Id: I1297e2dbf1f5e99da1659be85064f4abf76607d9
diff --git a/src/base/time.cc b/src/base/time.cc
index c371eb6..8e22d59 100644
--- a/src/base/time.cc
+++ b/src/base/time.cc
@@ -19,10 +19,15 @@
 
 #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
 #include <Windows.h>
+#else
+#include <unistd.h>
+#endif
 
 namespace perfetto {
 namespace base {
 
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+
 TimeNanos GetWallTimeNs() {
   LARGE_INTEGER freq;
   ::QueryPerformanceFrequency(&freq);
@@ -44,7 +49,21 @@
   return TimeNanos((kernel_time + user_time) * 100);
 }
 
-}  // namespace base
-}  // namespace perfetto
+void SleepMicroseconds(unsigned interval_us) {
+  // The Windows Sleep function takes a millisecond count. Round up so that
+  // short sleeps don't turn into a busy wait. Note that the sleep granularity
+  // on Windows can dynamically vary from 1 ms to ~16 ms, so don't count on this
+  // being a short sleep.
+  ::Sleep(static_cast<DWORD>((interval_us + 999) / 1000));
+}
+
+#else  // PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+
+void SleepMicroseconds(unsigned interval_us) {
+  ::usleep(static_cast<useconds_t>(interval_us));
+}
 
 #endif  // PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+
+}  // namespace base
+}  // namespace perfetto