[njs] nxt_trace files have been missed in the previous commit.

Igor Sysoev igor at sysoev.ru
Thu Aug 4 13:32:07 UTC 2016


details:   http://hg.nginx.org/njs/rev/b33ba39a1108
branches:  
changeset: 141:b33ba39a1108
user:      Igor Sysoev <igor at sysoev.ru>
date:      Thu Aug 04 16:27:38 2016 +0300
description:
nxt_trace files have been missed in the previous commit.

diffstat:

 nxt/nxt_trace.c |  57 +++++++++++++++++++++++++++++++++++++++++++++++
 nxt/nxt_trace.h |  68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 0 deletions(-)

diffs (133 lines):

diff -r 23598cfcfd15 -r b33ba39a1108 nxt/nxt_trace.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nxt/nxt_trace.c	Thu Aug 04 16:27:38 2016 +0300
@@ -0,0 +1,57 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#include <nxt_auto_config.h>
+#include <nxt_types.h>
+#include <nxt_clang.h>
+#include <nxt_malloc.h>
+#include <nxt_trace.h>
+#include <stdio.h>
+
+
+static u_char *
+nxt_last_handler(nxt_trace_t *trace, nxt_trace_data_t *td, u_char *start)
+{
+    int      n;
+    ssize_t  size;
+
+    size = td->end - start;
+    n = vsnprintf((char *) start, size, td->fmt, td->args);
+
+    if (n < size) {
+        start += n;
+    }
+
+    return start;
+}
+
+
+void
+nxt_trace_handler(nxt_trace_t *trace, uint32_t level, const char *fmt, ...)
+{
+    u_char            *start;
+    nxt_trace_t       last;
+    nxt_trace_data_t  td;
+
+    td.level = level;
+    td.fmt = fmt;
+
+    va_start(td.args, fmt);
+
+    start = alloca(trace->size);
+    td.end = start + trace->size;
+
+    last.handler = nxt_last_handler;
+    trace->next = &last;
+
+    while (trace->prev != NULL) {
+        trace = trace->prev;
+    }
+
+    (void) trace->handler(trace, &td, start);
+
+    va_end(td.args);
+}
diff -r 23598cfcfd15 -r b33ba39a1108 nxt/nxt_trace.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nxt/nxt_trace.h	Thu Aug 04 16:27:38 2016 +0300
@@ -0,0 +1,68 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#ifndef _NXT_TRACE_H_INCLUDED_
+#define _NXT_TRACE_H_INCLUDED_
+
+
+typedef enum {
+    NXT_LEVEL_CRIT = 0,
+    NXT_LEVEL_ERROR,
+    NXT_LEVEL_WARN,
+    NXT_LEVEL_INFO,
+    NXT_LEVEL_TRACE,
+} nxt_trace_level_t;
+
+
+typedef struct {
+    uint32_t             level;
+    u_char               *end;
+    const char           *fmt;
+    va_list              args;
+} nxt_trace_data_t;
+
+
+typedef struct nxt_trace_s  nxt_trace_t;
+
+typedef u_char *(*nxt_trace_handler_t)(nxt_trace_t *trace, nxt_trace_data_t *td,
+    u_char *start);
+
+struct nxt_trace_s {
+    uint32_t             level;
+    uint32_t             size;
+    nxt_trace_handler_t  handler;
+    void                 *data;
+    nxt_trace_t          *prev;
+    nxt_trace_t          *next;
+};
+
+
+#define nxt_alert(_trace, _level, ...)                                        \
+    do {                                                                      \
+        nxt_trace_t  *_trace_ = _trace;                                       \
+        uint32_t     _level_ = _level;                                        \
+                                                                              \
+        if (nxt_slow_path(_trace_->level >= _level_)) {                       \
+            nxt_trace_handler(_trace_, _level_, __VA_ARGS__);                 \
+        }                                                                     \
+    } while (0)
+
+
+#define nxt_trace(_trace, ...)                                                \
+    do {                                                                      \
+        nxt_trace_t  *_trace_ = _trace;                                       \
+                                                                              \
+        if (nxt_slow_path(_trace_->level == NXT_LEVEL_TRACE)) {               \
+            nxt_trace_handler(_trace_, NXT_LEVEL_TRACE, __VA_ARGS__);         \
+        }                                                                     \
+    } while (0)
+
+
+NXT_EXPORT void nxt_trace_handler(nxt_trace_t *trace, uint32_t level,
+    const char *fmt, ...);
+
+
+#endif /* _NXT_TRACE_H_INCLUDED_ */



More information about the nginx-devel mailing list