📄 frmgradegraph.frm
字号:
On Error GoTo ErrStart
If mfWaitingForClick Then
mfWaitingForClick = False
Dim pt As Double
pt = X / mData.ScaleFactor
Dim thread As clsThread
Dim intPt As Double, lTime As Long
Dim lThread As Long
If chkSingleLine.Value = vbChecked Then
mData.FindClosestInt pt, lThread, lTime
Set thread = mData.thread(lThread)
Else
lThread = Int(Y / 10)
If lThread + 1 > mData.ThreadCount Then Exit Sub
Set thread = mData.thread(lThread)
thread.FindClosestInt pt, lTime
End If
intPt = thread.EndTime(lTime)
Do
Dim dInterval As Double
Dim sInput As String
sInput = (InputBox("Enter the student's estimation of the timer interval (in cycles). Enter only a positive value."))
If (sInput = vbNullString) Then Exit Do
If IsNumeric(sInput) Then
dInterval = CDbl(sInput)
If dInterval > 0 Then
mdInterval = dInterval * mData.ScaleFactor
mdPt = intPt * mData.ScaleFactor
mfOverlayed = True
chkToggleOverlay.Value = vbChecked
DrawGraph
ShowAnswers
Exit Do
End If
End If
Loop
End If
Exit Sub
ErrStart:
MsgBox "Error in pic.MouseUp: " & vbCrLf & Err.Number & " " & Err.Description
End Sub
Private Sub DrawOverlay()
On Error GoTo ErrStart
pic.DrawStyle = vbDot
Dim f As Double
f = mData.ScaleFactor
Dim dCurrent As Double
dCurrent = mdPt
Do While (dCurrent > mData.Min * f)
pic.Line (dCurrent, 0)-(dCurrent, 100), &H808080
dCurrent = dCurrent - mdInterval
Loop
dCurrent = mdPt + mdInterval
Do While (dCurrent < mData.Max * f)
pic.Line (dCurrent, 0)-(dCurrent, 100), &H808080
dCurrent = dCurrent + mdInterval
Loop
pic.DrawStyle = vbSolid
Exit Sub
ErrStart:
MsgBox "Error in DrawOverlay: " & vbCrLf & Err.Number & " " & Err.Description
End Sub
Private Sub DrawThreadNumber(lThreadNum As Long)
' Draw thread number, centered horizontally (and vertically)
Dim i As Integer
For i = 0 To 1
picNum(i).CurrentX = 5 - (Abs(picNum(i).TextWidth(CStr(lThreadNum))) / 2)
Dim lY As Long
lY = (lThreadNum * 10) + 3
picNum(i).CurrentY = lY - (Abs(picNum(i).TextHeight(CStr(lThreadNum))) / 2)
picNum(i).Print CStr(lThreadNum)
Next
End Sub
Private Sub ShowAnswers()
Dim iFileNum As Integer
iFileNum = FreeFile
Open App.Path & "\answers.txt" For Output As #iFileNum
Dim a() As clsThreadSlice
a = CreateSliceArray
Print #iFileNum, "1) See student submission"
Print #iFileNum, "2) See student submission"
OutputMinMax a, iFileNum
OutputTotals iFileNum
OutputSwitches a, iFileNum
OutputFinishedThreads iFileNum
OutputIntervalCount a, iFileNum
OutputNotRun a, iFileNum
OutputOrder a, iFileNum
Print #iFileNum, vbNullString
Print #iFileNum, vbNullString
Print #iFileNum, vbNullString
Print #iFileNum, "Answers to the questions marked with an"
Print #iFileNum, "asterisk were derived using a heuristic"
Print #iFileNum, "approach."
Close #iFileNum
Call Shell("notepad.exe " & App.Path & "\answers.txt", vbNormalFocus)
End Sub
Private Sub OutputMinMax(a() As clsThreadSlice, iFileNum As Integer)
Dim i As Integer, lPrev As Long
lPrev = a(0).ThreadID
Dim Min As Double, Max As Double
For i = 1 To UBound(a)
If a(i).ThreadID = lPrev And a(i - 1).TimerInt Then
Dim diff As Double
diff = a(i).StartTime - a(i - 1).EndTime
If (diff < mdInterval * CONTEXT_SWITCH_THRESHOLD_FACTOR) Then
If Min = 0 Or diff < Min Then Min = diff
If Max = 0 Or diff > Max Then Max = diff
End If
End If
lPrev = a(i).ThreadID
Next
Print #iFileNum, "*3) Min: " & Min & " Max: " & Max
End Sub
Private Sub OutputNotRun(a() As clsThreadSlice, iFileNum As Integer)
Dim i As Long, l As Long
For i = 0 To UBound(a) - 1
Dim diff As Double
diff = a(i + 1).StartTime - a(i).EndTime
Dim d As Double
d = diff / mdInterval
If Abs(CLng(d) - d) < TOLERANCE Then
l = l + CLng(d)
ElseIf Int(d) > 0 Then
l = l + Int(d)
End If
Next
Print #iFileNum, "*9b) Not run during " & l & " intervals "
End Sub
Private Sub OutputSwitches(a() As clsThreadSlice, iFileNum As Integer)
Dim i As Long
Dim lThread As Long, lProcess As Long, lInts As Long
For i = 1 To UBound(a)
If a(i - 1).TimerInt Then
Dim diff As Double
diff = a(i).StartTime - a(i - 1).EndTime
If diff < mdInterval * CONTEXT_SWITCH_THRESHOLD_FACTOR Then
If a(i).ThreadID <> a(i - 1).ThreadID Then
lThread = lThread + 1
End If
Else
lProcess = lProcess + 1
Dim d As Double
d = diff / mdInterval
lInts = lInts + CLng(d)
End If
End If
Next
Print #iFileNum, "*6) Switches to Other Threads: " & lThread
Print #iFileNum, "*7) Switches to Other Process: " & lProcess & " " & lInts & " Intervals "
End Sub
Private Sub OutputIntervalCount(a() As clsThreadSlice, iFileNum As Integer)
Dim l As Long
If isTimerInt(a(0).StartTime) Then
If a(UBound(a)).TimerInt Then
l = CLng((a(UBound(a)).EndTime - a(0).StartTime) / mdInterval)
Else
l = CLng((a(UBound(a)).StartTime - a(0).StartTime) / mdInterval)
End If
Else
If a(UBound(a)).TimerInt Then
l = CLng((a(UBound(a)).EndTime - a(0).EndTime) / mdInterval)
Else
l = CLng((a(UBound(a)).StartTime - a(0).EndTime) / mdInterval)
End If
End If
Print #iFileNum, "9a) Elapsed Intervals: " & l
End Sub
Private Sub OutputFinishedThreads(iFileNum As Integer)
Dim lCount As Long
Dim l As Long, lT As Long
For l = 0 To mData.ThreadCount - 1
If Not isTimerInt(mData.thread(l).EndTime(mData.thread(l).TimeCount - 1)) Then
lCount = lCount + 1
End If
Next
Print #iFileNum, "*8) " & lCount & " Thread(s) finished executing before the end of an interval"
End Sub
Private Sub OutputOrder(a() As clsThreadSlice, iFileNum As Integer)
Dim i As Integer, lPrev As Long
Dim s As String
lPrev = -1
For i = 0 To UBound(a)
If a(i).ThreadID <> lPrev Then
lPrev = a(i).ThreadID
s = s & lPrev & "-"
End If
Next
s = Left$(s, Len(s) - 1)
Print #iFileNum, " 10) " & s
End Sub
Private Sub OutputTotals(iFileNum As Integer)
Dim iTotal As Integer, iTimer As Integer
' Count total and timer
Dim nMin As Double, nMax As Double
Dim l As Long
For l = 0 To mData.ThreadCount - 1
Dim lTime As Long
For lTime = 0 To mData.thread(l).TimeCount - 1
If isTimerInt(mData.thread(l).EndTime(lTime)) Then
iTimer = iTimer + 1
End If
iTotal = iTotal + 1
Next
Next
Print #iFileNum, " 4) Total Interrupts: " & iTotal - 1
Print #iFileNum, "*5) Total Timer Interrupts: " & iTimer
End Sub
Private Sub Sort(a() As clsThreadSlice)
Dim i As Long, j As Long, curmin As Double, Min
For i = 0 To UBound(a) - 1
curmin = a(i).StartTime
Min = i
For j = i + 1 To UBound(a)
If a(j).StartTime < curmin Then
Min = j
curmin = a(j).StartTime
End If
Next
If (Min <> i) Then
Dim temp As clsThreadSlice
Set temp = a(i)
Set a(i) = a(Min)
Set a(Min) = temp
End If
Next
End Sub
Private Function CreateSliceArray() As clsThreadSlice()
Dim lCount As Long, lThread As Long
For lThread = 0 To mData.ThreadCount - 1
lCount = lCount + mData.thread(lThread).TimeCount
Next
ReDim a(lCount - 1) As clsThreadSlice
Dim iNext As Integer
For lThread = 0 To mData.ThreadCount - 1
Dim lTime As Long
For lTime = 0 To mData.thread(lThread).TimeCount - 1
Dim o As clsThreadSlice
Set o = New clsThreadSlice
o.StartTime = mData.thread(lThread).StartTime(lTime)
o.EndTime = mData.thread(lThread).EndTime(lTime)
o.ThreadID = lThread
o.TimeID = lTime
If isTimerInt(mData.thread(lThread).EndTime(lTime)) Then
o.TimerInt = True
End If
Set a(iNext) = o
iNext = iNext + 1
Next
Next
Sort a
CreateSliceArray = a
End Function
Private Function isTimerInt(d As Double) As Boolean
Dim dSelectedInt As Double
dSelectedInt = mdPt / mData.ScaleFactor
Dim dNum As Double
dNum = Abs(dSelectedInt - d) / mdInterval
If Abs(CInt(dNum) - dNum) < TOLERANCE Then
isTimerInt = True
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -