diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2021-02-01 06:11:18 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2021-02-01 06:11:18 +0000 |
commit | 4f9de1dfebdc66d367d730252d6f224d37e96ee6 (patch) | |
tree | 3750421fabf3aa8a8e1f4f6d5558d489e9d4fe02 /Build/source/libs/xpdf/xpdf-src/goo/Trace.cc | |
parent | 9d694205709f79666458dc2ee685767b28bcd9ac (diff) |
xpdf 4.03
git-svn-id: svn://tug.org/texlive/trunk@57588 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/xpdf/xpdf-src/goo/Trace.cc')
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/Trace.cc | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/Build/source/libs/xpdf/xpdf-src/goo/Trace.cc b/Build/source/libs/xpdf/xpdf-src/goo/Trace.cc new file mode 100644 index 00000000000..4b730e5b97d --- /dev/null +++ b/Build/source/libs/xpdf/xpdf-src/goo/Trace.cc @@ -0,0 +1,114 @@ +//======================================================================== +// +// Trace.cc +// +// Nested tracing. +// +// Copyright 2020 Glyph & Cog, LLC +// +//======================================================================== + +#include <aconf.h> + +#if ENABLE_TRACING + +#include <stdio.h> +#include <stdarg.h> +#include <sys/types.h> +#include <sys/time.h> +#include <unistd.h> +#include "GString.h" +#include "Trace.h" + +// NB: This module is NOT thread-safe. + +static bool traceInitialized = false; +static FILE *traceOut = NULL; + +static void traceInit() { + if (traceInitialized) { + return; + } + //~ this could read an env var to set up an output file + GString *fileName = GString::format("/tmp/trace.{0:d}", (int)getpid()); + traceOut = fopen(fileName->getCString(), "w"); + delete fileName; + traceInitialized = true; +} + +static void traceHeader(char flag, void *handle) { + timeval tv; + gettimeofday(&tv, NULL); + if (handle) { + fprintf(traceOut, "%c %ld %06ld %p ", flag, tv.tv_sec, tv.tv_usec, handle); + } else { + fprintf(traceOut, "%c %ld %06ld 0x0 ", flag, tv.tv_sec, tv.tv_usec); + } +} + +void traceBegin(void *nestHandle, const char *fmt, ...) { + traceInit(); + if (!traceOut) { + return; + } + traceHeader('B', nestHandle); + va_list args; + va_start(args, fmt); + vfprintf(traceOut, fmt, args); + va_end(args); + fprintf(traceOut, "\n"); +} + +void traceEnd(void *nestHandle, const char *fmt, ...) { + traceInit(); + if (!traceOut) { + return; + } + traceHeader('E', nestHandle); + va_list args; + va_start(args, fmt); + vfprintf(traceOut, fmt, args); + va_end(args); + fprintf(traceOut, "\n"); +} + +void traceAlloc(void *resourceHandle, const char *fmt, ...) { + traceInit(); + if (!traceOut) { + return; + } + traceHeader('A', resourceHandle); + va_list args; + va_start(args, fmt); + vfprintf(traceOut, fmt, args); + va_end(args); + fprintf(traceOut, "\n"); +} + +void traceFree(void *resourceHandle, const char *fmt, ...) { + traceInit(); + if (!traceOut) { + return; + } + traceHeader('F', resourceHandle); + va_list args; + va_start(args, fmt); + vfprintf(traceOut, fmt, args); + va_end(args); + fprintf(traceOut, "\n"); +} + +void traceMessage(const char *fmt, ...) { + traceInit(); + if (!traceOut) { + return; + } + traceHeader('M', NULL); + va_list args; + va_start(args, fmt); + vfprintf(traceOut, fmt, args); + va_end(args); + fprintf(traceOut, "\n"); +} + +#endif // ENABLE_TRACING |