whatap 1.0.2 → 1.0.3-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +77 -33
  2. package/agent/darwin/arm64/whatap_nodejs +0 -0
  3. package/agent/linux/amd64/whatap_nodejs +0 -0
  4. package/agent/linux/arm64/whatap_nodejs +0 -0
  5. package/build.txt +4 -0
  6. package/lib/conf/config-default.js +3 -10
  7. package/lib/conf/configure.js +349 -369
  8. package/lib/conf/license.js +1 -1
  9. package/lib/control/packagectr-helper.js +3 -34
  10. package/lib/core/agent.js +888 -176
  11. package/lib/core/interceptor.js +6 -6
  12. package/lib/core/shimmer.js +36 -82
  13. package/lib/counter/counter-manager.js +8 -79
  14. package/lib/counter/task/activetransaction.js +17 -68
  15. package/lib/io/data-inputx.js +3 -13
  16. package/lib/io/data-outputx.js +206 -268
  17. package/lib/logger.js +6 -6
  18. package/lib/net/security-master.js +20 -139
  19. package/lib/observers/apollo-server-observer.js +27 -33
  20. package/lib/observers/global-observer.js +80 -155
  21. package/lib/observers/http-observer.js +236 -666
  22. package/lib/observers/ioredis-observer.js +294 -0
  23. package/lib/observers/maria-observer.js +362 -204
  24. package/lib/observers/mongodb-observer.js +226 -169
  25. package/lib/observers/mongoose-observer.js +323 -518
  26. package/lib/observers/mssql-observer.js +418 -177
  27. package/lib/observers/mysql-observer.js +449 -342
  28. package/lib/observers/mysql2-observer.js +358 -396
  29. package/lib/observers/oracle-observer.js +384 -559
  30. package/lib/observers/pgsql-observer.js +489 -231
  31. package/lib/observers/prisma-observer.js +92 -303
  32. package/lib/observers/process-observer.js +35 -79
  33. package/lib/observers/redis-observer.js +331 -166
  34. package/lib/observers/socket.io-observer.js +187 -226
  35. package/lib/observers/websocket-observer.js +301 -175
  36. package/lib/pack/counter-pack.js +0 -3
  37. package/lib/pack/log-sink-pack.js +52 -14
  38. package/lib/pack/tagcount-pack.js +4 -4
  39. package/lib/{counter/task → system}/gc-action.js +74 -27
  40. package/lib/trace/trace-context-manager.js +25 -113
  41. package/lib/trace/trace-context.js +7 -21
  42. package/lib/trace/trace-httpc.js +11 -17
  43. package/lib/trace/trace-sql.js +21 -29
  44. package/lib/udp/async_sender.js +119 -0
  45. package/lib/udp/index.js +17 -0
  46. package/lib/udp/packet_enum.js +52 -0
  47. package/lib/udp/packet_queue.js +69 -0
  48. package/lib/udp/packet_type_enum.js +33 -0
  49. package/lib/udp/param_def.js +72 -0
  50. package/lib/udp/udp_session.js +336 -0
  51. package/lib/util/escape-literal-sql.js +5 -5
  52. package/lib/util/hashutil.js +18 -18
  53. package/lib/util/keygen.js +3 -0
  54. package/lib/util/linkedset.js +2 -1
  55. package/lib/util/nodeutil.js +1 -2
  56. package/lib/util/sql-util.js +178 -0
  57. package/lib/util/trace-helper.js +91 -0
  58. package/lib/util/transfer.js +58 -0
  59. package/lib/value/map-value.js +2 -3
  60. package/package.json +5 -9
  61. package/whatap.conf +4 -1
  62. package/lib/conf/conf-sys-mon.js +0 -101
  63. package/lib/control/cmd-config.js +0 -24
  64. package/lib/control/control-handler.js +0 -367
  65. package/lib/core/request-agent.js +0 -27
  66. package/lib/counter/meter/meter-activex.js +0 -67
  67. package/lib/counter/meter/meter-httpc.js +0 -57
  68. package/lib/counter/meter/meter-resource.js +0 -9
  69. package/lib/counter/meter/meter-service.js +0 -168
  70. package/lib/counter/meter/meter-socket.io.js +0 -51
  71. package/lib/counter/meter/meter-sql.js +0 -71
  72. package/lib/counter/meter/meter-users.js +0 -58
  73. package/lib/counter/meter.js +0 -183
  74. package/lib/counter/task/agentinfo.js +0 -107
  75. package/lib/counter/task/gcstat.js +0 -34
  76. package/lib/counter/task/heapmem.js +0 -25
  77. package/lib/counter/task/httpc.js +0 -76
  78. package/lib/counter/task/metering-info.js +0 -125
  79. package/lib/counter/task/proc-cpu.js +0 -29
  80. package/lib/counter/task/realtimeuser.js +0 -31
  81. package/lib/counter/task/res/systemECSTask.js +0 -39
  82. package/lib/counter/task/res/systemKubeTask.js +0 -53
  83. package/lib/counter/task/res/util/awsEcsClientThread.js +0 -218
  84. package/lib/counter/task/res/util/linuxProcStatUtil.js +0 -14
  85. package/lib/counter/task/res-sys-cpu.js +0 -62
  86. package/lib/counter/task/service.js +0 -202
  87. package/lib/counter/task/socketio.js +0 -30
  88. package/lib/counter/task/sql.js +0 -105
  89. package/lib/counter/task/systemperf.js +0 -43
  90. package/lib/data/datapack-sender.js +0 -289
  91. package/lib/data/dataprofile-agent.js +0 -162
  92. package/lib/data/datatext-agent.js +0 -135
  93. package/lib/data/event-level.js +0 -15
  94. package/lib/data/test.js +0 -49
  95. package/lib/data/zipprofile.js +0 -197
  96. package/lib/env/constants.js +0 -21
  97. package/lib/error/error-handler.js +0 -437
  98. package/lib/kube/kube-client.js +0 -144
  99. package/lib/lang/text-types.js +0 -58
  100. package/lib/logsink/line-log-util.js +0 -87
  101. package/lib/logsink/line-log.js +0 -12
  102. package/lib/logsink/log-sender.js +0 -78
  103. package/lib/logsink/log-tracer.js +0 -40
  104. package/lib/logsink/sender-util.js +0 -56
  105. package/lib/logsink/zip/zip-send.js +0 -177
  106. package/lib/net/netflag.js +0 -55
  107. package/lib/net/receiver.js +0 -66
  108. package/lib/net/sender.js +0 -141
  109. package/lib/net/tcp-return.js +0 -18
  110. package/lib/net/tcp-session.js +0 -286
  111. package/lib/net/tcpreq-client-proxy.js +0 -70
  112. package/lib/net/tcprequest-mgr.js +0 -58
  113. package/lib/observers/cluster-observer.js +0 -22
  114. package/lib/observers/express-observer.js +0 -215
  115. package/lib/observers/file-observer.js +0 -184
  116. package/lib/observers/grpc-observer.js +0 -336
  117. package/lib/observers/memcached-observer.js +0 -56
  118. package/lib/observers/mongo-observer.js +0 -317
  119. package/lib/observers/net-observer.js +0 -77
  120. package/lib/observers/promise-observer.js +0 -31
  121. package/lib/observers/schedule-observer.js +0 -67
  122. package/lib/observers/stream-observer.js +0 -19
  123. package/lib/observers/thrift-observer.js +0 -197
  124. package/lib/pack/activestack-pack.js +0 -55
  125. package/lib/pack/apenum.js +0 -8
  126. package/lib/pack/errorsnap-pack.js +0 -69
  127. package/lib/pack/event-pack.js +0 -54
  128. package/lib/pack/hitmap-pack.js +0 -63
  129. package/lib/pack/hitmap-pack1.js +0 -152
  130. package/lib/pack/netstat.js +0 -15
  131. package/lib/pack/otype.js +0 -7
  132. package/lib/pack/profile-pack.js +0 -49
  133. package/lib/pack/realtimeuser-pack.js +0 -41
  134. package/lib/pack/stat-general-pack.js +0 -96
  135. package/lib/pack/staterror-pack.js +0 -120
  136. package/lib/pack/stathttpc-pack.js +0 -66
  137. package/lib/pack/stathttpc-rec.js +0 -78
  138. package/lib/pack/statremote-pack.js +0 -46
  139. package/lib/pack/statservice-pack.js +0 -63
  140. package/lib/pack/statservice-pack1.js +0 -88
  141. package/lib/pack/statservice-rec.js +0 -292
  142. package/lib/pack/statservice-rec_dep.js +0 -151
  143. package/lib/pack/statsql-pack.js +0 -69
  144. package/lib/pack/statsql-rec.js +0 -100
  145. package/lib/pack/statuseragent-pack.js +0 -44
  146. package/lib/pack/tagctr.js +0 -15
  147. package/lib/pack/text-pack.js +0 -50
  148. package/lib/pack/time-count.js +0 -25
  149. package/lib/pack/websocket.js +0 -15
  150. package/lib/pack/zip-pack.js +0 -70
  151. package/lib/pii/pii-item.js +0 -31
  152. package/lib/pii/pii-mask.js +0 -174
  153. package/lib/plugin/plugin-loadermanager.js +0 -57
  154. package/lib/plugin/plugin.js +0 -75
  155. package/lib/service/tx-record.js +0 -332
  156. package/lib/stat/stat-error.js +0 -116
  157. package/lib/stat/stat-httpc.js +0 -98
  158. package/lib/stat/stat-remote-ip.js +0 -46
  159. package/lib/stat/stat-remote-ipurl.js +0 -88
  160. package/lib/stat/stat-sql.js +0 -113
  161. package/lib/stat/stat-tranx.js +0 -58
  162. package/lib/stat/stat-tx-caller.js +0 -160
  163. package/lib/stat/stat-tx-domain.js +0 -111
  164. package/lib/stat/stat-tx-referer.js +0 -112
  165. package/lib/stat/stat-useragent.js +0 -48
  166. package/lib/stat/timingsender.js +0 -76
  167. package/lib/step/activestack-step.js +0 -38
  168. package/lib/step/dbc-step.js +0 -36
  169. package/lib/step/http-stepx.js +0 -67
  170. package/lib/step/message-step.js +0 -40
  171. package/lib/step/method-stepx.js +0 -45
  172. package/lib/step/resultset-step.js +0 -40
  173. package/lib/step/securemsg-step.js +0 -44
  174. package/lib/step/socket-step.js +0 -46
  175. package/lib/step/sql-stepx.js +0 -68
  176. package/lib/step/sqlxtype.js +0 -16
  177. package/lib/step/step.js +0 -66
  178. package/lib/step/stepenum.js +0 -54
  179. package/lib/topology/link.js +0 -63
  180. package/lib/topology/nodeinfo.js +0 -123
  181. package/lib/topology/status-detector.js +0 -111
  182. package/lib/util/anylist.js +0 -103
  183. package/lib/util/cardinality/hyperloglog.js +0 -106
  184. package/lib/util/cardinality/murmurhash.js +0 -31
  185. package/lib/util/cardinality/registerset.js +0 -75
  186. package/lib/util/errordata.js +0 -21
  187. package/lib/util/iputil_x.js +0 -527
  188. package/lib/util/kube-util.js +0 -73
  189. package/lib/util/paramsecurity.js +0 -80
  190. package/lib/util/pre-process.js +0 -13
  191. package/lib/util/process-seq.js +0 -166
  192. package/lib/util/property-util.js +0 -36
  193. package/lib/util/request-queue.js +0 -70
  194. package/lib/util/requestdouble-queue.js +0 -72
  195. package/lib/util/resourceprofile.js +0 -157
  196. package/lib/util/stop-watch.js +0 -30
  197. package/lib/util/system-util.js +0 -10
  198. package/lib/util/userid-util.js +0 -57
@@ -1,123 +0,0 @@
1
- const DataOutputX = require('../io/data-outputx');
2
- const DataInputX = require('../io/data-inputx');
3
- const MapValue = require('../value/map-value');
4
- const LINK = require('./link');
5
- const net = require('net');
6
-
7
- function NodeInfo() {
8
- this.attr = new MapValue();
9
- this.listen = new Set();
10
- this.outter = new Set();
11
-
12
- this.addListen = function (localIPs, address) {
13
- const ipo = this.getIPPORT(address);
14
- if (!ipo || this.isLocal127(ipo)) return;
15
-
16
- if (ipo.ip === '*' || ipo.ip === '0.0.0.0' || ipo.ip === '::') {
17
- localIPs.forEach(local_ip => {
18
- const k = LINK.create(local_ip, parseInt(ipo.port, 10));
19
- if (k) this.listen.add(k);
20
- });
21
- } else {
22
- const k = LINK.create(ipo.ip, parseInt(ipo.port, 10));
23
- if (k) this.listen.add(k);
24
- }
25
- };
26
-
27
- this.addOutter = function (local, remote) {
28
- const localIPO = this.getIPPORT(local);
29
- if (!localIPO || this.isIPv6(localIPO)) return;
30
- if (this.hasListen(localIPO.ip, localIPO.port)) return;
31
-
32
- const remoteIPO = this.getIPPORT(remote);
33
- if (!remoteIPO || this.isIPv6(remoteIPO) || this.isLocal127(remoteIPO)) return;
34
-
35
- const k = LINK.create(remoteIPO.ip, parseInt(remoteIPO.port, 10));
36
- if (k) this.outter.add(k);
37
- };
38
-
39
- this.hasListen = function (ip, port) {
40
- const k = LINK.create(ip, parseInt(port, 10));
41
- return this.listen.has(k);
42
- };
43
-
44
- this.getIPPORT = function (address) {
45
- try {
46
- const ipo = {};
47
- const x = address.lastIndexOf(':');
48
- ipo.ip = address.substring(0, x);
49
- ipo.port = address.substring(x + 1);
50
- return ipo;
51
- } catch (e) {
52
- return null;
53
- }
54
- };
55
-
56
- this.toBytes = function () {
57
- const out = new DataOutputX();
58
- out.writeByte(0);
59
- out.writeValue(this.attr);
60
- this.toLinkBytes(this.listen, out);
61
- this.toLinkBytes(this.outter, out);
62
- return out.toByteArray();
63
- };
64
-
65
- this.toObject = function (b) {
66
- const din = new DataInputX(b);
67
- const ver = din.readByte();
68
- this.attr = din.readValue();
69
- this.listen = this.toLinkObject(din);
70
- this.outter = this.toLinkObject(din);
71
- return this;
72
- };
73
-
74
- this.toLinkObject = function (din) {
75
- const data = new Set();
76
- const sz = din.readDecimal();
77
- for (let i = 0; i < sz; i++) {
78
- data.add(new LINK().toObject(din));
79
- }
80
- return data;
81
- };
82
-
83
- this.toLinkBytes = function (data, out) {
84
- out.writeDecimal(data.size);
85
- if (data.size === 0) return;
86
- data.forEach(k => k.toBytes(out));
87
- };
88
-
89
- this.toJSON = function () {
90
- const o = new Map();
91
- o.put('attr', JSON.stringify(this.attr));
92
- o.put('listen', JSON.parse(this.listen));
93
- o.put('outter', JSON.parse(this.outter));
94
- return o;
95
- };
96
-
97
- this.toJSON = function (data) {
98
- const out = new JSONArray();
99
- data.forEach(k => out.put(k.toString()));
100
- return out;
101
- };
102
-
103
- this.isIPv6 = function(data) {
104
- var ip = data.ip;
105
- if(ip){
106
- return net.isIPv6(ip);
107
- }
108
- return false;
109
- };
110
-
111
- this.isLocal127 = function (data) {
112
- var ip = data.ip;
113
- if(ip){
114
- return ip === '127.0.0.1';
115
- }
116
- return false;
117
- }
118
- }
119
-
120
- NodeInfo.prototype = new NodeInfo();
121
- NodeInfo.prototype.constructor = NodeInfo;
122
-
123
- module.exports = NodeInfo;
@@ -1,111 +0,0 @@
1
- var { exec } = require('child_process');
2
- var os = require('os');
3
- var NodeInfo = require('./nodeinfo');
4
- var Logger = require('../logger');
5
-
6
- function StatusDetector() {
7
- this.process = async function () {
8
- let node = new NodeInfo();
9
- let stat = await this.netstat();
10
-
11
- if (!stat) {
12
- node = new NodeInfo();
13
- } else {
14
- try {
15
- node = this.parse(stat);
16
- } catch (e) {
17
- node = new NodeInfo();
18
- Logger.printError("WHATAP-203", "NodeInfo parse error", e, false);
19
- }
20
- }
21
-
22
- node.attr.type = 'nodejs';
23
- node.attr.time = Date.now();
24
- node.attr.ip = this.getLocalIpAddress();
25
- node.attr.pid = process.pid;
26
- node.attr.pname = process.title;
27
-
28
- return node;
29
- };
30
-
31
- this.netstat = function () {
32
- return new Promise((resolve, reject) => {
33
- let cmd = 'netstat -an -t';
34
- if (os.platform() === 'darwin') {
35
- cmd = 'netstat -an -p tcp';
36
- } else if (os.platform() === 'win32') {
37
- resolve('');
38
- return;
39
- }
40
-
41
- exec(cmd, (error, stdout, stderr) => {
42
- if (error) {
43
- reject(error);
44
- return;
45
- }
46
- resolve(stdout);
47
- });
48
- });
49
- };
50
-
51
- this.parse = function (netstat) {
52
- var node = new NodeInfo();
53
- var localIPs = this.getLocalIpSet();
54
-
55
- var lines = netstat.split('\n');
56
- lines.forEach(line => {
57
- if (line.startsWith('tcp')) {
58
- this.parseLine(node, line, localIPs);
59
- }
60
- });
61
-
62
- return node;
63
- };
64
-
65
- this.parseLine = function (node, line, localIPs) {
66
- var tokens = line.trim().split(/\s+/);
67
- if (!tokens[0].startsWith('tcp')) return;
68
-
69
- var localAddress = tokens[3].replace(/(\d+\.\d+\.\d+\.\d+)\.(\d+)/, '$1:$2');
70
- var remoteAddress = tokens[4].replace(/(\d+\.\d+\.\d+\.\d+)\.(\d+)/, '$1:$2');
71
-
72
- if (tokens[5] === 'LISTEN') {
73
- node.addListen(localIPs, localAddress);
74
- } else {
75
- node.addOutter(localAddress, remoteAddress);
76
- }
77
- };
78
-
79
- this.getLocalIpSet = function () {
80
- var ipSet = new Set();
81
- var interfaces = os.networkInterfaces();
82
- for (var devName in interfaces) {
83
- var iface = interfaces[devName];
84
- iface.forEach(alias => {
85
- if (alias.family === 'IPv4' && !alias.internal) {
86
- ipSet.add(alias.address);
87
- }
88
- });
89
- }
90
- return ipSet;
91
- };
92
-
93
- this.getLocalIpAddress = function () {
94
- var interfaces = os.networkInterfaces();
95
- for (var devName in interfaces) {
96
- var iface = interfaces[devName];
97
- for (let i = 0; i < iface.length; i++) {
98
- var alias = iface[i];
99
- if (alias.family === 'IPv4' && !alias.internal) {
100
- return alias.address;
101
- }
102
- }
103
- }
104
- return '0.0.0.0';
105
- };
106
- }
107
-
108
- StatusDetector.prototype = new StatusDetector();
109
- StatusDetector.prototype.constructor = StatusDetector;
110
-
111
- module.exports = StatusDetector;
@@ -1,103 +0,0 @@
1
- var INT = 1;
2
- var LONG = 2;
3
- var FLOAT = 3;
4
- var DOUBLE = 4;
5
- var STRING = 5;
6
-
7
- AnyList.INT = 1;
8
- AnyList.LONG = 2;
9
- AnyList.FLOAT = 3;
10
- AnyList.DOUBLE = 4;
11
- AnyList.STRING = 5;
12
-
13
- function AnyList(type, len){
14
- this.type=type;
15
- this.data = new Array(len);
16
- }
17
- AnyList.prototype.getType=function(){
18
- return this.type;
19
- };
20
- AnyList.prototype.put=function(idx, d){
21
- this.data[idx]=d;
22
- };
23
-
24
- AnyList.prototype.get=function(idx){
25
- return this.data[idx];
26
- };
27
- AnyList.prototype.size = function () {
28
- return this.data ? this.data.length : 0;
29
- };
30
- AnyList.prototype.write=function(o){
31
- switch(this.type){
32
- case INT: this.writeDecimal(o); return this;
33
- case LONG: this.writeDecimal(o); return this;
34
- case FLOAT: this.writeFloat(o); return this;
35
- case DOUBLE: this.writeDouble(o); return this;
36
- case STRING: this.writeString(o); return this;
37
- }
38
- };
39
- AnyList.prototype.read=function(i){
40
- switch(this.type){
41
- case INT: this.readDecimal(i); return this;
42
- case LONG: this.readDecimal(i); return this;
43
- case FLOAT: this.readFloat(i); return this;
44
- case DOUBLE: this.readDouble(i); return this;
45
- case STRING: this.readString(i); return this;
46
- }
47
- };
48
-
49
- AnyList.prototype.writeDouble = function (dout) {
50
- var len =this.size();
51
- dout.writeInt24BE(len);
52
- for (var i = 0; i < len; i++) {
53
- dout.writeDouble(this.get(i));
54
- }
55
- };
56
- AnyList.prototype.readDouble=function(din) {
57
- var count = din.readInt24BE();
58
- for (var i = 0; i < count; i++) {
59
- this.add(din.readDouble());
60
- }
61
- };
62
- AnyList.prototype.writeFloat = function (dout) {
63
- var len =this.size();
64
- dout.writeInt24BE(len);
65
- for (var i = 0; i < len; i++) {
66
- dout.writeFloat(this.get(i));
67
- }
68
- };
69
- AnyList.prototype.readFloat=function(din) {
70
- var count = din.readInt24BE();
71
- for (var i = 0; i < count; i++) {
72
- this.add(din.readFloat());
73
- }
74
- };
75
-
76
- AnyList.prototype.writeDecimal = function (dout) {
77
- var len =this.size();
78
- dout.writeInt24BE(len);
79
- for (var i = 0; i < len; i++) {
80
- dout.writeDecimal(this.get(i));
81
- }
82
- };
83
- AnyList.prototype.readDecimal=function(din) {
84
- var count = din.readInt24BE();
85
- for (var i = 0; i < count; i++) {
86
- this.add(din.readDecNumber());
87
- }
88
- };
89
- AnyList.prototype.writeString = function (dout) {
90
- var len =this.size();
91
- dout.writeInt24BE(len);
92
- for (var i = 0; i < len; i++) {
93
- dout.writeText(this.get(i));
94
- }
95
- };
96
- AnyList.prototype.readString=function(din) {
97
- var count = din.readInt24BE();
98
- for (var i = 0; i < count; i++) {
99
- this.add(din.readText());
100
- }
101
- };
102
-
103
- module.exports = AnyList;
@@ -1,106 +0,0 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- var RegisterSet = require('./registerset'),
8
- MurmurHash = require('./murmurhash'),
9
- DataOutpuxX = require('../../io/data-outputx'),
10
- Long = require('long');
11
-
12
-
13
- function HyperLogLog() {
14
- this.log2m = 10;
15
- this.registerSet = new RegisterSet(1 << this.log2m);
16
- var m = 1 << this.log2m;
17
- this.alphaMM = getAlphaMM(this.log2m, m);
18
- }
19
-
20
- HyperLogLog.prototype.offerHashed = function (hashedValue) {
21
- var j = hashedValue >>> (32 - this.log2m);
22
- var r = numberOfLeadingZeros((hashedValue << this.log2m) | (1 << (this.log2m - 1)) + 1) + 1;
23
- return this.registerSet.updateIfGreater(j, r);
24
- };
25
- HyperLogLog.prototype.offer = function (o) {
26
- var val;
27
- if(o instanceof Long) {
28
- val = o;
29
- } else if(typeof o === 'string') {
30
- val = Long.fromString(o);
31
- } else if(typeof o === 'number') {
32
- val = Long.fromNumber(o);
33
- }
34
- var x = MurmurHash.hashLong(val);
35
- return this.offerHashed(x);
36
- };
37
- HyperLogLog.prototype.cardinality = function () {
38
- var registerSum = 0;
39
- var count = this.registerSet.count;
40
- var zeros = 0.0;
41
- for(var j=0; j<this.registerSet.count; j++) {
42
- var val = this.registerSet.get(j);
43
- registerSum += 1.0 / (1 << val);
44
- if(parseFloat(val) === 0.0) {
45
- zeros++;
46
- }
47
- }
48
- var estimate = this.alphaMM * (1 / registerSum);
49
- if(estimate <= (5.0 / 2.0) * count) {
50
- return Math.round(linearCounting(count, zeros));
51
- } else {
52
- return Math.round(estimate);
53
- }
54
- };
55
- HyperLogLog.prototype.getBytes = function () {
56
- var dout = new DataOutpuxX();
57
- dout.writeInt(this.log2m);
58
- dout.writeInt(this.registerSet.size);
59
- var M = this.registerSet.readOnlyBits();
60
- for(var i=0; i<M.length; i++) {
61
- dout.writeInt(M[i]);
62
- }
63
- return dout.toByteArray();
64
- };
65
-
66
- var getAlphaMM = function (p, m) {
67
- switch (p) {
68
- case 4:
69
- return 0.673 * m * m;
70
- case 5:
71
- return 0.697 * m * m;
72
- case 6:
73
- return 0.709 * m * m;
74
- default:
75
- return (0.7213 / (1 + 1.079 / m)) * m * m;
76
- }
77
- };
78
- var linearCounting = function (m, V) {
79
- return m * Math.log(m / V);
80
- };
81
- var numberOfLeadingZeros = function (i) {
82
- if (i === 0)
83
- return 32;
84
- var n = 1;
85
-
86
- if (i >>> 16 === 0) {
87
- n += 16;
88
- i <<= 16;
89
- }
90
- if (i >>> 24 === 0) {
91
- n += 8;
92
- i <<= 8;
93
- }
94
- if (i >>> 28 === 0) {
95
- n += 4;
96
- i <<= 4;
97
- }
98
- if (i >>> 30 === 0) {
99
- n += 2;
100
- i <<= 2;
101
- }
102
- n -= i >>> 31;
103
- return n;
104
- }
105
-
106
- module.exports = HyperLogLog;
@@ -1,31 +0,0 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- var Long = require('long');
8
-
9
- function hash(data) {
10
- var m = 0x5bd1e995;
11
- var r = 24;
12
- var h = 0;
13
- var k = data.mul(m);
14
- k = k.getLowBits();
15
- k ^= k >>> r;
16
- h ^= Long.fromNumber(k).mul(m).getLowBits();
17
- k = Long.fromNumber(data.getHighBits()).mul(m).getLowBits();
18
- k ^= k >>> r;
19
- h = Long.fromNumber(h).mul(m).getLowBits();
20
- h ^= Long.fromNumber(k).mul(m).getLowBits();
21
- h ^= h >>> 13;
22
- h = Long.fromNumber(h).mul(m).getLowBits();
23
- h ^= h >>> 15;
24
- return h;
25
- };
26
-
27
- var MurMurHash = {
28
- hashLong : hash
29
- };
30
-
31
- module.exports = MurMurHash;
@@ -1,75 +0,0 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- const LOG2_BITS_PER_WORD = 6;
8
- const REGISTER_SIZE = 5;
9
-
10
- var Long = require('long');
11
-
12
- function RegisterSet(count) {
13
- this.count = count;
14
- this.M = new Array(getSizeForCount(this.count));
15
- this.size = this.M.length;
16
- }
17
-
18
- RegisterSet.prototype.set = function (position, value) {
19
- var bucketPos = parseInt(position / LOG2_BITS_PER_WORD);
20
- var shift = REGISTER_SIZE * (position - (bucketPos * LOG2_BITS_PER_WORD));
21
- this.M[bucketPos] = (this.M[bucketPos] & ~(0x1f << shift) | (value << shift));
22
- };
23
- RegisterSet.prototype.get = function (position) {
24
- var bucketPos = parseInt(position / LOG2_BITS_PER_WORD);
25
- var shift = REGISTER_SIZE * (position - (bucketPos * LOG2_BITS_PER_WORD));
26
- return (this.M[bucketPos] & (0x1f << shift)) >>> shift;
27
- };
28
- RegisterSet.prototype.updateIfGreater = function (position, value) {
29
- var bucket = parseInt(position / LOG2_BITS_PER_WORD);
30
- var shift = REGISTER_SIZE * (position - (bucket * LOG2_BITS_PER_WORD));
31
- var mask = 0x1f << shift;
32
-
33
- var curVal = Long.fromNumber(this.M[bucket]).and(mask);
34
- var newVal = Long.fromNumber(value).shiftLeft(shift);
35
-
36
- if(newVal.greaterThan(curVal)) {
37
- var tmp = Long.fromNumber(this.M[bucket]).and(~mask).or(newVal);
38
- this.M[bucket] = tmp.getLowBits();
39
- return true;
40
- } else {
41
- return false;
42
- }
43
- };
44
- RegisterSet.prototype.merge = function (that) {
45
-
46
- for(var bucket = 0; bucket < this.M.length; bucket++) {
47
- var word = 0;
48
- for(var j=0; j<LOG2_BITS_PER_WORD; j++) {
49
- var mask = 0x1f << (REGISTER_SIZE * j);
50
- var thisVal = (this.M[bucket] & mask);
51
- var thatVal = (that.M[bucket] & mask);
52
- word |= (thisVal < thatVal) ? thatVal : thisVal;
53
- }
54
- this.M[bucket] = word;
55
- }
56
- };
57
- RegisterSet.prototype.readOnlyBits = function () {
58
- return this.M;
59
- };
60
-
61
- function getSizeForCount(count) {
62
- var bits = getBits(count);
63
- if(bits === 0) {
64
- return 1;
65
- } else if(bits % 32 === 0) {
66
- return bits;
67
- } else {
68
- return bits + 1;
69
- }
70
- }
71
- function getBits(count) {
72
- return parseInt(count / LOG2_BITS_PER_WORD);
73
- }
74
-
75
- module.exports = RegisterSet;
@@ -1,21 +0,0 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- var Step = require('../step/step');
8
-
9
- function ErrorData(error, dbc, service, profile, isStackTrace) {
10
- this.error = error || {};
11
- this.dbc = dbc || 0;
12
- this.service = service || 0;
13
- this.profile = profile || new Step();
14
- this.isStackTrace = isStackTrace || null;
15
- }
16
-
17
- ErrorData.prototype.toString = function() {
18
- return "LeakData [error=" + this.error + ", dbc=" + this.dbc + ", service=" + this.service + ", profile=" + this.profile + "]";
19
- };
20
-
21
- module.exports = ErrorData;