Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Procenat zauzetosti procesora

[es] :: .NET :: Procenat zauzetosti procesora

[ Pregleda: 2663 | Odgovora: 6 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Blue82
dipl. ecc.

Član broj: 165981
Poruke: 838
*.adsl-a-1.sezampro.yu.



+322 Profil

icon Procenat zauzetosti procesora03.04.2008. u 15:17 - pre 195 meseci
Kako u Visual Basic 2008 .NET dobiti procenat zauzetosti procesora? Ima neko kod?
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.adsl-1.sezampro.yu.



+395 Profil

icon Re: Procenat zauzetosti procesora03.04.2008. u 15:49 - pre 195 meseci
Kljucna rec u google-u : System.Diagnostics.PerformanceCounter
Primera ima bezbroj ....




Viva lollapalooza
 
Odgovor na temu

toxi_programer
Nemanja Todić
Beograd

Član broj: 104396
Poruke: 464
*.adsl-a-1.sezampro.yu.

Sajt: www.articles411.com


+8 Profil

icon Re: Procenat zauzetosti procesora03.04.2008. u 16:32 - pre 195 meseci
deerbeer, hvala za hint od mene, iako nisam ja postavio pitanje.
 
Odgovor na temu

Blue82
dipl. ecc.

Član broj: 165981
Poruke: 838
*.adsl-a-1.sezampro.yu.



+322 Profil

icon Re: Procenat zauzetosti procesora03.04.2008. u 18:47 - pre 195 meseci
Pronasao sam ovo ali ne snalazim se bas sa engleskim toliko a kako mi se cini ovo sve od koda nije potrebno a ne znam tacno ni gde bih ga pisao. Znam da te mucim ali ako imas zivaca mozes li mi preraditi ovo tipa sta je od toga samo potrebno i gde sta da pisem. Da bismo pojednostavili objasnjenje, iseci mi kako treba da izgleda kod koji mi u labeli1 na form1 napise procenat zauzetosti racunara. Evo i kod:

Visual Basic (Declaration)
<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization := True, _
SharedState := True)> _
Public NotInheritable Class PerformanceCounter _
Inherits Component _
Implements ISupportInitialize
----------------------------------------------
Visual Basic (Usage)
Dim instance As PerformanceCounter
----------------------------------------------

Visual Basic
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics

_

Public Class App

Private Shared PC As PerformanceCounter
Private Shared BPC As PerformanceCounter


Public Shared Sub Main()

Dim samplesList As New ArrayList()
'If the category does not exist, create the category and exit.
'Performance counters should not be created and immediately used.
'There is a latency time to enable the counters, they should be created
'prior to executing the application that uses the counters.
'Execute this sample a second time to use the counters.
If Not (SetupCategory()) Then
CreateCounters()
CollectSamples(samplesList)
CalculateResults(samplesList)
End If

End Sub 'Main



Private Shared Function SetupCategory() As Boolean
If Not PerformanceCounterCategory.Exists("AverageCounter64SampleCategory") Then

Dim CCDC As New CounterCreationDataCollection()

' Add the counter.
Dim averageCount64 As New CounterCreationData()
averageCount64.CounterType = PerformanceCounterType.AverageCount64
averageCount64.CounterName = "AverageCounter64Sample"
CCDC.Add(averageCount64)

' Add the base counter.
Dim averageCount64Base As New CounterCreationData()
averageCount64Base.CounterType = PerformanceCounterType.AverageBase
averageCount64Base.CounterName = "AverageCounter64SampleBase"
CCDC.Add(averageCount64Base)

' Create the category.
PerformanceCounterCategory.Create("AverageCounter64SampleCategory", _
"Demonstrates usage of the AverageCounter64 performance counter type.", _
PerformanceCounterCategoryType.SingleInstance, CCDC)


Return True
Else
Console.WriteLine("Category exists - AverageCounter64SampleCategory")
Return False
End If
End Function 'SetupCategory


Private Shared Sub CreateCounters()
' Create the counters.

PC = New PerformanceCounter("AverageCounter64SampleCategory", "AverageCounter64Sample", False)

BPC = New PerformanceCounter("AverageCounter64SampleCategory", "AverageCounter64SampleBase", False)


PC.RawValue = 0
BPC.RawValue = 0
End Sub 'CreateCounters

Private Shared Sub CollectSamples(samplesList As ArrayList)

Dim r As New Random(DateTime.Now.Millisecond)

' Loop for the samples.
Dim j As Integer
For j = 0 To 99

Dim value As Integer = r.Next(1, 10)
Console.Write(j.ToString() + " = " + value.ToString())

PC.IncrementBy(value)

BPC.Increment()

If j Mod 10 = 9 Then
OutputSample(PC.NextSample())
samplesList.Add(PC.NextSample())
Else
Console.WriteLine()
End If
System.Threading.Thread.Sleep(50)
Next j
End Sub 'CollectSamples

Private Shared Sub CalculateResults(samplesList As ArrayList)
Dim i As Integer
For i = 0 To (samplesList.Count - 1) - 1
' Output the sample.
OutputSample(CType(samplesList(i), CounterSample))
OutputSample(CType(samplesList((i + 1)), CounterSample))

' Use .NET to calculate the counter value.
Console.WriteLine(".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())

' Calculate the counter value manually.
Console.WriteLine("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
Next i
End Sub 'CalculateResults




'++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
' Description - This counter type shows how many items are processed, on average,
' during an operation. Counters of this type display a ratio of the items
' processed (such as bytes sent) to the number of operations completed. The
' ratio is calculated by comparing the number of items processed during the
' last interval to the number of operations completed during the last interval.
' Generic type - Average
' Formula - (N1 - N0) / (D1 - D0), where the numerator (N) represents the number
' of items processed during the last sample interval and the denominator (D)
' represents the number of operations completed during the last two sample
' intervals.
' Average (Nx - N0) / (Dx - D0)
' Example PhysicalDisk\ Avg. Disk Bytes/Transfer
'++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
Private Shared Function MyComputeCounterValue(s0 As CounterSample, s1 As CounterSample) As [Single]
Dim numerator As [Single] = CType(s1.RawValue, [Single]) - CType(s0.RawValue, [Single])
Dim denomenator As [Single] = CType(s1.BaseValue, [Single]) - CType(s0.BaseValue, [Single])
Dim counterValue As [Single] = numerator / denomenator
Return counterValue
End Function 'MyComputeCounterValue


' Output information about the counter sample.
Private Shared Sub OutputSample(s As CounterSample)
Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
Console.WriteLine((" BaseValue = " + s.BaseValue.ToString()))
Console.WriteLine((" CounterFrequency = " + s.CounterFrequency.ToString()))
Console.WriteLine((" CounterTimeStamp = " + s.CounterTimeStamp.ToString()))
Console.WriteLine((" CounterType = " + s.CounterType.ToString()))
Console.WriteLine((" RawValue = " + s.RawValue.ToString()))
Console.WriteLine((" SystemFrequency = " + s.SystemFrequency.ToString()))
Console.WriteLine((" TimeStamp = " + s.TimeStamp.ToString()))
Console.WriteLine((" TimeStamp100nSec = " + s.TimeStamp100nSec.ToString()))
Console.WriteLine("++++++++++++++++++++++")
End Sub 'OutputSample
End Class 'App



Znam da ima relativno puno toga, nikada ne postavljam tako obimna pitanja ali stvarno nisam vican ovome. Hvala ti ako se potrudis. Pretpostavljam da zapravo treba samo trecina od ovoga ako ne i manje.
 
Odgovor na temu

nikomak
Nikola Makić
Beograd

Član broj: 177053
Poruke: 65
*.eunet.yu.



+1 Profil

icon Re: Procenat zauzetosti procesora03.04.2008. u 20:38 - pre 195 meseci
Ako se ne varam ovo gore je primer iz MSDN-a. ali ne treba ti nista od ovoga (skoro nista od toga :)
Evo kako to izgleda u C# (neka neko prevede u VB posto ne znam doticni ;)

Code:

using System;
using System.Diagnostics;
using System.Threading;

namespace CPUOpterecenje
{
    class Program
    {
        static void Main(string[] args)
        {
            PerformanceCounter pc = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            pc.NextValue();
            while (true) 
            {
                float opterecenje = pc.NextValue();
                Console.WriteLine("% zauzeca CPU: {0}", opterecenje);
                Thread.Sleep(1000);
            }
        } 
    }
}


Konzolni primer gore vrsi sampling procenata zauzeca procesora svake sekunde.
TurboDispatchJumpAddressEnd
----
Knocka Fia
----
And so we meet, again in a different time
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.adsl-a-1.sezampro.yu.



+395 Profil

icon Re: Procenat zauzetosti procesora03.04.2008. u 20:39 - pre 195 meseci
MIslim da bi ti ovo bilo dovoljno za sad ..

//za procesorsko vreme
Code:

Imports System.Diagnostics
Dim oPerf1 As New PerformanceCounter
oPerf1.CategoryName = "Processor"
oPerf1.CounterName = "% Processor Time"
oPerf1.InstanceName = "0"

' metoda NextValue ti daje trenutno stanje counter-a 
Dim I As Integer
For I = 0 To 100
SomeListBox.Items.Add (oPerf1.NextValue)
Threading.Thread.Sleep (20)
Next


' za ram memoriju 
Dim ramCounter As New PerformanceCounter("Memory", "Available MBytes");
Dim strRAM  As String 
strRAM = ramCounter.NextValue ;  


Nisam se preterano zadubljivao u kod koji si poslao ..al u pitanju je custom performance counter (kolekcija) koji u toku runtime-a sakuplja samplove iz tvojih kalkulacija u kodu i smesta ih u arrayliste ..

Viva lollapalooza
 
Odgovor na temu

Blue82
dipl. ecc.

Član broj: 165981
Poruke: 838
*.adsl-a-1.sezampro.yu.



+322 Profil

icon Re: Procenat zauzetosti procesora03.04.2008. u 21:15 - pre 195 meseci
Aha, e sad ovako, sta to tacno treba da radi? Ako se ne varam napravio sam jedan ListBox pod imenom SomeListBox.
i stavio sam jedan Button i napisao kod u okviru buttona sve osim prvog reda koji ide tamo skroz na pocetku pisanja van svega (ne znam kako se to zove ali valjda se razumemo). I kada startujem on puni ListBox ali ga napuni samo vrednostima 0, 50 i 100 a mislim da nema ni veze sa zauzecem procesora jer kad startujem windows-ov on ne pokazije ni blizu te vrednosti. Gresim negde ili...?
 
Odgovor na temu

[es] :: .NET :: Procenat zauzetosti procesora

[ Pregleda: 2663 | Odgovora: 6 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.