开发者

How to count the data sent or received by my PC (all processes/programs)?

I need to count the amount (in B/kB/MB/whatever) of data sent and received by my PC, by every running program/process.

Let's say I click "Start counting" and I get the sum of everything sent/received by my browser, FTP client, system actualizations etc. etc. from that moment till I choose "Stop".

To make it simpler, I want to count data transferred via TCP only - if it matters.

For now, I got the combo list of NICs in the PC (based on the comment in the link below). I tried to change the code given here but I failed, getting strange out-of-nowhere values in dataSent/dataReceived.

I also read the answer at the question 442409 but as I can see it is about the data sent/received by the same program, which doesn't fit my requirements开发者_JS百科.


Perfmon should have counters for this type of thing that you want to do, so look there first.


Alright, I think I've found the solution, but maybe someone will suggest something better...

I made the timer (tested it with 10ms interval), which gets the "Bytes Received/sec" PerformanceCounter value and adds it to a global "temporary" variable and also increments the sum counter (if there is any lag). Then I made second timer with 1s interval, which gets the sum of values (from temporary sum), divides it by the counter and adds to the overall amount (also global). Then it resets the temporary sum and the counter.

I'm just not sure if it is right method, because I don't know, how the variables of "Bytes Received/sec" PerformanceCounter are varying during the one second. Maybe I should make some kind of histograph and get the average value?

For now, downloading 8.6MB file gave me 9.2MB overall amount - is it possible the other processes would generate that amount of net activity in less than 20 seconds?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜