private static void PopulateProjectData(LogLine line, FahLogUnitData data) { Debug.Assert(line != null); Debug.Assert(data != null); Debug.Assert(line.LineType.Equals(LogLineType.WorkUnitProject)); var match = (Match)line.LineData; var info = new ProjectInfo { ProjectID = Int32.Parse(match.Result("${ProjectNumber}")), ProjectRun = Int32.Parse(match.Result("${Run}")), ProjectClone = Int32.Parse(match.Result("${Clone}")), ProjectGen = Int32.Parse(match.Result("${Gen}")) }; data.ProjectInfoList.Add(info); }
private UnitInfo[] GenerateUnitInfoDataFromQueue(QueueData q) { Debug.Assert(q != null); var parsedUnits = new UnitInfo[10]; _unitLogLines = new IList<LogLine>[10]; for (int queueIndex = 0; queueIndex < parsedUnits.Length; queueIndex++) { // Get the Log Lines for this queue position from the reader _unitLogLines[queueIndex] = _logInterpreterLegacy.GetLogLinesForQueueIndex(queueIndex); // Get the FAH Log Data from the Log Lines FahLogUnitData fahLogUnitData = LogReader.GetFahLogDataFromLogLines(_unitLogLines[queueIndex]); UnitInfoLogData unitInfoLogData = null; // On the Current Queue Index if (queueIndex == q.CurrentIndex) { // Get the UnitInfo Log Data unitInfoLogData = GetUnitInfoLogData(); } parsedUnits[queueIndex] = BuildUnitInfo(q.GetQueueEntry((uint)queueIndex), fahLogUnitData, unitInfoLogData); if (parsedUnits[queueIndex] == null) { if (queueIndex == q.CurrentIndex) { string message = String.Format(CultureInfo.CurrentCulture, "Could not verify log section for current queue entry {0}. Trying to parse with most recent log section.", queueIndex); _logger.Warn(Constants.ClientNameFormat, ClientName, message); _unitLogLines[queueIndex] = _logInterpreterLegacy.CurrentWorkUnitLogLines; // If got no Work Unit Log Lines based on Current Work Unit Log Lines // then take the entire Current Client Run Log Lines - likely the run // was short and never contained any Work Unit Data. if (_unitLogLines[queueIndex] == null) { _unitLogLines[queueIndex] = _logInterpreterLegacy.CurrentClientRunLogLines; } fahLogUnitData = LogReader.GetFahLogDataFromLogLines(_unitLogLines[queueIndex]); if (_currentClientRun.Status.Equals(SlotStatus.GettingWorkPacket)) { // Use either the current Work Unit log lines or current Client Run log lines // as decided upon above... don't clear it here and show the user nothing - 10/9/10 //_unitLogLines[queueIndex] = null; fahLogUnitData = new FahLogUnitData(); unitInfoLogData = new UnitInfoLogData(); } parsedUnits[queueIndex] = BuildUnitInfo(q.GetQueueEntry((uint)queueIndex), fahLogUnitData, unitInfoLogData, true); } else { // Just skip this unit and continue string message = String.Format(CultureInfo.CurrentCulture, "Could not find or verify log section for queue entry {0} (this is not a problem).", queueIndex); _logger.Debug(Constants.ClientNameFormat, ClientName, message); } } } return parsedUnits; }
private UnitInfo BuildUnitInfo(QueueEntry queueEntry, FahLogUnitData fahLogUnitData, UnitInfoLogData unitInfoLogData, bool matchOverride) { // queueEntry can be null Debug.Assert(fahLogUnitData != null); // unitInfoLogData can be null var unit = new UnitInfo(); unit.UnitStartTimeStamp = fahLogUnitData.UnitStartTimeStamp; unit.FramesObserved = fahLogUnitData.FramesObserved; unit.CoreVersion = fahLogUnitData.CoreVersion; unit.UnitResult = fahLogUnitData.UnitResult; if (queueEntry != null) { PopulateUnitInfoFromQueueEntry(queueEntry, unit); SearchFahLogUnitDataProjects(unit, fahLogUnitData); PopulateUnitInfoFromLogs(CurrentClientRun, fahLogUnitData, unitInfoLogData, unit); if (ProjectsMatch(unit, fahLogUnitData) || ProjectsMatch(unit, unitInfoLogData) || matchOverride) { // continue parsing the frame data ParseFrameData(fahLogUnitData.FrameDataList, unit); } else { return null; } } else { PopulateUnitInfoFromLogs(CurrentClientRun, fahLogUnitData, unitInfoLogData, unit); ParseFrameData(fahLogUnitData.FrameDataList, unit); } return unit; }
private UnitInfo BuildUnitInfo(QueueEntry queueEntry, FahLogUnitData fahLogUnitData, UnitInfoLogData unitInfoLogData) { return BuildUnitInfo(queueEntry, fahLogUnitData, unitInfoLogData, false); }
private static void SearchFahLogUnitDataProjects(UnitInfo unit, FahLogUnitData fahLogUnitData) { Debug.Assert(unit != null); Debug.Assert(fahLogUnitData != null); for (int i = 0; i < fahLogUnitData.ProjectInfoList.Count; i++) { if (ProjectsMatch(unit, fahLogUnitData.ProjectInfoList[i])) { fahLogUnitData.ProjectInfoIndex = i; } } }
private static void PopulateUnitInfoFromLogs(ClientRun currentClientRun, FahLogUnitData fahLogUnitData, UnitInfoLogData unitInfoLogData, UnitInfo unit) { Debug.Assert(currentClientRun != null); Debug.Assert(fahLogUnitData != null); // unitInfoLogData can be null Debug.Assert(unit != null); /* Project (R/C/G) (Could have already been read through Queue) */ if (unit.ProjectIsUnknown()) { unit.ProjectID = fahLogUnitData.ProjectID; unit.ProjectRun = fahLogUnitData.ProjectRun; unit.ProjectClone = fahLogUnitData.ProjectClone; unit.ProjectGen = fahLogUnitData.ProjectGen; } if (fahLogUnitData.Threads > 1) { unit.SlotType = SlotType.CPU; } if (unitInfoLogData != null) { unit.ProteinName = unitInfoLogData.ProteinName; /* Tag (Could have already been read through Queue) */ if (unit.ProteinTag.Length == 0) { unit.ProteinTag = unitInfoLogData.ProteinTag; } /* DownloadTime (Could have already been read through Queue) */ if (unit.DownloadTime.IsUnknown()) { unit.DownloadTime = unitInfoLogData.DownloadTime; } /* DueTime (Could have already been read through Queue) */ if (unit.DueTime.IsUnknown()) { unit.DueTime = unitInfoLogData.DueTime; } /* FinishedTime (Not available in unitinfo log) */ /* Project (R/C/G) (Could have already been read through Queue) */ if (unit.ProjectIsUnknown()) { unit.ProjectID = unitInfoLogData.ProjectID; unit.ProjectRun = unitInfoLogData.ProjectRun; unit.ProjectClone = unitInfoLogData.ProjectClone; unit.ProjectGen = unitInfoLogData.ProjectGen; } } /* FoldingID and Team from Last Client Run (Could have already been read through Queue) */ if (unit.FoldingID.Equals(Constants.DefaultFoldingID) && !String.IsNullOrEmpty(currentClientRun.FoldingID)) { unit.FoldingID = currentClientRun.FoldingID; } if (unit.Team == Constants.DefaultTeam) { unit.Team = currentClientRun.Team; } // Possibly check the currentClientRun from the log file. // The queue will have the ID and Team that was set when the work unit was received. //if (unit.FoldingID.Equals(Default.FoldingID) || // !unit.FoldingID.Equals(currentClientRun.FoldingID)) //{ // unit.FoldingID = currentClientRun.FoldingID; //} //if (unit.Team == Default.Team || // unit.Team != currentClientRun.Team) //{ // unit.Team = currentClientRun.Team; //} }
/// <summary> /// Get FAHlog Unit Data from the given Log Lines /// </summary> /// <param name="logLines">Log Lines to search</param> public static FahLogUnitData GetFahLogDataFromLogLines(IEnumerable <LogLine> logLines) { var data = new FahLogUnitData(); if (logLines == null) { return(data); } bool clientWasPaused = false; bool lookForProject = true; int queueIndex = -1; foreach (var line in logLines) { #region Unit Start if ((line.LineType.Equals(LogLineType.WorkUnitProcessing) || line.LineType.Equals(LogLineType.WorkUnitWorking) || line.LineType.Equals(LogLineType.WorkUnitStart) || line.LineType.Equals(LogLineType.WorkUnitFrame)) && data.UnitStartTimeStamp.Equals(TimeSpan.MinValue)) { data.UnitStartTimeStamp = line.GetTimeStamp() ?? TimeSpan.MinValue; } if (line.LineType.Equals(LogLineType.WorkUnitPaused) || line.LineType.Equals(LogLineType.WorkUnitPausedForBattery)) { clientWasPaused = true; } else if ((line.LineType.Equals(LogLineType.WorkUnitWorking) || line.LineType.Equals(LogLineType.WorkUnitResumeFromBattery) || line.LineType.Equals(LogLineType.WorkUnitFrame)) && clientWasPaused) { clientWasPaused = false; // Reset the Frames Observed Count // This will cause the Instance to only use frames beyond this point to // set frame times and determine status - Issue 13 (Revised) data.FramesObserved = 0; // Reset the Unit Start Time data.UnitStartTimeStamp = line.GetTimeStamp() ?? TimeSpan.MinValue; } #endregion #region Frame Data if (line.LineType.Equals(LogLineType.WorkUnitFrame)) { Debug.Assert(line.LineData is UnitFrame); data.FramesObserved++; data.FrameDataList.Add(line); } #endregion #region Core Version if (data.CoreVersion == 0) { if (line.LineType.Equals(LogLineType.WorkUnitCoreVersion) && line.LineData != null) { data.CoreVersion = (float)line.LineData; } } #endregion #region Project if (lookForProject) { // If we encounter a work unit frame, we should have // already seen the Project Information, stop looking if (line.LineType.Equals(LogLineType.WorkUnitFrame)) { lookForProject = false; } if (line.LineType.Equals(LogLineType.WorkUnitProject)) { PopulateProjectData(line, data); } } #endregion #region Unit Result if ((line.LineType.Equals(LogLineType.WorkUnitCoreShutdown) && line.LineData != null) || (line.LineType.Equals(LogLineType.ClientCoreCommunicationsError) && line.LineData != null)) { data.UnitResult = (WorkUnitResult)line.LineData; } if (line.LineType.Equals(LogLineType.WorkUnitWorking) && line.LineData != null) { queueIndex = (int)line.LineData; } if (line.LineType.Equals(LogLineType.WorkUnitCoreReturn) && line.LineData != null) { // make sure the result being captured // is for the correct queue index. var unitResult = (UnitResult)line.LineData; if (unitResult.Index == queueIndex) { data.UnitResult = unitResult.Value; } } #endregion #region Threads if (line.LineType.Equals(LogLineType.WorkUnitCallingCore) && line.LineData != null) { data.Threads = (int)line.LineData; } #endregion } return(data); }
/// <summary> /// Get FAHlog Unit Data from the given Log Lines /// </summary> /// <param name="logLines">Log Lines to search</param> public static FahLogUnitData GetFahLogDataFromLogLines(IEnumerable<LogLine> logLines) { var data = new FahLogUnitData(); if (logLines == null) return data; bool clientWasPaused = false; bool lookForProject = true; int queueIndex = -1; foreach (var line in logLines) { #region Unit Start if ((line.LineType.Equals(LogLineType.WorkUnitProcessing) || line.LineType.Equals(LogLineType.WorkUnitWorking) || line.LineType.Equals(LogLineType.WorkUnitStart) || line.LineType.Equals(LogLineType.WorkUnitFrame)) && data.UnitStartTimeStamp.Equals(TimeSpan.MinValue)) { data.UnitStartTimeStamp = line.GetTimeStamp() ?? TimeSpan.MinValue; } if (line.LineType.Equals(LogLineType.WorkUnitPaused) || line.LineType.Equals(LogLineType.WorkUnitPausedForBattery)) { clientWasPaused = true; } else if ((line.LineType.Equals(LogLineType.WorkUnitWorking) || line.LineType.Equals(LogLineType.WorkUnitResumeFromBattery) || line.LineType.Equals(LogLineType.WorkUnitFrame)) && clientWasPaused) { clientWasPaused = false; // Reset the Frames Observed Count // This will cause the Instance to only use frames beyond this point to // set frame times and determine status - Issue 13 (Revised) data.FramesObserved = 0; // Reset the Unit Start Time data.UnitStartTimeStamp = line.GetTimeStamp() ?? TimeSpan.MinValue; } #endregion #region Frame Data if (line.LineType.Equals(LogLineType.WorkUnitFrame)) { Debug.Assert(line.LineData is UnitFrame); data.FramesObserved++; data.FrameDataList.Add(line); } #endregion #region Core Version if (data.CoreVersion == 0) { if (line.LineType.Equals(LogLineType.WorkUnitCoreVersion) && line.LineData != null) { data.CoreVersion = (float)line.LineData; } } #endregion #region Project if (lookForProject) { // If we encounter a work unit frame, we should have // already seen the Project Information, stop looking if (line.LineType.Equals(LogLineType.WorkUnitFrame)) { lookForProject = false; } if (line.LineType.Equals(LogLineType.WorkUnitProject)) { PopulateProjectData(line, data); } } #endregion #region Unit Result if ((line.LineType.Equals(LogLineType.WorkUnitCoreShutdown) && line.LineData != null) || (line.LineType.Equals(LogLineType.ClientCoreCommunicationsError) && line.LineData != null)) { data.UnitResult = (WorkUnitResult)line.LineData; } if (line.LineType.Equals(LogLineType.WorkUnitWorking) && line.LineData != null) { queueIndex = (int)line.LineData; } if (line.LineType.Equals(LogLineType.WorkUnitCoreReturn) && line.LineData != null) { // make sure the result being captured // is for the correct queue index. var unitResult = (UnitResult)line.LineData; if (unitResult.Index == queueIndex) { data.UnitResult = unitResult.Value; } } #endregion #region Threads if (line.LineType.Equals(LogLineType.WorkUnitCallingCore) && line.LineData != null) { data.Threads = (int)line.LineData; } #endregion } return data; }
private static void UpdateUnitInfo(UnitInfo unit, FahLogUnitData fahLogUnitData) { Debug.Assert(unit != null); Debug.Assert(fahLogUnitData != null); unit.UnitStartTimeStamp = fahLogUnitData.UnitStartTimeStamp; unit.FramesObserved = fahLogUnitData.FramesObserved; unit.CoreVersion = fahLogUnitData.CoreVersion; unit.UnitResult = fahLogUnitData.UnitResult; // there is no finished time available from the client API // since the unit history database won't write the same // result twice, the first time this hits use the local UTC // value for the finished time... not as good as what was // available with v6. if (unit.UnitResult.Equals(WorkUnitResult.FinishedUnit)) { unit.FinishedTime = DateTime.UtcNow; } // parse the frame data ParseFrameData(fahLogUnitData.FrameDataList, unit); }
private static UnitInfo BuildUnitInfo(Unit queueEntry, Options options, SlotOptions slotOptions, FahLogUnitData fahLogUnitData) { Debug.Assert(queueEntry != null); Debug.Assert(options != null); Debug.Assert(slotOptions != null); var unit = new UnitInfo(); unit.QueueIndex = queueEntry.Id; if (fahLogUnitData != null) { unit.UnitStartTimeStamp = fahLogUnitData.UnitStartTimeStamp; unit.FramesObserved = fahLogUnitData.FramesObserved; unit.CoreVersion = fahLogUnitData.CoreVersion; unit.UnitResult = fahLogUnitData.UnitResult; // there is no finished time available from the client API // since the unit history database won't write the same // result twice, the first time this hits use the local UTC // value for the finished time... not as good as what was // available with v6. if (unit.UnitResult.Equals(WorkUnitResult.FinishedUnit)) { unit.FinishedTime = DateTime.UtcNow; } } PopulateUnitInfoFromQueueEntry(queueEntry, options, slotOptions, unit); if (fahLogUnitData != null) { // parse the frame data ParseFrameData(fahLogUnitData.FrameDataList, unit); } return unit; }