[master] 18ad341 Support for optional Summing function.

Poul-Henning Kamp phk at FreeBSD.org
Sat May 27 10:58:06 CEST 2017


commit 18ad341a78c8efa7e190b8f6f6d4af7b8af67990
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat May 27 07:05:57 2017 +0000

    Support for optional Summing function.
    
    We don't optimize but emit straight C-code summing each element in
    turn, so that it will work with any arithmetic C type down the road.

diff --git a/bin/varnishd/main.vsc b/bin/varnishd/main.vsc
index 242681d..16106f7 100644
--- a/bin/varnishd/main.vsc
+++ b/bin/varnishd/main.vsc
@@ -7,6 +7,7 @@
 
 .. varnish_vsc_begin::	main
 	:oneliner:	Main counters
+	:sumfunction:
 
 .. varnish_vsc:: uptime
 	:oneliner:	Child process uptime
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index 0a4a17b..432f67f 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -120,11 +120,18 @@ class vscset(object):
 			fo.write("\tuint64_t\t%s;\n" % i.arg)
 		fo.write("};\n")
 		fo.write("\n");
+
 		fo.write(self.struct + " *VSC_" + self.name + "_New")
 		fo.write("(const char *fmt, ...);\n");
+
 		fo.write("void VSC_" + self.name + "_Destroy")
 		fo.write("(" + self.struct + "**);\n")
 
+		if 'sumfunction' in self.head.param:
+			fo.write("void VSC_" + self.name + "_Summ")
+			fo.write("(" + self.struct + " *, ")
+			fo.write("const " + self.struct + " *);\n")
+
 	def emit_c(self):
 		fon="VSC_" + self.name + ".c"
 		fo = open(fon, "w")
@@ -140,6 +147,7 @@ class vscset(object):
 		    (self.name, self.name.upper()))
 
 		self.emit_json(fo)
+
 		fo.write("\n")
 		fo.write(self.struct + "*\n");
 		fo.write("VSC_" + self.name + "_New")
@@ -159,6 +167,7 @@ class vscset(object):
 		fo.write("\tva_end(ap);\n")
 		fo.write("\treturn(retval);\n")
 		fo.write("}\n")
+
 		fo.write("\n")
 		fo.write("void\n")
 		fo.write("VSC_" + self.name + "_Destroy")
@@ -170,6 +179,21 @@ class vscset(object):
 		fo.write("\t*pp = NULL;\n")
 		fo.write("}\n")
 
+		if 'sumfunction' in self.head.param:
+			fo.write("\n")
+			fo.write("void\n")
+			fo.write("VSC_" + self.name + "_Summ")
+			fo.write("(" + self.struct + " *dst, ")
+			fo.write("const " + self.struct + " *src)\n")
+			fo.write("{\n")
+			fo.write("\n")
+			fo.write("\tAN(dst);\n")
+			fo.write("\tAN(src);\n")
+			for i in self.mbrs:
+				fo.write("\tdst->" + i.arg)
+				fo.write(" += src->" + i.arg + ";\n")
+			fo.write("}\n")
+
 #######################################################################
 
 class directive(object):



More information about the varnish-commit mailing list