1 | /*
|
2 | * Copyright (c) 2012 Dmitri Melikyan
|
3 | *
|
4 | * Permission is hereby granted, free of charge, to any person obtaining a
|
5 | * copy of this software and associated documentation files (the
|
6 | * "Software"), to deal in the Software without restriction, including
|
7 | * without limitation the rights to use, copy, modify, merge, publish,
|
8 | * distribute, sublicense, and/or sell copies of the Software, and to permit
|
9 | * persons to whom the Software is furnished to do so, subject to the
|
10 | * following conditions:
|
11 | *
|
12 | * The above copyright notice and this permission notice shall be included
|
13 | * in all copies or substantial portions of the Software.
|
14 | *
|
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
18 | * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
21 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22 | */
|
23 |
|
24 |
|
25 | var nt = require('../nodetime');
|
26 | var proxy = require('../proxy');
|
27 | var samples = require('../samples');
|
28 |
|
29 |
|
30 | var commands = [
|
31 | 'get',
|
32 | 'gets',
|
33 | 'getMulti',
|
34 | 'set',
|
35 | 'replace',
|
36 | 'add',
|
37 | 'cas',
|
38 | 'append',
|
39 | 'prepend',
|
40 | 'increment',
|
41 | 'decrement',
|
42 | 'incr',
|
43 | 'decr',
|
44 | 'del',
|
45 | 'delete',
|
46 | 'version',
|
47 | 'flush',
|
48 | 'samples',
|
49 | 'slabs',
|
50 | 'items',
|
51 | 'flushAll',
|
52 | 'samplesSettings',
|
53 | 'samplesSlabs',
|
54 | 'samplesItems',
|
55 | 'cachedump'
|
56 | ];
|
57 |
|
58 |
|
59 | module.exports = function(obj) {
|
60 | commands.forEach(function(command) {
|
61 | proxy.before(obj.prototype, command, function(obj, args) {
|
62 | // ignore, getMulti will be called
|
63 | if(command === 'get' && Array.isArray(args[0])) return;
|
64 |
|
65 | var client = obj;
|
66 | var trace = samples.stackTrace();
|
67 | var params = args;
|
68 | var time = samples.time("Memcached", command);
|
69 |
|
70 | proxy.callback(args, -1, function(obj, args) {
|
71 | if(!time.done()) return;
|
72 | if(nt.paused) return;
|
73 |
|
74 | var error = (args && args.length > 0) ? (args[0] ? args[0].message : undefined) : undefined;
|
75 | var obj = {'Type': 'Memcached',
|
76 | 'Servers': client.servers,
|
77 | 'Command': command,
|
78 | 'Arguments': samples.truncate(params),
|
79 | 'Stack trace': trace,
|
80 | 'Error': error};
|
81 |
|
82 | samples.add(time, obj, 'Memcached: ' + obj['Command']);
|
83 | });
|
84 | });
|
85 | });
|
86 | };
|
87 |
|