45 #define _RPMZLOG_INTERNAL
65 #define _RPMZLOG_MAXMSG 256
76 fprintf(stderr,
" ++ zlog %p[%ld]\n", zlog, nrefs+1);
86 zlog->msg_head = NULL;
87 zlog->msg_tail = &zlog->msg_head;
94 (
void) gettimeofday(&zlog->start, NULL);
112 xx = gettimeofday(&now, NULL);
113 me = (rpmzMsg)
xmalloc(
sizeof(*me));
116 xx =
vsnprintf(msg,
sizeof(msg)-1, fmt, ap);
118 msg[
sizeof(msg)-1] =
'\0';
121 me->msg = (
char *)
xmalloc(strlen(msg) + 1);
123 strcpy(me->msg, msg);
128 assert(zlog->_item.use != NULL);
130 *zlog->msg_tail = me;
131 zlog->msg_tail = &me->next;
152 if (zlog->msg_tail == NULL || (me = zlog->msg_head) == NULL) {
156 zlog->msg_head = me->next;
157 if (me->next == NULL)
158 zlog->msg_tail = &zlog->msg_head;
162 diff.tv_usec = me->when.tv_usec - zlog->start.tv_usec;
163 diff.tv_sec = me->when.tv_sec - zlog->start.tv_sec;
164 if (diff.tv_usec < 0) {
165 diff.tv_usec += 1000000
L;
168 fprintf(fp,
"trace %ld.%06ld %s\n",
169 (
long)diff.tv_sec, (
long)diff.tv_usec, me->msg);
171 me->msg =
_free(me->msg);
187 fprintf(stderr,
" -- zlog %p[%ld]\n", zlog, nrefs);
192 fprintf(stderr,
"==> FIXME: %s: zlog %p[%ld]\n", __FUNCTION__, zlog, nrefs);
196 if (zlog->msg_tail != NULL) {
197 while ((me = zlog->msg_head) != NULL) {
198 zlog->msg_head = me->next;
199 me->msg =
_free(me->msg);
206 assert(zlog->msg_count == 0);
208 if (zlog->msg_count != 0)
209 fprintf(stderr,
"==> FIXME: %s: zlog %p[%ld] count %d\n", __FUNCTION__, zlog, nrefs, zlog->msg_count);
212 zlog->msg_tail = NULL;
rpmzLog rpmzLogLink(rpmzLog zlog)
Reference the log data.
void yarnTwist(yarnLock bolt, yarnTwistOP op, long val)
void rpmzLogAdd(rpmzLog zlog, const char *fmt,...)
Add entry to trace log.
void yarnPossess(yarnLock bolt)
long yarnPeekLock(yarnLock bolt)
rpmzLog rpmzLogDump(rpmzLog zlog, FILE *fp)
Show entries until no more, free log.
Job queue and buffer pool management.
rpmzLog rpmzLogFree(rpmzLog zlog)
Release a reference to the log data.
static int rpmzMsgShow(rpmzLog zlog, FILE *fp)
void * xcalloc(size_t nmemb, size_t size)
static int _rpmzlog_debug
struct rpmzLog_s * rpmzLog
trace log pointer
yarnLock yarnNewLock(long initial)
yarnLock yarnFreeLock(yarnLock bolt)
void yarnRelease(yarnLock bolt)
static int vsnprintf(char *buf, int nb, const char *fmt, va_list ap)
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
rpmzLog rpmzLogNew(struct timeval *tv)
Set up log (call from main thread before other threads launched).