static void epicsThreadShowHeader (void) { fprintf(epicsGetStdout()," PRIORITY\n"); fprintf(epicsGetStdout()," ID EPICS RTEMS STATE WAIT NAME\n"); fprintf(epicsGetStdout(),"+--------+-----------+--------+--------+---------------------+\n"); }
static void epicsThreadShowInfo (struct taskVar *v, unsigned int level) { fprintf(epicsGetStdout(),"%9.8x", (int)v->id); showInternalTaskInfo (v->id); fprintf(epicsGetStdout()," %s\n", v->name); }
static void helpCallFunc(const iocshArgBuf *args) { int argc = args[0].aval.ac; const char * const * argv = args[0].aval.av; struct iocshFuncDef const *piocshFuncDef; struct iocshCommand *pcmd; if (argc == 1) { int l, col = 0; fprintf(epicsGetStdout(), "Type 'help <command>' to see the arguments of <command>.\n"); iocshTableLock (); for (pcmd = iocshCommandHead ; pcmd != NULL ; pcmd = pcmd->next) { piocshFuncDef = pcmd->pFuncDef; l = strlen (piocshFuncDef->name); if ((l + col) >= 79) { fputc('\n', epicsGetStdout()); col = 0; } fputs(piocshFuncDef->name, epicsGetStdout()); col += l; if (col >= 64) { fputc('\n', epicsGetStdout()); col = 0; } else { do { fputc(' ', epicsGetStdout()); col++; } while ((col % 16) != 0); } } if (col) fputc('\n', epicsGetStdout()); iocshTableUnlock (); } else { for (int iarg = 1 ; iarg < argc ; iarg++) { for (pcmd = iocshCommandHead ; pcmd != NULL ; pcmd = pcmd->next) { piocshFuncDef = pcmd->pFuncDef; if (epicsStrGlobMatch(piocshFuncDef->name, argv[iarg]) != 0) { fputs(piocshFuncDef->name, epicsGetStdout()); for (int a = 0 ; a < piocshFuncDef->nargs ; a++) { const char *cp = piocshFuncDef->arg[a]->name; if ((piocshFuncDef->arg[a]->type == iocshArgArgv) || (strchr (cp, ' ') == NULL)) { fprintf(epicsGetStdout(), " %s", cp); } else { fprintf(epicsGetStdout(), " '%s'", cp); } } fprintf(epicsGetStdout(),"\n");; } } } } }
static void epicsThreadShowInfo (struct taskVar *v, unsigned int level) { if (!v) { fprintf(epicsGetStdout()," PRIORITY\n"); fprintf(epicsGetStdout()," ID EPICS RTEMS STATE WAIT NAME\n"); fprintf(epicsGetStdout(),"+--------+-----------+--------+--------+---------------------+\n"); } else { fprintf(epicsGetStdout(),"%9.8x", (int)v->id); showInternalTaskInfo (v->id); fprintf(epicsGetStdout()," %s\n", v->name); } }
/* * Internal commands */ static void varHandler(const iocshVarDef *v, const char *setString) { switch(v->type) { default: fprintf(epicsGetStderr(), "Can't handle variable %s of type %d.\n", v->name, v->type); return; case iocshArgInt: break; case iocshArgDouble: break; } if(setString == NULL) { switch(v->type) { default: break; case iocshArgInt: fprintf(epicsGetStdout(), "%s = %d\n", v->name, *(int *)v->pval); break; case iocshArgDouble: fprintf(epicsGetStdout(), "%s = %g\n", v->name, *(double *)v->pval); break; } } else { switch(v->type) { default: break; case iocshArgInt: { char *endp; long ltmp = strtol(setString, &endp, 0); if((*setString != '\0') && (*endp == '\0')) *(int *)v->pval = ltmp; else fprintf(epicsGetStderr(), "Invalid integer value. Var %s not changed.\n", v->name); break; } case iocshArgDouble: { char *endp; double dtmp = epicsStrtod(setString, &endp); if((*setString != '\0') && (*endp == '\0')) *(double *)v->pval = dtmp; else fprintf(epicsGetStderr(), "Invalid double value. Var %s not changed.\n", v->name); break; } } } }
/** * @brief Print one line of thread info. * * @param pthreadInfo thread id to print line for, NULL = print header line * @param level verbosity level (unused) */ static void mcoreThreadShowPrint(epicsThreadOSD *pthreadInfo, unsigned int level) { if (!pthreadInfo) { fprintf(epicsGetStdout(), " NAME EPICS ID " "LWP ID OSIPRI OSSPRI STATE POLICY CPUSET\n"); } else { struct sched_param param; int priority = 0; int policy; policies = "?"; cpuspec[0] = '?'; cpuspec[1] = '\0'; if (pthreadInfo->tid) { cpu_set_t cpuset; int status; status = pthread_getschedparam(pthreadInfo->tid, &policy, ¶m); if (errVerbose) checkStatus(status,"pthread_getschedparam"); if (!status) { priority = param.sched_priority; policies = policyToStr(policy); } status = pthread_getaffinity_np(pthreadInfo->tid, sizeof(cpu_set_t), &cpuset); if (!status) { cpusetToStr(cpuspec, NO_OF_CPUS+2, &cpuset); } } fprintf(epicsGetStdout(),"%16.16s %14p %8lu %3d%8d %8.8s %7.7s %s\n", pthreadInfo->name, (void *)pthreadInfo, (unsigned long)pthreadInfo->lwpId, pthreadInfo->osiPriority, priority, pthreadInfo->isSuspended ? "SUSPEND" : "OK", policies, cpuspec); } }
int epicsShareAPI epicsStdoutPrintf(const char *pFormat, ...) { va_list pvar; int nchar; FILE *stream = epicsGetStdout(); va_start(pvar, pFormat); nchar = vfprintf(stream, pFormat, pvar); va_end(pvar); return nchar; }
static void showThreadInfo(epicsThreadOSD *pthreadInfo,unsigned int level) { if(!pthreadInfo) { fprintf(epicsGetStdout()," NAME EPICS ID " "PTHREAD ID OSIPRI OSSPRI STATE\n"); } else { struct sched_param param; int policy; int priority = 0; if(pthreadInfo->tid) { int status; status = pthread_getschedparam(pthreadInfo->tid,&policy,¶m); if(!status) priority = param.sched_priority; } fprintf(epicsGetStdout(),"%16.16s %12p %12lu %3d%8d %8.8s\n", pthreadInfo->name,(void *) pthreadInfo,(unsigned long)pthreadInfo->tid, pthreadInfo->osiPriority,priority, pthreadInfo->isSuspended?"SUSPEND":"OK"); } }
void epicsThreadShow (epicsThreadId id, unsigned int level) { struct taskVar *v; if (!id) { epicsThreadShowHeader (); return; } taskVarLock (); for (v = taskVarHead ; v != NULL ; v = v->forw) { if ((rtems_id)id == v->id) { epicsThreadShowInfo (v, level); return; } } taskVarUnlock (); fprintf(epicsGetStdout(),"*** Thread %x does not exist.\n", (unsigned int)id); }
static void showInternalTaskInfo (rtems_id tid) { #ifdef __RTEMS_VIOLATE_KERNEL_VISIBILITY__ int epicsPri; Thread_Control *the_thread; Objects_Locations location; static Thread_Control thread; static char bitbuf[120]; static const struct bitmap taskState[] = { { "RUN", STATES_ALL_SET, STATES_READY }, { "DORM", STATES_DORMANT, STATES_DORMANT }, { "SUSP", STATES_SUSPENDED, STATES_SUSPENDED }, { "TRANS", STATES_TRANSIENT, STATES_TRANSIENT }, { "Delay", STATES_DELAYING, STATES_DELAYING }, { "Wtime", STATES_WAITING_FOR_TIME, STATES_WAITING_FOR_TIME }, { "Wbuf", STATES_WAITING_FOR_BUFFER, STATES_WAITING_FOR_BUFFER }, { "Wseg", STATES_WAITING_FOR_SEGMENT, STATES_WAITING_FOR_SEGMENT }, { "Wmsg" , STATES_WAITING_FOR_MESSAGE, STATES_WAITING_FOR_MESSAGE }, { "Wevnt", STATES_WAITING_FOR_EVENT, STATES_WAITING_FOR_EVENT }, { "Wsem", STATES_WAITING_FOR_SEMAPHORE,STATES_WAITING_FOR_SEMAPHORE }, { "Wmtx", STATES_WAITING_FOR_MUTEX, STATES_WAITING_FOR_MUTEX }, { "Wjoin", STATES_WAITING_FOR_JOIN_AT_EXIT,STATES_WAITING_FOR_JOIN_AT_EXIT }, { "Wrpc", STATES_WAITING_FOR_RPC_REPLY,STATES_WAITING_FOR_RPC_REPLY }, { "Wrate", STATES_WAITING_FOR_PERIOD, STATES_WAITING_FOR_PERIOD }, { "Wsig", STATES_WAITING_FOR_SIGNAL, STATES_WAITING_FOR_SIGNAL }, { NULL, 0, 0 }, }; the_thread = _Thread_Get (tid, &location); if (location != OBJECTS_LOCAL) { fprintf(epicsGetStdout(),"%-30s", " *** RTEMS task gone! ***"); return; } thread = *the_thread; _Thread_Enable_dispatch(); /* * Show both real and current priorities if they differ. * Note that the epicsThreadGetOsiPriorityValue routine is not used here. * If a thread has a priority outside the normal EPICS range then * that priority should be displayed, not the value truncated to * the EPICS range. */ epicsPri = 199-thread.real_priority; if (epicsPri < 0) fprintf(epicsGetStdout()," <0"); else if (epicsPri > 99) fprintf(epicsGetStdout()," >99"); else fprintf(epicsGetStdout()," %4d", epicsPri); if (thread.current_priority == thread.real_priority) fprintf(epicsGetStdout(),"%4d ", (int)thread.current_priority); else fprintf(epicsGetStdout(),"%4d/%-3d", (int)thread.real_priority, (int)thread.current_priority); showBitmap (bitbuf, thread.current_state, taskState); fprintf(epicsGetStdout(),"%8.8s", bitbuf); if (thread.current_state & (STATES_WAITING_FOR_SEMAPHORE | STATES_WAITING_FOR_MUTEX | STATES_WAITING_FOR_MESSAGE)) fprintf(epicsGetStdout()," %8.8x", (int)thread.Wait.id); else fprintf(epicsGetStdout()," %8.8s", ""); #endif }
int epicsShareAPI epicsStdoutPutchar(int c) { return putc(c, epicsGetStdout()); }
int epicsShareAPI epicsStdoutPuts(const char *str) { return fprintf(epicsGetStdout(), "%s\n", str); }
void testStdoutRedir (const char *report) { FILE *realStdout = stdout; FILE *stream = 0; char linebuf[80]; size_t buflen = sizeof linebuf; testOk1(epicsGetStdout() == stdout); errno = 0; if (!testOk1((stream = fopen(report, "w")) != NULL)) { testDiag("'%s' could not be opened for writing: %s", report, strerror(errno)); testSkip(11, "Can't create stream file"); return; } epicsSetThreadStdout(stream); testOk1(stdout == stream); printf(LINE_1); printf(LINE_2); epicsSetThreadStdout(0); testOk1(epicsGetStdout() == realStdout); testOk1(stdout == realStdout); errno = 0; if (!testOk1(!fclose(stream))) { testDiag("fclose error: %s", strerror(errno)); #ifdef vxWorks testDiag("The above test fails if you don't cd to a writable directory"); testDiag("before running the test. The next test will also fail..."); #endif } if (!testOk1((stream = fopen(report, "r")) != NULL)) { testDiag("'%s' could not be opened for reading: %s", report, strerror(errno)); testSkip(6, "Can't reopen stream file."); return; } if (!testOk1(fgets(linebuf, buflen, stream) != NULL)) { testDiag("File read error: %s", strerror(errno)); testSkip(5, "Read failed."); fclose(stream); return; } testOk(strcmp(linebuf, LINE_1) == 0, "First line correct"); if (!testOk1(fgets(linebuf, buflen, stream) != NULL)) { testDiag("File read error: %s", strerror(errno)); testSkip(1, "No line to compare."); } else testOk(strcmp(linebuf, LINE_2) == 0, "Second line"); testOk(!fgets(linebuf, buflen, stream), "File ends"); if (!testOk1(!fclose(stream))) testDiag("fclose error: %s\n", strerror(errno)); }