Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

41 lignes
1.1 KiB

  1. #pragma once
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <time.h>
  5. struct Profiler {
  6. inline thread_local static int thread_id = 0;
  7. inline thread_local static FILE* out_file = nullptr;
  8. inline static char file_template[40] = "\0";
  9. Profiler(const char* file, const char* func, const int line) {
  10. if (!out_file) {
  11. time_t t = time(NULL);
  12. tm tm_i;
  13. localtime_s(&tm_i, &t);
  14. if (!file_template[0]) {
  15. sprintf(file_template, "%02d.%02d.%04d-%02d.%02d.%02d-%%02d-profiler.report",
  16. tm_i.tm_mday, tm_i.tm_mon+1, tm_i.tm_year+1900,
  17. tm_i.tm_hour, tm_i.tm_min, tm_i.tm_sec);
  18. }
  19. char file_name[38];
  20. sprintf(file_name, file_template, thread_id);
  21. fopen_s(&out_file, file_name, "w");
  22. if (!out_file) {
  23. printf("could not open %s\n", file_name);
  24. }
  25. }
  26. fprintf(out_file, "-> %s %s %d\n", func, file, line);
  27. };
  28. ~Profiler() {
  29. fprintf(out_file, "<-\n");
  30. };
  31. };
  32. #define profile_this Profiler profiler(__FILE__, __FUNCTION__, __LINE__)