forked from uillianluiz/node-tiers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
malloc.ts
34 lines (28 loc) · 906 Bytes
/
malloc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Tier, Status } from './tier';
import ffi = require('ffi');
/**
* Malloc tier (Linux only)
* Main resources used: Memory
*/
export default class Malloc extends Tier {
bytes: number;
/**
* It executes a C lib that execute several malloc, calloc, realloc and free operations.
* Check file malloc.c for details.
* The libmalloc is generated by executing: npm run gulp
* @param bytes quantity of bytes to be allocate in each iteration.
*/
constructor(bytes = 500000) {
super();
this.bytes = bytes;
}
protected executeTask(): Status {
var libmalloc = ffi.Library('./dist/clib/libmalloc', {
'stressMalloc': ['int', ['long']]
});
var output = libmalloc.stressMalloc(this.bytes);
if (output == -1)
return new Status("There was an error executing the malloc lib.", 500);
return new Status("Malloc lib executed successfully.");
}
}