Skip to content

Commit

Permalink
add instrumentation for allocation profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
sflow committed May 30, 2023
1 parent d61d7b3 commit 99d330b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/Linux/hsflowd.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,16 @@ extern "C" {
deleteAdaptorFromHT(sp->adaptorsByMac, ad, "byMac");
if(ad->peer_ifIndex)
deleteAdaptorFromHT(sp->adaptorsByPeerIndex, ad, "byPeerIndex");
if(freeFlag)
if(freeFlag) {
HSPAdaptorNIO *nio = ADAPTOR_NIO(ad);
if(nio->sampler)
myDebug(1, "deleteAdaptor: adaptor %s has sFlow sampler", ad->deviceName);
if(nio->poller)
myDebug(1, "deleteAdaptor: adaptor %s has sFlow poller", ad->deviceName);
if(nio->deviceAlias)
myDebug(1, "deleteAdaptor: adaptor %s has deviceAlias", ad->deviceName);
adaptorFree(ad);
}
}

int deleteMarkedAdaptors(HSP *sp, UTHash *adaptorHT, int freeFlag) {
Expand Down Expand Up @@ -299,16 +307,24 @@ extern "C" {
-----------------___________________________------------------
*/

static __thread int th_n_localIPs = 0;

HSPLocalIP *localIPNew(SFLAddress *ipAddr, char *dev) {
HSPLocalIP *lip = my_calloc(sizeof(HSPLocalIP));
lip->ipAddr = *ipAddr;
lip->dev = my_strdup(dev);
th_n_localIPs++;
return lip;
}

void localIPFree(HSPLocalIP *lip) {
my_free(lip->dev);
my_free(lip);
th_n_localIPs--;
}

int localIPInstances(void) {
return th_n_localIPs;
}

/*_________________---------------------------__________________
Expand Down Expand Up @@ -644,6 +660,10 @@ extern "C" {
installSFlowSettings(sp, sp->sFlowSettings);
}

myDebug(1, "instances: adaptors=%d, localIP=%d",
adaptorInstances(),
localIPInstances());

if(ad_added || ad_removed || ad_cameup || ad_wentdown || ad_changed) {
// test for switch ports
configSwitchPorts(sp); // in readPackets.c
Expand Down
3 changes: 1 addition & 2 deletions src/Linux/hsflowd.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,6 @@ extern "C" {
// cache nio counters per adaptor
typedef struct _HSPAdaptorNIO {
SFLAddress ipAddr;
UTHash *ip4Addrs;
UTHash *ip6Addrs;
EnumHSPDevType devType;
bool up:1;
bool loopback:1;
Expand Down Expand Up @@ -829,6 +827,7 @@ extern "C" {
// local IPs
HSPLocalIP *localIPNew(SFLAddress *ipAddr, char *dev);
void localIPFree(HSPLocalIP *lip);
int localIPInstances(void);

// readPackets.c
#define HSP_SAMPLEOPT_BRIDGE 0x0001
Expand Down
8 changes: 8 additions & 0 deletions src/Linux/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,8 @@ extern "C" {
----------------___________________________------------------
*/

static __thread int th_n_adaptors=0;

SFLAdaptor *adaptorNew(char *dev, u_char *macBytes, size_t userDataSize, uint32_t ifIndex) {
SFLAdaptor *ad = (SFLAdaptor *)my_calloc(sizeof(SFLAdaptor));
ad->deviceName = my_strdup(dev);
Expand All @@ -1256,6 +1258,7 @@ extern "C" {
memcpy(ad->macs[0].mac, macBytes, 6);
ad->num_macs = 1;
}
th_n_adaptors++;
return ad;
}

Expand All @@ -1275,9 +1278,14 @@ extern "C" {
if(ad->deviceName) my_free(ad->deviceName);
if(ad->userData) my_free(ad->userData);
my_free(ad);
th_n_adaptors--;
}
}

int adaptorInstances(void) {
return th_n_adaptors;
}

/*________________---------------------------__________________
________________ adaptorList __________________
----------------___________________________------------------
Expand Down
1 change: 1 addition & 0 deletions src/Linux/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ extern "C" {
SFLAdaptor *adaptorNew(char *dev, u_char *macBytes, size_t userDataSize, uint32_t ifIndex);
int adaptorEqual(SFLAdaptor *ad1, SFLAdaptor *ad2);
void adaptorFree(SFLAdaptor *ad);
int adaptorInstances(void);

// SFLAdaptorList
SFLAdaptorList *adaptorListNew(void);
Expand Down

0 comments on commit 99d330b

Please sign in to comment.