Mijn vraag
ik heb een stuk code en dat gaat door een log bestand en doet per lijn checks (indexof) of iets op die lijn staat of niet.
Nu heb ik gemerkt met hele grote logs (>100.000 lijnen) dat het langer en langer duurt om daar door te gaan en ik heb ook gemerkt dat de thread dat er aan werkt wat verspringt door naar taakbeheer te zien.
Relevante software en hardware die ik gebruik
VS 2022 Community
Wat ik al gevonden of geprobeerd heb
Heb al 2 stukken van de code dat dan behandeld word gewijzigd zodoende dat ze op hun eigen tempo kunnen worden afgewerkt maar de rest van het stuk code weet ik niet hoe ik dat moet doen, vermits de lijnen in volgorde moeten blijven staan. Iemand een idee wat ik daarmee kan doen.
Het code stuk dat door de vele lijnen gaat:
LogFileContents is een string array gevuld door en lstBox is een woordenboek
ik heb een stuk code en dat gaat door een log bestand en doet per lijn checks (indexof) of iets op die lijn staat of niet.
Nu heb ik gemerkt met hele grote logs (>100.000 lijnen) dat het langer en langer duurt om daar door te gaan en ik heb ook gemerkt dat de thread dat er aan werkt wat verspringt door naar taakbeheer te zien.
Relevante software en hardware die ik gebruik
VS 2022 Community
Wat ik al gevonden of geprobeerd heb
Heb al 2 stukken van de code dat dan behandeld word gewijzigd zodoende dat ze op hun eigen tempo kunnen worden afgewerkt maar de rest van het stuk code weet ik niet hoe ik dat moet doen, vermits de lijnen in volgorde moeten blijven staan. Iemand een idee wat ik daarmee kan doen.
Het code stuk dat door de vele lijnen gaat:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
| Try Dim Var As Long For s As Integer = 0 To LogFileContents.Length - 1 If LogFileContents(s).Length <= 10 Then Continue For #Region "Total su todo day" If LogFileContents(s).IndexOf(BuffIn) > -1 Then Var = Get_Stats_Units(LogFileContents(s - 1)) If Var > CLng(sParse(29)) Then sParse(29) = Var GoTo add_line End If #End Region #Region "read cpu :)" If LogFileContents(s).IndexOf("Automatic processor") > -1 AndAlso LogFileContents(s).IndexOf("did not") = -1 AndAlso LogFileContents(s).IndexOf("tag:") = -1 Then iStart = LogFileContents(s).IndexOf("Automatic processor") + 26 sParse(7) = LogFileContents(s).Substring(iStart, LogFileContents(s).IndexOf(" processor") - iStart) '-cpu/gpu info :) GoTo add_line End If #End Region #Region "read flushed wu's + stats units >> sparse(23)" If LogFileContents(s).IndexOf("Sent") > -1 AndAlso LogFileContents(s).IndexOf(ProjectType) > -1 AndAlso LogFileContents(s).IndexOf("packets") > -1 Then '-check if its not already added sTmp = LogFileContents(s).Substring(1, 19) If Array.IndexOf(aFlush, sTmp) = -1 Then ReDim Preserve aFlush(aFlush.Length) aFlush(aFlush.Length - 1) = sTmp sParse(23) = CLng(sParse(23)) + Get_Stats_Units(LogFileContents(s)) sParse(14) = CLng(sParse(14)) + Get_Packets(LogFileContents(s)) sParse(15) += 1 End If GoTo add_line End If #End Region #Region "read fetched wu's + stats units >> sparse(24)" If LogFileContents(s).IndexOf("Retrieved") > -1 AndAlso LogFileContents(s).IndexOf(ProjectType) > -1 AndAlso LogFileContents(s).IndexOf("packets") > -1 Then '-check if its not already added sTmp = LogFileContents(s).Substring(1, 19) If Array.IndexOf(aFetch, sTmp) = -1 Then ReDim Preserve aFetch(aFetch.Length) aFetch(aFetch.Length - 1) = sTmp sParse(24) = CLng(sParse(24)) + Get_Stats_Units(LogFileContents(s)) sParse(18) = CLng(sParse(18)) + Get_Packets(LogFileContents(s)) sParse(19) += 1 End If GoTo add_line End If #End Region '-read cruncher(s) If LogFileContents(s).IndexOf("cruncher") > -1 AndAlso LogFileContents(s).IndexOf("Loading") = -1 Then sParse(16) = LogFileContents(s).Substring(LogFileContents(s).IndexOf("cruncher") - 2, 1) 'regex maybe if sparse(16)>1 End If add_line: 'Packet was from a different user/core/client cpu/os/build. '-fetched/flushed/restarted not add to lstbox If LogFileContents(s).IndexOf("The") = -1 AndAlso LogFileContents(s).IndexOf("Connected") = -1 AndAlso LogFileContents(s).IndexOf("Retrieved") = -1 AndAlso LogFileContents(s).IndexOf("*Break*") = -1 AndAlso LogFileContents(s).IndexOf("Shutdown") = -1 AndAlso LogFileContents(s).IndexOf("Paused") = -1 AndAlso LogFileContents(s).IndexOf("Running") = -1 AndAlso LogFileContents(s).IndexOf("cruncher") = -1 AndAlso LogFileContents(s).IndexOf("dnetc") = -1 AndAlso LogFileContents(s).IndexOf("Using") = -1 AndAlso LogFileContents(s).IndexOf("Sent") AndAlso LogFileContents(s).IndexOf("from a different") = -1 AndAlso LogFileContents(s).IndexOf("size_t") = -1 Then lstBox.Add(lstBox.LongCount, LogFileContents(s)) '-this is prolly a new start for stage 2 If LogFileContents(s).IndexOf("[") = 0 AndAlso LogFileContents(s).IndexOf(ProjectType) > -1 AndAlso (LogFileContents(s).IndexOf("Completed") > -1 Or LogFileContents(s).IndexOf("Saved") > -1) Then iFFLines = lstBox.LongCount - 1 Else If LogFileContents(s).IndexOf("Shutdown") > -1 AndAlso Process.GetProcessesByName(dNet_Exe_Name).Count = 0 Then sParse(12) = 2 ElseIf LogFileContents(s).IndexOf("Paused") > -1 AndAlso Process.GetProcessesByName(dNet_Exe_Name).Count > 0 Then sParse(12) = 1 ElseIf LogFileContents(s).IndexOf("Running") > -1 Or LogFileContents(s).IndexOf("Restarting") > -1 Then sParse(12) = 0 End If End If Next Catch ex As Exception Debug.WriteLine(Date.Now & " modDnetcLogParser :: Parser :: First Stage #" & Err.Number & " " & ex.ToString) MsgBox(ex.Message, MsgBoxStyle.Exclamation, "modDnetcLogParser :: Parser :: First stage") End Try |
LogFileContents is een string array gevuld door en lstBox is een woordenboek
Visual Basic:
1
2
| LogFileContents = File.ReadAllLines(Path.Combine(DNETC_Pathname, LogFile)) Dim lstBox As New Dictionary(Of Integer, String) |
[ Voor 85% gewijzigd door RobIII op 27-12-2022 16:51 . Reden: Code leesbaarder gemaakt door indentation minder te maken ]
Al wat ik aanraak werk niet meer zoals het hoort. Damic houd niet van zijn verjaardag