4. Metody statyczne klasy Process
• GetCurrentProcess():Process
• GetProcessById(int, [string]):Process
• GetProcesses([string]):Process[]
• GetProcessesByName(string, [string]):Process[]
• Start(ProcessStartInfo):Process
• Start(string, [string]):Process
• Start(string, [string], string, SecureString,
string):Process
5. Monitorowanie liczników
• Obiekty systemu operacyjnego
– Klasy i instancje (np. CPU, wątek, pamięć)
– Pseudoinstancja _Total
• Przykłady
– # uchwytów używanych w procesie
– # błedów stron/sek
• Dostęp:
– Przystawka Performance Monitor (perfmon)
– API (natywne/zarządzane)
11. Klasa Debug i Trace c.d.
• Niemal identyczne
• Oparte o wspólną infrastrukturę TraceListeners
• Zależą od różnych falg (DEBUG i TRACE)
• Statyczne metody/właściwości Debug i Trace
– Assert
– Fail
– Write[Line][If]
– Indent
– AutoFlush
– Flush i Close
12. Klasa Debug i Trace c.d.
• Statyczne metody Trace:
– TraceError
– TraceInformation
– TraceWarning
13. Assert
• Dodatkowa dokumentacja
• Pozwalają zachować stan
• Jak sprawdzać?
– Atomowe sprawdzenia
– Bez efektów ubocznych
– Kompletnie
• Co sprawdzać?
– Parametry metod, setterów i indekserów
– Otrzymywane wartości z wywołań
• CodeContracts
14. TraceSwitch i TraceListener
• TraceSwitch
– Decyduje co ma być zalogowane zanim trafi do
listenera
• TraceListener
– Filtry
– Wbudowane listenery
• DefaultTraceListener
• TextWriterTraceListener
• XmlWriterTraceListener
• EventLogTraceListener
• DelimitedListTraceListener
– Możliwość tworzenia własnych listenerów i ich filtrów
15. CorrelationManager
• Pozwala grupować logiczne bloki aktywności
• Korzysta z Thread Local Storage
• Hierarchiczny (LogicalOperationStack)
• StartLogicalOperation
• StopLogicalOperation
• Udostępnia pole ActivityId
16. TraceSource
• Dedykowane źródła logów dla poszczególnych
modułów aplikacji
• Możliwośc przekazywania dodatkowych
danych do loga
• Szersza skala poziomów logowania
17. Trace Source A Trace Source B Trace Source C
Switch 1 Switch 2
Trace
Listener A
Trace
Listener B
Trace
Filter 1
Trace
Listener C
Trace
Listener D
Trace
Filter 2
18. Konfiguracja
• Poprzez API lub w app.config
<system.diagnostics>
<sources>
<source …>
<listeners>
<add … />
</listeners>
</source>
</sources>
<sharedListeners>
<add …/>
</sharedListeners>
<switches />
</system.diagnostics>
Notas do Editor
Dostęp do liczników poprzed perfmon oraz publiczne API z możliwością tworzenia zapytań.
Wymagana komunikacja międzyprocesowa. Możliwy dostęp do liczników spoza lokalnej maszyny.
CategoryName
CounterName
InstanceName
MachineName
ReadOnly – false możliwe tylko dla Custom Counters
Increment
IncrementBy
Statyczne meotdy -> Problemy ze skalowalnością
WriteIf ->
Statyczne meotdy -> Problemy ze skalowalnością
WriteIf ->
In the 2.0 version of the framework, note that allocating a new TraceSource internally allocates a WeakReference to the new TraceSource and puts the WeakReference into a list. Although the WeakReference allows the TraceSource to be garbage collected, the WeakReference itself will never be freed. If you are dynamically creating large numbers of TraceSources (or TraceSwitches) you will see a WeakReference leak. This should not be a problem because there should not be a reason to create TraceSources dynamically. Use a small number of static TraceSources instead.
Na podstawie Fig 3-7 z Debugging Microsoft .NET 2.0 Applications (John Robbins)