mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:07:35 +00:00
Utilities/allocate: Modernize the code a bit
Use LibCore ArgsParser to parse the parameters instead of using the raw strings from the argv (Main::Arguments) array. Also, use indicative names for variables in the code so the utility code is more understandable.
This commit is contained in:
parent
75ae368896
commit
b74cb569ec
2 changed files with 105 additions and 53 deletions
|
@ -5,36 +5,31 @@ allocate - allocate memory
|
|||
## Synopsis
|
||||
|
||||
```**sh
|
||||
$ allocate [number [unit (B/KiB/MiB)]]
|
||||
$ allocate [--unit B/KiB/MiB/GiB] [--sleep-time N] [number]
|
||||
```
|
||||
|
||||
## Description
|
||||
|
||||
`allocate` allocates a specific amount of virtual memory (specified in `number` and `unit`, by default 50 MiB), It also writes to each allocated page and then sleeps for 10 seconds. It is primarily used to test the kernel's memory management capabilities.
|
||||
`allocate` allocates a specific amount of virtual memory. If nothing is specified
|
||||
then it will allocate 100 bytes of memory.
|
||||
If `number` is specified without `unit`, it will default to `number` of bytes.
|
||||
It also writes to each allocated page and then sleeps for N seconds (by default 10).
|
||||
It is primarily used to test the kernel's memory management capabilities.
|
||||
|
||||
## Arguments
|
||||
## Options
|
||||
|
||||
* `number`: A number of `units` to allocate; the default is **50**
|
||||
* `unit`: Data size unit, can be `B` (bytes), `KiB` (kibibytes) or `MiB` (mebibytes); the default is **MiB**
|
||||
* `-u`, `--size-unit`: Allocation's Size Unit (Base 2 units - B, KiB, MiB or GiB)
|
||||
* `-n`, `--sleep-time`: Number of seconds to sleep before freeing memory
|
||||
|
||||
## Examples
|
||||
|
||||
```sh
|
||||
$ allocate 100 MiB
|
||||
allocating memory (104857600 bytes)...
|
||||
done in 13ms
|
||||
$ allocate 500
|
||||
allocating memory (500 bytes)...
|
||||
done in 0ms
|
||||
writing one byte to each page of allocated memory...
|
||||
step took 46ms (217.391304MiB/s)
|
||||
step took 32ms (312.500000MiB/s)
|
||||
step took 31ms (322.580645MiB/s)
|
||||
step took 55ms (181.818181MiB/s)
|
||||
step took 35ms (285.714285MiB/s)
|
||||
step took 40ms (250.000000MiB/s)
|
||||
step took 39ms (256.410256MiB/s)
|
||||
step took 52ms (192.307692MiB/s)
|
||||
step took 44ms (227.272727MiB/s)
|
||||
done in 426ms
|
||||
sleeping for ten seconds...
|
||||
done in 0ms
|
||||
sleeping for 10 seconds...
|
||||
0
|
||||
1
|
||||
2
|
||||
|
@ -47,5 +42,58 @@ sleeping for ten seconds...
|
|||
9
|
||||
done.
|
||||
freeing memory...
|
||||
done in 119ms
|
||||
done in 0ms
|
||||
|
||||
$ allocate 500 -u KiB
|
||||
allocating memory (512000 bytes)...
|
||||
done in 0ms
|
||||
writing one byte to each page of allocated memory...
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
done in 4ms
|
||||
sleeping for 10 seconds...
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
done.
|
||||
freeing memory...
|
||||
done in 0ms
|
||||
|
||||
$ allocate -u KiB -n 2 500
|
||||
allocating memory (512000 bytes)...
|
||||
done in 0ms
|
||||
writing one byte to each page of allocated memory...
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
step took 1ms (46.875MiB/s)
|
||||
done in 0ms
|
||||
sleeping for 2 seconds...
|
||||
0
|
||||
1
|
||||
done.
|
||||
freeing memory...
|
||||
done in 0ms
|
||||
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue