main6.c 830 B

12345678910111213141516171819202122232425262728293031323334
  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. // Test that using the Go profiler in a C program does not crash.
  5. #include <stddef.h>
  6. #include <sys/time.h>
  7. #include "libgo6.h"
  8. int main(int argc, char **argv) {
  9. struct timeval tvstart, tvnow;
  10. int diff;
  11. gettimeofday(&tvstart, NULL);
  12. go_start_profile();
  13. // Busy wait so we have something to profile.
  14. // If we just sleep the profiling signal will never fire.
  15. while (1) {
  16. gettimeofday(&tvnow, NULL);
  17. diff = (tvnow.tv_sec - tvstart.tv_sec) * 1000 * 1000 + (tvnow.tv_usec - tvstart.tv_usec);
  18. // Profile frequency is 100Hz so we should definitely
  19. // get a signal in 50 milliseconds.
  20. if (diff > 50 * 1000)
  21. break;
  22. }
  23. go_stop_profile();
  24. return 0;
  25. }