int main() { FILE *fp = NULL; if(exist()) return 0;//判断是否有相同程序运行 fileInit(); while(1) { double cpuUsage[33] = {0};//最大支持32核; getAverageCpuUsage(cpuUsage); //写文件 if(((fp = fopen("CpuUsage.log", "at")) == NULL)) { printf("File open faild"); exit(0); } for (int i = 0; i < m_iNumberProcessors + 1; i++) fprintf(fp, "%.3f\t", cpuUsage[i]); fputs("\n",fp); fclose(fp); } return 1; }
// This is done assuming the shards start at 0 and end ate nShards - 1 int initFiles(int nShards) { int i; fileSize = (int*) malloc(sizeof(int) * nShards); freeIDs = (IntegerList**) malloc(sizeof(IntegerList*) * nShards); fileLocks = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t) * nShards); freeIDsLocks = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t) * nShards); if (fileSize == NULL || freeIDs == NULL || fileLocks == NULL) return -1; for (i = 0; i < nShards; i++) { freeIDs[i] = NULL; fileSize[i] = fileInit(i); } return 0; }
////////////////// // Initialize main window. // EditWin::EditWin(LPCSTR fname) { createWin(); // create main window // Create edit control editCtl = new WPMultiEdit(this, 1); createArgs.style |= WS_VSCROLL; editCtl->createWin(); // Create prompt line promptWin = new WPStatic(this, 2); promptWin->createWin(); pmtHeight = tm.tmHeight; fileInit(fname, "WINEDIT"); }
/** * Initializes the hardware/software SD card module. If the SD card is not * inserted, loops waiting to mount it until the SD ready is ready. * * \param int pin_sck - pin used as SPI SCLK signal * \param int pin_si - pin used as SPI MISO signal * \param int pin_so - pin used as SPI MOSI signal * \param int pin_cs - pin used as SD Chip Select signal * \param int pin_cd - pin used as SD Card Detect signal * \param BYTE _nTimeout - timeout of operation (expressed in about 0.1 sec scale, 255 to wait forever) * \return * BOOL result of operation */ BOOL SDInit(int pin_sck, int pin_si, int pin_so, int pin_cs, int pin_cd, BYTE timeout) { BYTE timecnt = 0; // SD hardware initialization pinConfig(pin_sck, pin_si, pin_so, pin_cs, pin_cd); SDdebug("Initializing SD card...\r\n"); if (diskMount()) SDdebug("SD software module initialized!\r\n"); else SDdebug("SD software module NOT initialized!\r\n"); // Check to detect SD card insertion while (disk_status(0)) { diskUnmount(); vTaskDelay(5); SDdebug("."); diskMount(); timecnt++; if ( (timecnt == timeout) && (timeout < 255) ) break; vTaskDelay(5); } if (!disk_status(0)) { SDdebug("SD card initialized and ready!\r\n"); setSdErr(0); fileInit(); sdInitOk = TRUE; return TRUE; } else { SDdebug("ERROR\n"); if (sdDetect()) setSdErr(SD_FS_NOT_INIT); else setSdErr(SD_NOT_PRESENT); sdInitOk = FALSE; return FALSE; } }
VkBool32 VKTS_APIENTRY engineInit() { if (!processorInit()) { VKTS_PRINTF("LOG [VKTS_LOG_ERROR]: Engine: Initialization failed! Could not initialize the processor!\n"); return VK_FALSE; } if (!logInit()) { VKTS_PRINTF("LOG [VKTS_LOG_ERROR]: Engine: Initialization failed! Could not initialize logging.\n"); return VK_FALSE; } if (!timeInit()) { logPrint(VKTS_LOG_ERROR, "Engine: Initialization failed! Could not initialize the timer!"); return VK_FALSE; } if (!barrierInit()) { logPrint(VKTS_LOG_ERROR, "Engine: Initialization failed! Could not initialize the barrier!"); return VK_FALSE; } if (!fileInit()) { logPrint(VKTS_LOG_ERROR, "Engine: Initialization failed! Could not initialize the file system!"); return VK_FALSE; } return VK_TRUE; }
/** * Closes a previously open file. Internal static function not to use in main * application. * \param FIL* file_close - file object to close */ static void fileClose(FIL *file_close) { f_close(file_close); fileInit(); }
static int beginPlot(JOB *analysisPtr, CKTcircuit *circuitPtr, char *cktName, char *analName, char *refName, int refType, int numNames, char **dataNames, int dataType, bool windowed, runDesc **runp) { runDesc *run; struct save_info *saves; bool *savesused = NULL; int numsaves; int i, j, depind = 0; char namebuf[BSIZE_SP], parambuf[BSIZE_SP], depbuf[BSIZE_SP]; char *ch, tmpname[BSIZE_SP]; bool saveall = TRUE; bool savealli = FALSE; char *an_name; /*to resume a run saj *All it does is reassign the file pointer and return (requires *runp to be NULL if this is not needed) */ if (dataType == 666 && numNames == 666) { run = *runp; run->writeOut = ft_getOutReq(&run->fp, &run->runPlot, &run->binary, run->type, run->name); } else { /*end saj*/ /* Check to see if we want to print informational data. */ if (cp_getvar("printinfo", CP_BOOL, NULL)) fprintf(cp_err, "(debug printing enabled)\n"); /* Check to see if we want to save only interpolated data. */ if (cp_getvar("interp", CP_BOOL, NULL)) { interpolated = TRUE; fprintf(cp_out, "Warning: Interpolated raw file data!\n\n"); } *runp = run = TMALLOC(struct runDesc, 1); /* First fill in some general information. */ run->analysis = analysisPtr; run->circuit = circuitPtr; run->name = copy(cktName); run->type = copy(analName); run->windowed = windowed; run->numData = 0; an_name = spice_analysis_get_name(analysisPtr->JOBtype); ft_curckt->ci_last_an = an_name; /* Now let's see which of these things we need. First toss in the * reference vector. Then toss in anything that getSaves() tells * us to save that we can find in the name list. Finally unpack * the remaining saves into parameters. */ numsaves = ft_getSaves(&saves); if (numsaves) { savesused = TMALLOC(bool, numsaves); saveall = FALSE; for (i = 0; i < numsaves; i++) { if (saves[i].analysis && !cieq(saves[i].analysis, an_name)) { /* ignore this one this time around */ savesused[i] = TRUE; continue; } /* Check for ".save all" and new synonym ".save allv" */ if (cieq(saves[i].name, "all") || cieq(saves[i].name, "allv")) { saveall = TRUE; savesused[i] = TRUE; saves[i].used = 1; continue; } /* And now for the new ".save alli" option */ if (cieq(saves[i].name, "alli")) { savealli = TRUE; savesused[i] = TRUE; saves[i].used = 1; continue; } } } /* Pass 0. */ if (refName) { addDataDesc(run, refName, refType, -1); for (i = 0; i < numsaves; i++) if (!savesused[i] && name_eq(saves[i].name, refName)) { savesused[i] = TRUE; saves[i].used = 1; } } else { run->refIndex = -1; } /* Pass 1. */ if (numsaves && !saveall) { for (i = 0; i < numsaves; i++) if (!savesused[i]) for (j = 0; j < numNames; j++) if (name_eq(saves[i].name, dataNames[j])) { addDataDesc(run, dataNames[j], dataType, j); savesused[i] = TRUE; saves[i].used = 1; break; } } else { for (i = 0; i < numNames; i++) if (!refName || !name_eq(dataNames[i], refName)) /* Save the node as long as it's an internal device node */ if (!strstr(dataNames[i], "#internal") && !strstr(dataNames[i], "#source") && !strstr(dataNames[i], "#drain") && !strstr(dataNames[i], "#collector") && !strstr(dataNames[i], "#emitter") && !strstr(dataNames[i], "#base")) { addDataDesc(run, dataNames[i], dataType, i); } } /* Pass 1 and a bit. This is a new pass which searches for all the internal device nodes, and saves the terminal currents instead */ if (savealli) { depind = 0; for (i = 0; i < numNames; i++) { if (strstr(dataNames[i], "#internal") || strstr(dataNames[i], "#source") || strstr(dataNames[i], "#drain") || strstr(dataNames[i], "#collector") || strstr(dataNames[i], "#emitter") || strstr(dataNames[i], "#base")) { tmpname[0] = '@'; tmpname[1] = '\0'; strncat(tmpname, dataNames[i], BSIZE_SP-1); ch = strchr(tmpname, '#'); if (strstr(ch, "#collector")) { strcpy(ch, "[ic]"); } else if (strstr(ch, "#base")) { strcpy(ch, "[ib]"); } else if (strstr(ch, "#emitter")) { strcpy(ch, "[ie]"); if (parseSpecial(tmpname, namebuf, parambuf, depbuf)) addSpecialDesc(run, tmpname, namebuf, parambuf, depind); strcpy(ch, "[is]"); } else if (strstr(ch, "#drain")) { strcpy(ch, "[id]"); if (parseSpecial(tmpname, namebuf, parambuf, depbuf)) addSpecialDesc(run, tmpname, namebuf, parambuf, depind); strcpy(ch, "[ig]"); } else if (strstr(ch, "#source")) { strcpy(ch, "[is]"); if (parseSpecial(tmpname, namebuf, parambuf, depbuf)) addSpecialDesc(run, tmpname, namebuf, parambuf, depind); strcpy(ch, "[ib]"); } else if (strstr(ch, "#internal") && (tmpname[1] == 'd')) { strcpy(ch, "[id]"); } else { fprintf(cp_err, "Debug: could output current for %s\n", tmpname); continue; } if (parseSpecial(tmpname, namebuf, parambuf, depbuf)) { if (*depbuf) { fprintf(stderr, "Warning : unexpected dependent variable on %s\n", tmpname); } else { addSpecialDesc(run, tmpname, namebuf, parambuf, depind); } } } } } /* Pass 2. */ for (i = 0; i < numsaves; i++) { if (savesused[i]) continue; if (!parseSpecial(saves[i].name, namebuf, parambuf, depbuf)) { if (saves[i].analysis) fprintf(cp_err, "Warning: can't parse '%s': ignored\n", saves[i].name); continue; } /* Now, if there's a dep variable, do we already have it? */ if (*depbuf) { for (j = 0; j < run->numData; j++) if (name_eq(depbuf, run->data[j].name)) break; if (j == run->numData) { /* Better add it. */ for (j = 0; j < numNames; j++) if (name_eq(depbuf, dataNames[j])) break; if (j == numNames) { fprintf(cp_err, "Warning: can't find '%s': value '%s' ignored\n", depbuf, saves[i].name); continue; } addDataDesc(run, dataNames[j], dataType, j); savesused[i] = TRUE; saves[i].used = 1; depind = j; } else { depind = run->data[j].outIndex; } } addSpecialDesc(run, saves[i].name, namebuf, parambuf, depind); } if (numsaves) { for (i = 0; i < numsaves; i++) { tfree(saves[i].analysis); tfree(saves[i].name); } tfree(saves); tfree(savesused); } if (numNames && ((run->numData == 1 && run->refIndex != -1) || (run->numData == 0 && run->refIndex == -1))) { fprintf(cp_err, "Error: no data saved for %s; analysis not run\n", spice_analysis_get_description(analysisPtr->JOBtype)); return E_NOTFOUND; } /* Now that we have our own data structures built up, let's see what * nutmeg wants us to do. */ run->writeOut = ft_getOutReq(&run->fp, &run->runPlot, &run->binary, run->type, run->name); if (run->writeOut) { fileInit(run); } else { plotInit(run); if (refName) run->runPlot->pl_ndims = 1; } } /* define storage for old and new data, to allow interpolation */ if (interpolated && run->circuit->CKTcurJob->JOBtype == 4) { valueold = TMALLOC(double, run->numData); for (i = 0; i < run->numData; i++) valueold[i] = 0.0; valuenew = TMALLOC(double, run->numData); }