diff options
author | Erich Eckner <git@eckner.net> | 2016-03-10 10:27:14 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2016-03-15 13:01:16 +0100 |
commit | cd76a7ae64b82c2001476548a8c5c70873045083 (patch) | |
tree | 69e1b1d495837e89681d6ade95f37e45c5423ff4 | |
parent | b67ce1d2d4274422b846584c1d15da64230f4507 (diff) | |
download | units-cd76a7ae64b82c2001476548a8c5c70873045083.tar.xz |
systemunit.pas aufgeräumt
-rw-r--r-- | systemunit.pas | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/systemunit.pas b/systemunit.pas index 763c8db..d4ec24b 100644 --- a/systemunit.pas +++ b/systemunit.pas @@ -36,19 +36,16 @@ begin reset(procstat); while not eof(procstat) do begin readln(procstat,s); - if pos('cpu ',s)=1 then break; + if startetMit('cpu ',s) then break; + s:=''; end; closefile(procstat); - if pos('cpu ',s)<>1 then exit; - delete(s,1,pos(' ',s)); - s:=trim(s); + if s='' then exit; used:=0; idle:=0; for i:=0 to 3 do begin used:=used+idle; - idle:=strtoint(copy(s,1,pos(' ',s)-1)); - delete(s,1,pos(' ',s)); - s:=trim(s); + idle:=strtoint(erstesArgument(s)); end; result:=(used-_cpuLastUsed)/max(1,used-_cpuLastUsed + idle-_cpuLastIdle); _cpuLastUsed:=used; @@ -66,8 +63,8 @@ begin reset(procstat); while not eof(procstat) do begin readln(procstat,s); - if (pos('cpu',s)=1) and - (pos('cpu ',s)<>1) then + if (not startetMit('cpu ',s)) and + startetMit('cpu',s) then inc(result); end; closefile(procstat); @@ -90,8 +87,8 @@ begin reset(f); while not eof(f) do begin readln(f,s); - if (leftStr(s,4)='Rss:') and (rightStr(s,3)=' kB') then - result:=result+strtoint(trim(copy(s,5,length(s)-4-3))); + if startetMit('Rss:',s) and (endetMit('kB',s) or endetMit('KB',s)) then + result:=result+strtoint(s); end; closefile(f); end; @@ -108,10 +105,7 @@ begin reset(f); while not eof(f) do begin readln(f,s); - if (leftStr(s,10)='cache size') and (rightStr(s,3)=' kB') then begin - delete(s,1,pos(':',s)); - delete(s,length(s)-2,3); - s:=trim(s); + if startetMit('cache',s) and startetMit('size',s) and startetMit(':',s) and (endetMit('KB',s) or endetMit('kB',s)) then begin if result=0 then result:=strtoint(s) else result:=min(result,strtoint(s)); end; @@ -125,10 +119,8 @@ var begin result:=s; while pos('${',result)>0 do begin - s:=leftStr(result,pos('${',result)-1); - delete(result,1,pos('${',result)-1+length('${')); - name:=leftStr(result,pos('}',result)-1); - delete(result,1,length(name+'}')); + s:=erstesArgument(result,'${',false); + name:=erstesArgument(result,'}',false); result:=s+GetEnvironmentVariable(name)+result; end; end; |