Memory detection

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Aug 24 14:05:28 PDT 2012


On 25-Aug-12 00:52, 1100110 wrote:
> 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.
>
Then it's not parsing but the it's time to spawn process that does a 
fuckton of syscalls and read its output through the pipe :)
I just cringed at:
"the overhead of parsing their output, cause that 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.
>

Yes, sorry for being nit-picky.

> Reading from /proc directly will take an order of magnitude less time.


And yes.

-- 
Olshansky Dmitry


More information about the Digitalmars-d-learn mailing list