r111617 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111616‎ | r111617 | r111618 >
Date:03:41, 16 February 2012
Author:tstarling
Status:ok
Tags:
Comment:
* Automatically aggregate results into an "all/-" DB/host
* Initialise the addrlen argument to accept() correctly, as documented in the Linux man page
* Use LDLIBS instead of LDFLAGS for -ldb, since that puts the -ldb near the end of the command line, which makes it not break in recent versions of gcc.
Modified paths:
  • /trunk/udpprofile/Makefile (modified) (history)
  • /trunk/udpprofile/collector.c (modified) (history)

Diff [purge]

Index: trunk/udpprofile/collector.c
@@ -31,6 +31,7 @@
3232
3333 void handleMessage(char *,ssize_t );
3434 void handleConnection(int);
 35+void updateEntry(char *dbname, char *hostname, char *task, struct pfstats *incoming);
3536
3637 int main(int ac, char **av) {
3738
@@ -44,7 +45,7 @@
4546 u_int yes=1;
4647 int port;
4748 struct sockaddr_in me, them;
48 - socklen_t sl;
 49+ socklen_t sl = sizeof(struct sockaddr_in);
4950
5051 struct pollfd fds[2];
5152
@@ -109,15 +110,13 @@
110111 char hostname[128];
111112 char dbname[128];
112113 char task[1024];
113 - char keytext[1500];
114114 int r;
115115
116 - struct pfstats incoming,*old;
 116+ struct pfstats incoming;
117117 /* db host count cpu cpusq real realsq eventdescription */
118118 const char msgformat[]="%127s %127s %ld %lf %lf %lf %lf %1023[^\n]";
119119
120120
121 - DBT key,data;
122121
123122 buf[l]=0;
124123 pp=buf;
@@ -135,39 +134,51 @@
136135 &incoming.pf_real,&incoming.pf_real_sq, (char *)&task);
137136 if (r<7)
138137 continue;
139 - snprintf(keytext,1499,"%s:%s:%s",dbname,hostname,task);
140138
141 - bzero(&key,sizeof(key));
142 - bzero(&data,sizeof(data));
143 - key.data=keytext;
144 - key.size=strlen(keytext);
 139+ // Update the DB-specific entry
 140+ updateEntry(dbname, hostname, task, &incoming);
145141
146 - /* Add new values if exists, put in fresh structure if not */
147 - if (db->get(db,NULL,&key,&data,0)==0) {
148 - /* Update old stuff */
149 - old=data.data;
150 - old->pf_count += incoming.pf_count;
151 - old->pf_cpu += incoming.pf_cpu;
152 - old->pf_cpu_sq += incoming.pf_cpu_sq;
153 - old->pf_real += incoming.pf_real;
154 - old->pf_real_sq += incoming.pf_real_sq;
155 - old->pf_reals[old->pf_real_pointer] = incoming.pf_real;
156 - if (old->pf_real_pointer == POINTS-1) {
157 - old->pf_real_pointer = 0;
158 - } else {
159 - old->pf_real_pointer++;
160 - }
161 - db->put(db,NULL,&key,&data,0);
162 - } else {
163 - /* Put in fresh data */
164 - incoming.pf_real_pointer = 1;
165 - incoming.pf_reals[0] = incoming.pf_real;
166 - data.data=&incoming;
167 - data.size=sizeof(incoming);
168 - db->put(db,NULL,&key,&data,0);
 142+ // Update the aggregate entry
 143+ updateEntry("all", "-", task, &incoming);
 144+ }
 145+}
 146+
 147+void updateEntry(char *dbname, char *hostname, char *task, struct pfstats *incoming) {
 148+ char keytext[1500];
 149+ DBT key,data;
 150+ struct pfstats *old;
 151+
 152+ snprintf(keytext,1499,"%s:%s:%s",dbname,hostname,task);
 153+
 154+ bzero(&key,sizeof(key));
 155+ bzero(&data,sizeof(data));
 156+ key.data=keytext;
 157+ key.size=strlen(keytext);
 158+
 159+ /* Add new values if exists, put in fresh structure if not */
 160+ if (db->get(db,NULL,&key,&data,0)==0) {
 161+ /* Update old stuff */
 162+ old=data.data;
 163+ old->pf_count += incoming->pf_count;
 164+ old->pf_cpu += incoming->pf_cpu;
 165+ old->pf_cpu_sq += incoming->pf_cpu_sq;
 166+ old->pf_real += incoming->pf_real;
 167+ old->pf_real_sq += incoming->pf_real_sq;
 168+ old->pf_reals[old->pf_real_pointer] = incoming->pf_real;
 169+ if (old->pf_real_pointer == POINTS-1) {
 170+ old->pf_real_pointer = 0;
 171+ } else {
 172+ old->pf_real_pointer++;
169173 }
170 - }
171 -
 174+ db->put(db,NULL,&key,&data,0);
 175+ } else {
 176+ /* Put in fresh data */
 177+ incoming->pf_real_pointer = 1;
 178+ incoming->pf_reals[0] = incoming->pf_real;
 179+ data.data=incoming;
 180+ data.size=sizeof(*incoming);
 181+ db->put(db,NULL,&key,&data,0);
 182+ }
172183 }
173184
174185 void handleConnection(int c) {
Index: trunk/udpprofile/Makefile
@@ -5,7 +5,7 @@
66 #CFLAGS+=-I/sw/include/
77 #LDFLAGS+=-L/sw/lib/
88
9 -LDFLAGS+=-ldb
 9+LDLIBS+=-ldb
1010 CFLAGS+=-Wall -g
1111
1212 all: collector exporter

Sign-offs

UserFlagDate
😂inspected13:54, 22 February 2012

Status & tagging log