Skip to content

Commit 99d330b

Browse files
committed
add instrumentation for allocation profiling
1 parent d61d7b3 commit 99d330b

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/Linux/hsflowd.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,16 @@ extern "C" {
181181
deleteAdaptorFromHT(sp->adaptorsByMac, ad, "byMac");
182182
if(ad->peer_ifIndex)
183183
deleteAdaptorFromHT(sp->adaptorsByPeerIndex, ad, "byPeerIndex");
184-
if(freeFlag)
184+
if(freeFlag) {
185+
HSPAdaptorNIO *nio = ADAPTOR_NIO(ad);
186+
if(nio->sampler)
187+
myDebug(1, "deleteAdaptor: adaptor %s has sFlow sampler", ad->deviceName);
188+
if(nio->poller)
189+
myDebug(1, "deleteAdaptor: adaptor %s has sFlow poller", ad->deviceName);
190+
if(nio->deviceAlias)
191+
myDebug(1, "deleteAdaptor: adaptor %s has deviceAlias", ad->deviceName);
185192
adaptorFree(ad);
193+
}
186194
}
187195

188196
int deleteMarkedAdaptors(HSP *sp, UTHash *adaptorHT, int freeFlag) {
@@ -299,16 +307,24 @@ extern "C" {
299307
-----------------___________________________------------------
300308
*/
301309

310+
static __thread int th_n_localIPs = 0;
311+
302312
HSPLocalIP *localIPNew(SFLAddress *ipAddr, char *dev) {
303313
HSPLocalIP *lip = my_calloc(sizeof(HSPLocalIP));
304314
lip->ipAddr = *ipAddr;
305315
lip->dev = my_strdup(dev);
316+
th_n_localIPs++;
306317
return lip;
307318
}
308319

309320
void localIPFree(HSPLocalIP *lip) {
310321
my_free(lip->dev);
311322
my_free(lip);
323+
th_n_localIPs--;
324+
}
325+
326+
int localIPInstances(void) {
327+
return th_n_localIPs;
312328
}
313329

314330
/*_________________---------------------------__________________
@@ -644,6 +660,10 @@ extern "C" {
644660
installSFlowSettings(sp, sp->sFlowSettings);
645661
}
646662

663+
myDebug(1, "instances: adaptors=%d, localIP=%d",
664+
adaptorInstances(),
665+
localIPInstances());
666+
647667
if(ad_added || ad_removed || ad_cameup || ad_wentdown || ad_changed) {
648668
// test for switch ports
649669
configSwitchPorts(sp); // in readPackets.c

src/Linux/hsflowd.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ extern "C" {
308308
// cache nio counters per adaptor
309309
typedef struct _HSPAdaptorNIO {
310310
SFLAddress ipAddr;
311-
UTHash *ip4Addrs;
312-
UTHash *ip6Addrs;
313311
EnumHSPDevType devType;
314312
bool up:1;
315313
bool loopback:1;
@@ -829,6 +827,7 @@ extern "C" {
829827
// local IPs
830828
HSPLocalIP *localIPNew(SFLAddress *ipAddr, char *dev);
831829
void localIPFree(HSPLocalIP *lip);
830+
int localIPInstances(void);
832831

833832
// readPackets.c
834833
#define HSP_SAMPLEOPT_BRIDGE 0x0001

src/Linux/util.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,8 @@ extern "C" {
12471247
----------------___________________________------------------
12481248
*/
12491249

1250+
static __thread int th_n_adaptors=0;
1251+
12501252
SFLAdaptor *adaptorNew(char *dev, u_char *macBytes, size_t userDataSize, uint32_t ifIndex) {
12511253
SFLAdaptor *ad = (SFLAdaptor *)my_calloc(sizeof(SFLAdaptor));
12521254
ad->deviceName = my_strdup(dev);
@@ -1256,6 +1258,7 @@ extern "C" {
12561258
memcpy(ad->macs[0].mac, macBytes, 6);
12571259
ad->num_macs = 1;
12581260
}
1261+
th_n_adaptors++;
12591262
return ad;
12601263
}
12611264

@@ -1275,9 +1278,14 @@ extern "C" {
12751278
if(ad->deviceName) my_free(ad->deviceName);
12761279
if(ad->userData) my_free(ad->userData);
12771280
my_free(ad);
1281+
th_n_adaptors--;
12781282
}
12791283
}
12801284

1285+
int adaptorInstances(void) {
1286+
return th_n_adaptors;
1287+
}
1288+
12811289
/*________________---------------------------__________________
12821290
________________ adaptorList __________________
12831291
----------------___________________________------------------

src/Linux/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ extern "C" {
226226
SFLAdaptor *adaptorNew(char *dev, u_char *macBytes, size_t userDataSize, uint32_t ifIndex);
227227
int adaptorEqual(SFLAdaptor *ad1, SFLAdaptor *ad2);
228228
void adaptorFree(SFLAdaptor *ad);
229+
int adaptorInstances(void);
229230

230231
// SFLAdaptorList
231232
SFLAdaptorList *adaptorListNew(void);

0 commit comments

Comments
 (0)