github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/go/misc/cgo/testcarchive/main6.c (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Test that using the Go profiler in a C program does not crash. 6 7 #include <stddef.h> 8 #include <sys/time.h> 9 10 #include "libgo6.h" 11 12 int main(int argc, char **argv) { 13 struct timeval tvstart, tvnow; 14 int diff; 15 16 gettimeofday(&tvstart, NULL); 17 18 go_start_profile(); 19 20 // Busy wait so we have something to profile. 21 // If we just sleep the profiling signal will never fire. 22 while (1) { 23 gettimeofday(&tvnow, NULL); 24 diff = (tvnow.tv_sec - tvstart.tv_sec) * 1000 * 1000 + (tvnow.tv_usec - tvstart.tv_usec); 25 26 // Profile frequency is 100Hz so we should definitely 27 // get a signal in 50 milliseconds. 28 if (diff > 50 * 1000) 29 break; 30 } 31 32 go_stop_profile(); 33 return 0; 34 }