]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
PID and core nr added. Sergey.
authorhadaq <hadaq>
Thu, 2 Sep 2010 17:07:32 +0000 (17:07 +0000)
committerhadaq <hadaq>
Thu, 2 Sep 2010 17:07:32 +0000 (17:07 +0000)
hadaq/evtbuild.c

index 98de09ba065490f261f33c0fd9a25d9b0cbc7992..419a204f58f3ae3214401a30cfa002e7a6d586a0 100644 (file)
@@ -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 <sys/utsname.h>
 #include <time.h>
 #include <dirent.h>
+#include <sched.h>
+#include <linux/unistd.h>
 
 #include <syslog.h>
 
@@ -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) {