Skip to content
Snippets Groups Projects
Commit 7175a458 authored by 名嘉真 梗介's avatar 名嘉真 梗介
Browse files

malloc_test

parents
Branches main
No related tags found
No related merge requests found
#!/usr/bin/perl
use strict;
my $width = 1200;
my $step = $width;
my $m_height = 3;
my $base = 0;
my $malloc_test = "./a.out -m 1000000 -l 10 -u 16";
# my $malloc_test = "ssh urasoe.ie.u-ryukyu.ac.jp ./a.out -m 10000000 -l 10 -u 16";
# my $malloc_test = "ssh urasoe.ie.u-ryukyu.ac.jp ./a.out -u 16 -m 1000000 -l 10";
# my $malloc_test = "ssh yomitan.ie.u-ryukyu.ac.jp ./malloc_test -m 10000000 -l 10";
# my $malloc_test = "./malloc_test -m 100000 -l 10";
# my $malloc_test = "./malloc_test -m 10000000 -l 10";
open(TEST,"$malloc_test | sort|") or die("Cannot run $malloc_test $!\n");
my ($min,$max);
my @adr;
my @size;
while(<TEST>) {
chop;
my ($adr,$size) = split;
$adr = eval($adr);
$size = eval($size);
$min = $adr if ($min==0||$adr<$min);
$max = $adr if ($adr>$max);
push(@adr,$adr);
push(@size,$size);
}
# print "$width $max $min\n";
my $scale = $step/($max-$min);
# print "$scale $width $max $min\n";
# $m->update;
# exit;
my @data;
for(my $i =0; $i<$#adr;$i++) {
my $adr = ($adr[$i]-$min)*$scale;
my $size = $size[$i]*$scale;
my $y = int($adr/$width) * $m_height + $base;
my $x = int($adr)%$width;
# print STDERR "$adr $size $x $y\n";
push(@data, $x,$size );
}
my $xydata = "[" . join(",",@data) ."]";
my $count = int ($#data / 2);
my $js = << "EOFEOF";
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>D3 World Map</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
#halfpage{
background: "white";
overflow-x: scroll;
}
</style>
</head>
<body>
<button type="button" onclick="shrink()" >shrink </button>
<button type="button" onclick="enlarge()" >enlarge</button>
<script type="text/javascript">
var elements = Array.from(Array($count).keys());
var xydata = $xydata;
var scale = 1;
var shrink = function(){
scale = scale * 0.7 ;
svgContainer.remove();
svgUpdate(scale,"green");
}
var enlarge = function(){
scale = scale / 0.7 ;
svgContainer.remove();
svgUpdate(scale,"green");
}
var svgUpdate = function(scale,color){
svgContainer = d3.select("body").append("svg")
.attr("width", 1200 * scale)
.attr("height", 300)
.attr("id", "halfpage");
svgContainer.selectAll("rects1").data(elements).enter().append("rect")
.attr("width", function(d,i) { return xydata[i*2+1] * scale;} )
.attr("height", 20)
.attr("y", 175)
.attr("x", function(d,i) { return xydata[i*2] * scale; })
.style("fill", color)
.style("stroke-width", 1)
.style("stroke", "black");
}
svgUpdate(scale,"green");
</script>
</body>
</html>
EOFEOF
print "$js";
# end
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
long MEMORY = 16000*1000*100; // test memory limit
long ALLOCATED = 0;
long COUNT = 8000; // repeat count
long ACTIVE = 1000; // number of memroy segment
long MAXSIZE = 400000; //
long MINSIZE = 400;
long MIN_UNIT = 16 ;
typedef
struct mem_list {
void *address;
long size;
struct mem_list *next;
} MEM_LIST, *MEM_LIST_PTR;
void
print_mem_list(MEM_LIST_PTR m)
{
MEM_LIST_PTR n;
if (!m) return;
n = m->next;
for(;n&&n!=m;n=n->next) {
// some malloc returns very large value. remove it to keep output clear
// if (n->address && ! (((long)n->address) & 0x700000000000))
printf("%p 0x%08lx\n",n->address,n->size);
}
}
void
die(char *msg)
{
fprintf(stderr,"%s\n",msg);
exit(0);
}
void
option(long ac, char *av[])
{
long i = 1;
while(ac>1) {
if (av[i][0] == '-') {
switch (av[i][1]) {
case 'c': COUNT = atol(av[++i]); break;
case 'a': ACTIVE = atol(av[++i]); break;
case 'u': MIN_UNIT = atol(av[++i]); break;
case 'm': MAXSIZE = atol(av[++i]); break;
case 'l': MINSIZE = atol(av[++i]); break;
case 'M': MEMORY = atol(av[++i]); break;
}
ac--;
}
ac--; i++;
}
}
int
main(int ac, char *av[])
{
MEM_LIST mlist;
MEM_LIST_PTR last = &mlist;
MEM_LIST_PTR new;
long i,size;
option(ac,av);
mlist.address = NULL;
mlist.size = 0;
for(i=0;i<ACTIVE;i++) {
new = (MEM_LIST_PTR)malloc(sizeof(MEM_LIST));
if (!new) die("malloc error");
new->address = NULL;
new->next = NULL;
last->next = new;
last = new;
}
last->next = &mlist;
for(i=0;i++<COUNT;last=last->next) {
size = ((random()%(MAXSIZE-MINSIZE))+MINSIZE)*MIN_UNIT;
if (last->address) {
ALLOCATED -= last->size;
last->size = 0;
free(last->address);
last->address = 0;
}
if ( ALLOCATED + size > MEMORY) {
// printf("%ld %ld size error\n",ALLOCATED , size);
// continue;
}
last->size = size;
last->address = (void *)malloc(size);
if (!last->address) die("malloc error");
memset(last->address, random(), size);
ALLOCATED += size;
}
print_mem_list(&mlist);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment