void TimeComputer::AddTimeStamp(bigtime_t realTime, uint64 frames) { bigtime_t estimatedPerformanceTime = fPerformanceTime + bigtime_t((realTime - fRealTime) * fDrift); fRealTime = realTime; if (fResetTimeBase) { // use the extrapolated performance time at the given real time fPerformanceTime = estimatedPerformanceTime; fPerformanceTimeBase = estimatedPerformanceTime; fFrameBase = frames; fResetTimeBase = false; _AddEntry(fRealTime, fPerformanceTime); return; } // add entry bigtime_t performanceTime = fPerformanceTimeBase + bigtime_t((frames - fFrameBase) * fUsecsPerFrame); _AddEntry(realTime, performanceTime); // Update performance time and drift. We don't use the given // performance time directly, but average it with the estimated // performance time. fPerformanceTime = (performanceTime + estimatedPerformanceTime) / 2; Entry& entry = fEntries[fFirstEntry]; fDrift = double(fPerformanceTime - entry.performanceTime) / double(fRealTime - entry.realTime); }
// ================================================== // VCacheLog / Append to the log // ================================================== void VCacheLog::Log(ECacheLogEntryKind inLogWhat, bool inWithStartFlag) { if (fLogFile != NULL) { VTaskLock lock(&s_mutex); if (fLogFile != NULL) { _UpdateStartFlag(inWithStartFlag); switch(inLogWhat) { case eCLEntryKind_MemStats: _LogMemStatsWithoutLocking(); break; default: if(_IsFlushFromActionEntrykind(inLogWhat)) { _LogFlushFromActionWithoutLocking(inLogWhat, -1, -1); } else { _AddEntry(inLogWhat, true); } break; } _UpdateStartFlag(false); } } }
bool CProfile::WriteProfileStr(CString strSection, CString strEntry, CString strValue) { bool bResult = true; // flag as 'dirty', needs to be saved to file m_bNeedsSave = true; int i; if((i = _FindEntry(strSection, strEntry)) == -1) { // not found, so add new entry _AddEntry(strSection, strEntry, strValue); } else { // update the found entry m_ProfileTable[i].strSection = strSection; m_ProfileTable[i].strEntry = strEntry; m_ProfileTable[i].strValue = strValue; bResult = true; } return bResult; }
void VCacheLog::_LogFlushFromActionWithoutLocking( ECacheLogEntryKind inKind, sLONG inIsWaitUntilDone, sLONG inIsEmptyCache) { if (fLogFile != NULL) { VTaskLock lock(&s_mutex); if (fLogFile != NULL) { _FormatCurrentVTaskInfos(); _AddEntry(inKind); fLogFile->AppendFormattedString("\t%s\t%d\t%d\r", fVTaskInfos, inIsWaitUntilDone, inIsEmptyCache); } } }
void VCacheLog::LogNeedsBytes(ECacheLogEntryKind inKind, VSize inNeededBytes, bool inWithMemStats, bool inWithStartFlag) { if (fLogFile != NULL) { VTaskLock lock(&s_mutex); if (fLogFile != NULL) { _FormatCurrentVTaskInfos(); _UpdateStartFlag(inWithStartFlag); _AddEntry(inKind); fLogFile->AppendFormattedString("\t%s\t%llu\r", fVTaskInfos, (uLONG8) inNeededBytes); _UpdateStartFlag(false); if(inWithMemStats) _LogMemStatsWithoutLocking(inKind); } } }
void VCacheLog::LogComment( const XBOX::VString& inComment ) { if(!inComment.IsEmpty()) { if (fLogFile != NULL) { VTaskLock lock(&s_mutex); if (fLogFile != NULL) { _UpdateStartFlag(true); _AddEntry(eCLEntryKind_Comment); _UpdateStartFlag(false); fLogFile->AppendFormattedString("\r%s\r", fConverter.ConvertString(inComment)); _AddEntryEnd(eCLEntryKind_Comment, true); } } } }
void VCacheLog::_LogMemStatsWithoutLocking(ECacheLogEntryKind inOrigin) { if(fLogFile == NULL) return; XBOX::VCppMemMgr *memMgr = VDBMgr::GetCacheManager()->GetMemoryManager(); _AddEntry(eCLEntryKind_MemStats); fLogFile->AppendFormattedString("\t%d\r", (sLONG) inOrigin); // "Header", with main infos VSize theSize, usedMem; memMgr->GetMemUsageInfo(theSize, usedMem); _FormatCurrentVTaskInfos(true); fLogFile->AppendFormattedString("<mem_stats level=\"%d\" %s size=\"%llu\" used=\"%llu\">\r", fMemStatsLevel, fVTaskInfos, (uLONG8) theSize, (uLONG8) usedMem); // Physical/virtual sizes fLogFile->AppendFormattedString("<system phys=\"%llu\" free=\"%llu\" app_used_phys=\"%llu\" used_virtual=\"%llu\"/>\r", (uLONG8) VSystem::GetPhysicalMemSize(), (uLONG8) VSystem::GetPhysicalFreeMemSize(), (uLONG8) VSystem::GetApplicationPhysicalMemSize(), (uLONG8) VSystem::VirtualMemoryUsedSize() ); // Allocation blocks // Voir avec LE/LR si c'est utile. Le code qui parcourt les infos des blocs d'allocation // ("DumpAllocationToLog") est plus loin, commenté. // En attendant, on Log le minimum VIndex countAlloc = memMgr->CountVirtualAllocations(); VSize totalAlloc = memMgr->GetAllocatedMem(); fLogFile->AppendFormattedString("<alloc count=\"%d\" tot=\"%llu\"/>\r", countAlloc, (uLONG8) totalAlloc); // Mem. stats VMemStats stats; memMgr->GetStatistics(stats); _DumpMemStatsWithoutLocking(stats); // "Footer" fLogFile->AppendFormattedString("</mem_stats>\r"); }
status_t PackageWriter::_Finish() { // write entries for (EntryList::ConstIterator it = fRootEntry->ChildIterator(); Entry* entry = it.Next();) { _AddEntry(AT_FDCWD, entry, entry->Name()); } printf("header size: %lu\n", sizeof(hpkg_header)); printf("heap size: %lld\n", fHeapEnd - sizeof(hpkg_header)); hpkg_header header; // write the TOC and package attributes _WriteTOC(header); _WritePackageAttributes(header); off_t totalSize = fHeapEnd; printf("total size: %lld\n", totalSize); // prepare the header // general header.magic = B_HOST_TO_BENDIAN_INT32(B_HPKG_MAGIC); header.header_size = B_HOST_TO_BENDIAN_INT16( (uint16)sizeof(hpkg_header)); header.version = B_HOST_TO_BENDIAN_INT16(B_HPKG_VERSION); header.total_size = B_HOST_TO_BENDIAN_INT64(totalSize); // write the header _WriteBuffer(&header, sizeof(hpkg_header), 0); fFinished = true; return B_OK; }
/* Initialize ProvReg strucutre from given directory */ _Use_decl_annotations_ MI_Result ProvReg_Init(ProvReg* self, const char* directory) { RegFile* reg = NULL; Dir* dir = NULL; Dir* dir2 = NULL; MI_Result r = MI_RESULT_FAILED; /* Zero-fill self */ memset(self, 0, sizeof(*self)); dir = Dir_Open(directory); if (!dir) { return r; } /* Initialize batch allocator */ Batch_Init(&self->batch, BATCH_MAX_PAGES); /* For each namespace directory in 'omirgister' */ for (;;) { DirEnt* ent = Dir_Read(dir); if (!ent) { break; } /* Ignore system directories */ if (strcmp(ent->name, ".") == 0 || strcmp(ent->name, "..") == 0) continue; /* Skip 'CVS' directories */ if (strcmp(ent->name, "CVS") == 0) continue; /* Scan .reg files in the current namespace directory */ { char path[PAL_MAX_PATH_SIZE]; Strlcpy(path, directory, sizeof(path)); Strlcat(path, "/", sizeof(path)); Strlcat(path, ent->name, sizeof(path)); /* Skip if not a dir */ if(!Isdir(path)) continue; dir2 = Dir_Open(path); if (!dir2) { goto failed; } for (;;) { DirEnt* ent2 = Dir_Read(dir2); if (!ent2) { break; } /* Ignore system directories */ if (strcmp(ent2->name,".") == 0 || strcmp(ent2->name,"..") == 0) { continue; } /* Skip non-reg file */ { char* affix = Strrchr(ent2->name, '.'); if (!affix || (Strcasecmp(&affix[1], "reg") != 0)) continue; } /* Load the reg file */ { char regPath[PAL_MAX_PATH_SIZE]; /* Form path to .reg file */ Strlcpy(regPath, path, sizeof(regPath)); Strlcat(regPath, "/", sizeof(regPath)); Strlcat(regPath, ent2->name, sizeof(regPath)); /* Create new reg file object */ reg = RegFile_New(regPath); if (!reg) { trace_ProvReg_SkipRegFile(scs(regPath)); continue; } /* For each class in the reg file */ { RegClass* rc; char* p = ent->name; /* Transpose NAMESPACE_SEPARATOR characters to '/' * characters */ while (*p) { if (*p == NAMESPACE_SEPARATOR) *p = '/'; p++; } for (rc = reg->classesHead; rc; rc = rc->next) { if (_AddEntry(self, ent->name, reg, rc) != 0) { goto failed; } } } /* For each extraClass in the reg file */ { RegClass* rc; char* p = ent->name; /* Transpose NAMESPACE_SEPARATOR characters to '/' * characters */ while (*p) { if (*p == NAMESPACE_SEPARATOR) *p = '/'; p++; } for (rc = reg->extraClassesHead; rc; rc = rc->next) { if (_AddEntryForExtraClass(self, ent->name, reg, rc) != 0) { goto failed; } } } /* Delete the current entry */ RegFile_Delete(reg); reg = NULL; } } /* Close the directory */ Dir_Close(dir2); dir2 = NULL; } } r = MI_RESULT_OK; failed: if (dir2) { Dir_Close(dir2); } if (dir) { Dir_Close(dir); } if (r != MI_RESULT_OK) { ProvReg_Destroy(self); memset(self, 0, sizeof(*self)); } if(reg) { RegFile_Delete(reg); reg = NULL; } return r; }
void PackageWriter::_AddEntry(int dirFD, Entry* entry, const char* fileName) { printf("PackageWriter::_AddEntry(%d, %p, \"%s\")\n", dirFD, entry, fileName); bool isImplicitEntry = entry != NULL && entry->IsImplicit(); // open the node int fd = openat(dirFD, fileName, O_RDONLY | (isImplicitEntry ? 0 : O_NOTRAVERSE)); if (fd < 0) { fprintf(stderr, "Error: Failed to open entry \"%s\": %s\n", fileName, strerror(errno)); throw status_t(errno); } FDCloser fdCloser(fd); // stat the node struct stat st; if (fstat(fd, &st) < 0) { fprintf(stderr, "Error: Failed to fstat() file \"%s\": %s\n", fileName, strerror(errno)); throw status_t(errno); } // implicit entries must be directories if (isImplicitEntry && !S_ISDIR(st.st_mode)) { fprintf(stderr, "Error: Non-leaf path component \"%s\" is not a " "directory\n", fileName); throw status_t(B_BAD_VALUE); } // check/translate the node type uint8 fileType; uint32 defaultPermissions; if (S_ISREG(st.st_mode)) { fileType = B_HPKG_FILE_TYPE_FILE; defaultPermissions = B_HPKG_DEFAULT_FILE_PERMISSIONS; } else if (S_ISLNK(st.st_mode)) { fileType = B_HPKG_FILE_TYPE_SYMLINK; defaultPermissions = B_HPKG_DEFAULT_SYMLINK_PERMISSIONS; } else if (S_ISDIR(st.st_mode)) { fileType = B_HPKG_FILE_TYPE_DIRECTORY; defaultPermissions = B_HPKG_DEFAULT_DIRECTORY_PERMISSIONS; } else { // unsupported node type fprintf(stderr, "Error: Unsupported node type, entry: \"%s\"\n", fileName); throw status_t(B_UNSUPPORTED); } // add attribute entry Attribute* entryAttribute = _AddStringAttribute( B_HPKG_ATTRIBUTE_NAME_DIRECTORY_ENTRY, fileName); Stacker<Attribute> entryAttributeStacker(fTopAttribute, entryAttribute); // add stat data if (fileType != B_HPKG_DEFAULT_FILE_TYPE) _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_TYPE, fileType); if (defaultPermissions != uint32(st.st_mode & ALLPERMS)) { _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_PERMISSIONS, uint32(st.st_mode & ALLPERMS)); } _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_ATIME, uint32(st.st_atime)); _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_MTIME, uint32(st.st_mtime)); _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_CRTIME, uint32(st.st_crtime)); // TODO: File user/group! // add file data/symlink path if (S_ISREG(st.st_mode)) { // regular file -- add data if (st.st_size > 0) { FDDataReader dataReader(fd); status_t error = _AddData(dataReader, st.st_size); if (error != B_OK) throw status_t(error); } } else if (S_ISLNK(st.st_mode)) { // symlink -- add link address char path[B_PATH_NAME_LENGTH + 1]; ssize_t bytesRead = readlinkat(dirFD, fileName, path, B_PATH_NAME_LENGTH); if (bytesRead < 0) { fprintf(stderr, "Error: Failed to read symlink \"%s\": %s\n", fileName, strerror(errno)); throw status_t(errno); } path[bytesRead] = '\0'; _AddStringAttribute(B_HPKG_ATTRIBUTE_NAME_SYMLINK_PATH, path); } // add attributes if (DIR* attrDir = fs_fopen_attr_dir(fd)) { CObjectDeleter<DIR, int> attrDirCloser(attrDir, fs_close_attr_dir); while (dirent* entry = readdir(attrDir)) { attr_info attrInfo; if (fs_stat_attr(fd, entry->d_name, &attrInfo) < 0) { fprintf(stderr, "Error: Failed to stat attribute \"%s\" of " "file \"%s\": %s\n", entry->d_name, fileName, strerror(errno)); throw status_t(errno); } // create attribute entry Attribute* attributeAttribute = _AddStringAttribute( B_HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE, entry->d_name); Stacker<Attribute> attributeAttributeStacker(fTopAttribute, attributeAttribute); // add type _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE_TYPE, (uint32)attrInfo.type); // add data AttributeDataReader dataReader(fd, entry->d_name, attrInfo.type); status_t error = _AddData(dataReader, attrInfo.size); if (error != B_OK) throw status_t(error); } } if (S_ISDIR(st.st_mode)) { // directory -- recursively add children if (isImplicitEntry) { // this is an implicit entry -- just add it's children for (EntryList::ConstIterator it = entry->ChildIterator(); Entry* child = it.Next();) { _AddEntry(fd, child, child->Name()); } } else { // we need to clone the directory FD for fdopendir() int clonedFD = dup(fd); if (clonedFD < 0) { fprintf(stderr, "Error: Failed to dup() directory FD: %s\n", strerror(errno)); throw status_t(errno); } DIR* dir = fdopendir(clonedFD); if (dir == NULL) { fprintf(stderr, "Error: Failed to open directory \"%s\": %s\n", fileName, strerror(errno)); close(clonedFD); throw status_t(errno); } CObjectDeleter<DIR, int> dirCloser(dir, closedir); while (dirent* entry = readdir(dir)) { // skip "." and ".." if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { continue; } _AddEntry(fd, NULL, entry->d_name); } } } }