-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
#include <sys/utsname.h>
#include <time.h>
#include <dirent.h>
+#include <sched.h>
+#include <linux/unistd.h>
#include <syslog.h>
unsigned long *dataMover;
unsigned long *diskNr;
unsigned long *diskNrEB;
+ unsigned long *PID;
+ unsigned long *coreNr;
} TheStats;
typedef struct TheDebugS {
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;
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];
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);
add2Stat(theArgs, theStats, 1, shmTrans);
statsDump(theArgs, theStats, 1);
+ addCoreAffinity2Stat(theStats, 10);
if (*theStats->bytesWritten == 0) {