-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:chenshuo/recipes
- Loading branch information
Showing
5 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <stdio.h> | ||
|
||
#include "Acceptor.h" | ||
#include "InetAddress.h" | ||
#include "Socket.h" | ||
#include "TcpStream.h" | ||
|
||
|
||
void dump(const char* filename) | ||
{ | ||
char buf[65536]; | ||
FILE* fp = fopen(filename, "r"); | ||
if (fp) | ||
{ | ||
ssize_t nr; | ||
while ( (nr = fread(buf, 1, sizeof buf, fp)) > 0) | ||
fwrite(buf, 1, nr, stdout); | ||
|
||
fclose(fp); | ||
} | ||
} | ||
|
||
void snapshot(const char* name) | ||
{ | ||
printf("===== %s =====\n", name); | ||
dump("/proc/meminfo"); | ||
dump("/proc/slabinfo"); | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
const int N = argc > 1 ? atoi(argv[1]) : 1000; | ||
|
||
{ | ||
char buf[32]; | ||
snprintf(buf, sizeof buf, "start N=%d", N); | ||
snapshot(buf); | ||
} | ||
|
||
InetAddress listenAddr(2222); | ||
Acceptor acceptor(listenAddr); | ||
snapshot("acceptor created"); | ||
|
||
std::vector<Socket> clients; | ||
for (int i = 0; i < N; ++i) | ||
clients.push_back(Socket::createTCP()); | ||
snapshot("clients created"); | ||
|
||
std::vector<Socket> servers; | ||
InetAddress serverAddr("127.0.0.1", 2222); | ||
for (int i = 0; i < N; ++i) | ||
{ | ||
if (clients[i].connect(serverAddr)) | ||
{ | ||
perror("connect"); | ||
break; | ||
} | ||
servers.push_back(acceptor.acceptSocketOrDie()); | ||
} | ||
snapshot("clients connected"); | ||
|
||
// TODO: epoll | ||
|
||
servers.clear(); | ||
snapshot("servers disconnected"); | ||
|
||
clients.clear(); | ||
snapshot("clients disconnected"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/python | ||
|
||
from collections import OrderedDict | ||
import re, sys | ||
|
||
slabs = {} | ||
|
||
sections = [] | ||
|
||
section = None | ||
|
||
for line in sys.stdin: | ||
m = re.match('===== (.*) =====', line) | ||
if m: | ||
section_name = m.group(1) | ||
# print section_name | ||
if (section): | ||
sections.append(section) | ||
section = (section_name, OrderedDict(), OrderedDict()) | ||
meminfo = True | ||
continue | ||
if re.match('slabinfo -', line): | ||
meminfo = False | ||
continue | ||
if meminfo: | ||
m = re.match('(.*): *(\\d+) kB', line) | ||
if m: | ||
section[1][m.group(1)] = int(m.group(2)) | ||
else: | ||
if line[0] == '#': | ||
continue | ||
(slab, active, total, objsize) = line.split()[:4] | ||
slabs[slab] = int(objsize) | ||
section[2][slab] = int(active) | ||
|
||
|
||
sections.append(section) | ||
|
||
for i in range(1, len(sections)): | ||
print '=====', sections[i][0] | ||
meminfo = sections[i][1] | ||
old = sections[i-1][1] | ||
for key in meminfo: | ||
diff = meminfo[key]-old[key] | ||
if diff: | ||
print key, diff | ||
|
||
print '-----' | ||
slab = sections[i][2] | ||
old = sections[i-1][2] | ||
for key in slab: | ||
diff = slab[key]-old[key] | ||
if diff: | ||
print key, slabs[key], diff | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters