From e1e1abd8c634ba6c69ba34833ac4f39c357e274c Mon Sep 17 00:00:00 2001 From: hadaq Date: Thu, 2 Sep 2010 17:07:32 +0000 Subject: [PATCH] PID and core nr added. Sergey. --- hadaq/evtbuild.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/hadaq/evtbuild.c b/hadaq/evtbuild.c index 98de09b..419a204 100644 --- a/hadaq/evtbuild.c +++ b/hadaq/evtbuild.c @@ -1,4 +1,4 @@ -static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.131 2010-08-23 12:43:52 hadaq Exp $"; +static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.132 2010-09-02 17:07:32 hadaq Exp $"; #define _POSIX_C_SOURCE 199309L #define SYSLOG_NAMES @@ -20,6 +20,8 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada #include #include #include +#include +#include #include @@ -165,6 +167,8 @@ typedef struct TheStatsS { unsigned long *dataMover; unsigned long *diskNr; unsigned long *diskNrEB; + unsigned long *PID; + unsigned long *coreNr; } TheStats; typedef struct TheDebugS { @@ -854,6 +858,68 @@ static void printTime() printf("Time: %s.%03ld\n", time_string, milliseconds); } +char *itoa(int val, int base) +{ + + static char buf[32] = { 0 }; + + int i = 30; + + for (; val && i; --i, val /= base) + buf[i] = "0123456789abcdef"[val % base]; + + return &buf[i + 1]; + +} + +int countChar(char *string, char *char2count) +{ + int cnt = 0; + int i; + + for (i = strlen(string) - 1; i >= 0 && strchr(char2count, string[i]) != NULL; i--) + cnt++; + + return cnt; +} + +static void addCoreAffinity2Stat(TheStats *theStats, int interval) +{ + unsigned long new_mask = 2; + unsigned int len = sizeof(new_mask); + unsigned long cur_mask; + + static once = 1; + static time_t t0 = 0; + time_t t, dT; + + t = time(NULL); + dT = t - t0; + + if (dT >= interval) { + + if (once) { + (*theStats->PID) = (int) getpid(); + once = 0; + } + + sched_getaffinity((pid_t) (*theStats->PID), len, &cur_mask); + + char *buffer; + int nrOfZeros; + + /* Convert to binary */ + buffer = itoa(cur_mask, 2); + + /* Core number is equal to a number of zeros in affinity mask (in binary format) */ + nrOfZeros = countChar(buffer, "0"); + + (*theStats->coreNr) = nrOfZeros; + + t0 = t; + } +} + static int fillDebug(TheArgs *theArgs, TheStats *theStats, TheDebug * theDebug, int i, char *evtStatus) { int j; @@ -2301,6 +2367,7 @@ int main(int argc, char *argv[]) sprintf(buf, "errBit%d", i); theStats->errBit[i] = Worker_addStatistic(worker, buf); } + if (theArgs->debugOptsCnt) { for (i = 0; i < theArgs->nrOfMsgs; i++) { char buf[WORKER_MAX_NAME_LEN]; @@ -2326,6 +2393,9 @@ int main(int argc, char *argv[]) theStats->nrOfMsgs = Worker_addStatistic(worker, "nrOfMsgs"); (*theStats->nrOfMsgs) = theArgs->nrOfMsgs; + theStats->PID = Worker_addStatistic(worker, "PID"); + theStats->coreNr = Worker_addStatistic(worker, "coreNr"); + argsDump(theArgs); Worker_initEnd(worker); @@ -2349,6 +2419,7 @@ int main(int argc, char *argv[]) add2Stat(theArgs, theStats, 1, shmTrans); statsDump(theArgs, theStats, 1); + addCoreAffinity2Stat(theStats, 10); if (*theStats->bytesWritten == 0) { -- 2.43.0