[master] 4e750aa Delay allocating log line data until it's known to be needed in varnishtop

Martin Blix Grydeland martin at varnish-software.com
Mon Sep 15 16:50:31 CEST 2014


commit 4e750aa19841e76011549aabdfb3ede5d980beab
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Mon Sep 15 16:49:19 2014 +0200

    Delay allocating log line data until it's known to be needed in varnishtop

diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 2c195ef..d29aeb8 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -117,7 +117,6 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 	void *priv)
 {
 	struct top *tp, t;
-	char *rd;
 	unsigned int u;
 	unsigned tag;
 	const char *b, *e, *p;
@@ -148,12 +147,7 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 			t.hash = u;
 			t.tag = tag;
 			t.clen = len;
-			t.count = 0;
-			rd = calloc(len+1, 1);
-			AN(rd);
-			memcpy(rd, VSL_CDATA(tr->c->rec.ptr), len);
-			rd[len] = '\0';
-			t.rec_data = rd;
+			t.rec_data = (char *)VSL_CDATA(tr->c->rec.ptr);
 
 			AZ(pthread_mutex_lock(&mtx));
 			tp = VRB_FIND(top_tree, &top_tree_head, &t);
@@ -162,7 +156,6 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 				tp->count += 1.0;
 				/* Reinsert to rebalance */
 				VRB_INSERT(top_tree, &top_tree_head, tp);
-				free(rd);
 			} else {
 				ntop++;
 				tp = calloc(sizeof *tp, 1);
@@ -171,7 +164,8 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 				tp->count = 1.0;
 				tp->clen = len;
 				tp->tag = tag;
-				tp->rec_data = rd;
+				tp->rec_data = strdup(t.rec_data);
+				AN(tp->rec_data);
 				VRB_INSERT(top_tree, &top_tree_head, tp);
 			}
 			AZ(pthread_mutex_unlock(&mtx));



More information about the varnish-commit mailing list