trace.c

来自「俄罗斯高人Mamaich的Pocket gcc编译器(运行在PocketPC上)」· C语言 代码 · 共 101 行

C
101
字号
#include <stdlib.h>#include <stdio.h>#include <string.h>#include <stdarg.h>#include <sys/wcebase.h>#include <sys/wcetrace.h>#include <sys/wcefile.h>#ifndef CE_NOTRACEstatic HANDLE __wcetracehnd = NULL;static int   __wcetrace = 0;voidWCETRACESET(int trace){  __wcetrace = trace;}intWCETRACEGET(){  return(__wcetrace);}voidWCETRACEGETENV(){  char *trace, *p;  char  buf[256];  if ((trace = getenv("WCETRACE")) != NULL) {    __wcetrace = 0;    strcpy(buf, trace);    if (strcasecmp(buf, "all") == 0) {      __wcetrace = (WCE_IO|WCE_NETWORK|WCE_SIGNALS|WCE_FIFOS|WCE_TIME|                    WCE_SYNCH|WCE_MALLOC|WCE_VM);      return;    }    for (p = strtok(buf, ":"); p; p = strtok(NULL, ":")) {      if (strcasecmp(p, "io") == 0) {        __wcetrace |= WCE_IO;      } else if (strcasecmp(p, "network") == 0) {        __wcetrace |= WCE_NETWORK;      } else if (strcasecmp(p, "signals") == 0) {        __wcetrace |= WCE_SIGNALS;      } else if (strcasecmp(p, "fifos") == 0) {        __wcetrace |= WCE_FIFOS;      } else if (strcasecmp(p, "time") == 0) {        __wcetrace |= WCE_TIME;      } else if (strcasecmp(p, "synch") == 0) {        __wcetrace |= WCE_SYNCH;      } else if (strcasecmp(p, "malloc") == 0) {        __wcetrace |= WCE_MALLOC;      } else if (strcasecmp(p, "vm") == 0) {        __wcetrace |= WCE_VM;      }    }  }}voidWCETRACE(int level, const char *fmt, ...){  char buf[1024];  char tracepath[256];  wchar_t tracepathw[256];  int nwritten;  int len = 0;  va_list ap;  if(!(__wcetrace & level))    return;  if (__wcetracehnd == NULL) {    sprintf(tracepath, "/temp/wcetrace%u.log", getpid());    mbstowcs(tracepathw, tracepath, strlen(tracepath) + 1);    __wcetracehnd = CreateFileW(tracepathw, GENERIC_WRITE,       FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL);  }#if 1  len = sprintf(buf, "%08X:%08X: ", GetTickCount(), GetCurrentThreadId());#else  len = sprintf(buf, "%08d:%08x: ", GetTickCount(), GetCurrentProcessId());#endif  if(__wcetracehnd != INVALID_HANDLE_VALUE) {    va_start(ap, fmt);    vsprintf(buf + len, fmt, ap);    strcat(buf, "\n");    WriteFile(__wcetracehnd, buf, strlen(buf), (DWORD *)&nwritten, NULL);    FlushFileBuffers(__wcetracehnd);  }}#endif // CE_NOTRACE

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?