Memory detection
1100110
10equals2 at gmail.com
Fri Aug 24 13:52:02 PDT 2012
On Fri, 24 Aug 2012 15:42:21 -0500, Dmitry Olshansky
<dmitry.olsh at gmail.com> wrote:
> On 24-Aug-12 07:03, 1100110 wrote:
>>
>> On linux this is not so difficult to do.
>>
>> Those values are generally in /proc, and it seems to be portable across
>> pretty much every distro with a relatively recent kernel.
>>
>> I have an extremely half-assed bit of code that prints the load average
>> and the totaly % of mem used to my tmux session.
>> It gives the exact same values that are seen in top, or htop.(without
>> the overhead of parsing their output, cause that takes ~500ms, way too
>> slow.)
>
> If parsing takes 500ms then something is seriously wrong. What is size
> of the input to parse and the machine specs?
>
>
No, you misunderstand.
Parsing the output of the `top` command takes ~500ms.
The snippet of code that reads /proc directly takes an order of magnitude
less time.
I assume that top reads several times, and also reads the percentages of
each process that is running, while I only
read the load average and total memory consumption.
The vast majority of the time spent parsing `top` was spent waiting for it
to initialize, and print the values to be read.
TL;DR
Parsing was probably the wrong word to use.
Reading from /proc directly will take an order of magnitude less time.
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d-learn
mailing list