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 | var nt = require('../nodetime');
|
26 | var proxy = require('../proxy');
|
27 | var samples = require('../samples');
|
28 |
|
29 |
|
30 | var commands = [
|
31 | 'rename',
|
32 | 'truncate',
|
33 | 'chown',
|
34 | 'fchown',
|
35 | 'lchown',
|
36 | 'chmod',
|
37 | 'fchmod',
|
38 | 'lchmod',
|
39 | 'stat',
|
40 | 'lstat',
|
41 | 'fstat',
|
42 | 'link',
|
43 | 'symlink',
|
44 | 'readlink',
|
45 | 'realpath',
|
46 | 'unlink',
|
47 | 'rmdir',
|
48 | 'mkdir',
|
49 | 'readdir',
|
50 | 'close',
|
51 | 'open',
|
52 | 'utimes',
|
53 | 'futimes',
|
54 | 'fsync',
|
55 | 'write',
|
56 | 'read',
|
57 | 'readFile',
|
58 | 'writeFile',
|
59 | 'appendFile',
|
60 | 'exists'
|
61 | ];
|
62 |
|
63 |
|
64 | module.exports = function(obj) {
|
65 | commands.forEach(function(command) {
|
66 | proxy.before(obj, command, function(obj, args) {
|
67 | var trace = samples.stackTrace();
|
68 | var params = args;
|
69 | var time = samples.time("File System", command);
|
70 |
|
71 | proxy.callback(args, -1, function(obj, args) {
|
72 | if(!time.done()) return;
|
73 | if(nt.paused) return;
|
74 |
|
75 | var error = args.length > 0 ? (args[0] ? args[0].message : undefined) : undefined;
|
76 | var context = {'Type': 'File System',
|
77 | 'Command': command,
|
78 | 'Arguments': samples.truncate(params),
|
79 | 'Stack trace': trace,
|
80 | 'Error': error};
|
81 |
|
82 | samples.add(time, context, 'File System: ' + context['Command']);
|
83 | });
|
84 | });
|
85 |
|
86 |
|
87 | var commandSync = command + 'Sync';
|
88 | proxy.around(obj, commandSync, function(obj, args, locals) {
|
89 | locals.stackTrace = samples.stackTrace();
|
90 | locals.params = args;
|
91 | locals.time = samples.time("File System", commandSync);
|
92 |
|
93 | }, function(obj, args, ret, locals) {
|
94 | if(!locals.time.done()) return;
|
95 | if(nt.paused) return;
|
96 |
|
97 | var context = {'Type': 'File System',
|
98 | 'Command': commandSync,
|
99 | 'Arguments': samples.truncate(locals.params),
|
100 | 'Stack trace': locals.stackTrace};
|
101 |
|
102 | samples.add(locals.time, context, 'File System: ' + context['Command']);
|
103 | });
|
104 | });
|
105 | };
|
106 |
|