Skip to content

Commit f4c495f

Browse files
rtimmonsevergreen
authored andcommitted
SERVER-43254 Hang Analyzer shell integration uses child and peer mongo processes
1 parent a6e3d84 commit f4c495f

File tree

6 files changed

+95
-24
lines changed

6 files changed

+95
-24
lines changed

buildscripts/hang_analyzer.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,12 @@ def callo(args, logger):
6565

6666
def find_program(prog, paths):
6767
"""Find the specified program in env PATH, or tries a set of paths."""
68-
loc = spawn.find_executable(prog)
69-
70-
if loc is not None:
71-
return loc
72-
7368
for loc in paths:
7469
full_prog = os.path.join(loc, prog)
7570
if os.path.exists(full_prog):
7671
return full_prog
7772

78-
return None
73+
return spawn.find_executable(prog)
7974

8075

8176
def get_process_logger(debugger_output, pid, process_name):

buildscripts/resmokeconfig/suites/unittest_peer_pids.yml renamed to buildscripts/resmokeconfig/suites/unittest_shell_hang_analyzer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ test_kind: js_test
22

33
selector:
44
roots:
5-
- jstests/resmoke_selftest/peer_pids.js
5+
- jstests/resmoke_selftest/shell_hang_analyzer.js
66

77
executor:
88
fixture:

etc/evergreen.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6794,12 +6794,12 @@ tasks:
67946794
task_path_suffix: /data/multiversion
67956795
resmoke_args: --suites=multiversion --storageEngine=wiredTiger
67966796

6797-
- name: unittest_peer_pids_gen
6797+
- name: unittest_shell_hang_analyzer_gen
67986798
tags: ["misc_js"]
67996799
commands:
68006800
- func: "generate resmoke tasks"
68016801
vars:
6802-
suite: unittest_peer_pids
6802+
suite: unittest_shell_hang_analyzer
68036803
resmoke_args: --storageEngine=wiredTiger
68046804
fallback_num_sub_suites: 1
68056805

@@ -9731,7 +9731,7 @@ buildvariants:
97319731
- windows-64-vs2017-compile
97329732
- name: burn_in_tests_gen
97339733
- name: buildscripts_test
9734-
- name: unittest_peer_pids_gen
9734+
- name: unittest_shell_hang_analyzer_gen
97359735
- name: dbtest_TG
97369736
distros:
97379737
- windows-64-vs2017-compile
@@ -10694,7 +10694,7 @@ buildvariants:
1069410694
distros:
1069510695
- centos6-perf
1069610696
- name: buildscripts_test
10697-
- name: unittest_peer_pids_gen
10697+
- name: unittest_shell_hang_analyzer_gen
1069810698
- name: .causally_consistent !.sharding
1069910699
- name: .change_streams
1070010700
- name: .misc_js

jstests/resmoke_selftest/peer_pids.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
(function() {
4+
5+
/*
6+
* This tests that calling runHangAnalyzer() actually runs the hang analyzer.
7+
*/
8+
9+
const child = MongoRunner.runMongod();
10+
try {
11+
MongoRunner.runHangAnalyzer([child.pid]);
12+
13+
const anyLineMatches = function(lines, rex) {
14+
for (const line of lines) {
15+
if (line.match(rex)) {
16+
return true;
17+
}
18+
}
19+
return false;
20+
};
21+
22+
assert.soon(() => {
23+
const lines = rawMongoProgramOutput().split('\n');
24+
return anyLineMatches(lines, /Dumping core/);
25+
});
26+
} finally {
27+
MongoRunner.stopMongod(child);
28+
}
29+
})();
30+
31+
(function() {
32+
33+
/*
34+
* This tests the resmoke functionality of passing peer pids to TestData.
35+
*/
36+
37+
assert(typeof TestData.peerPids !== 'undefined');
38+
39+
// ShardedClusterFixture 2 shards with 3 rs members per shard, 2 mongos's => 7 peers
40+
assert.eq(7, TestData.peerPids.length);
41+
})();

src/mongo/shell/servers.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,54 @@ MongoRunner.VersionSub = function(pattern, version) {
8484
this.version = version;
8585
};
8686

87+
(function() {
88+
// Hang Analyzer integration.
89+
90+
function getPids() {
91+
let pids = [];
92+
if (typeof TestData !== 'undefined' && typeof TestData.peerPids !== 'undefined') {
93+
pids = pids.concat(TestData.peerPids);
94+
}
95+
pids = pids.concat(MongoRunner.runningChildPids());
96+
return pids;
97+
}
98+
99+
// A path.join-like thing for paths that must work
100+
// on Windows (\-separated) and *nix (/-separated).
101+
function pathJoin(...parts) {
102+
const separator = _isWindows() ? '\\' : '/';
103+
return parts.join(separator);
104+
}
105+
106+
/**
107+
* Run `./buildscripts/hang_analyzer.py`.
108+
*
109+
* @param {Number[]} pids
110+
* optional pids of processes to pass to hang_analyzer.py.
111+
* If not specified will use `TestData.peerPids` (pids of
112+
* "fixture" processes started and passed in by resmoke)
113+
* plus `MongoRunner.runningChildPids()` which includes all
114+
* child processes started by `MongoRunner.runMongo*()` etc.
115+
*/
116+
function runHangAnalyzer(pids) {
117+
if (typeof pids === 'undefined') {
118+
pids = getPids();
119+
}
120+
if (pids.length <= 0) {
121+
print("Skipping runHangAnalyzer: no running child or peer mongo processes.");
122+
return;
123+
}
124+
// Result of runningChildPids may be NumberLong(), so
125+
// add 0 to convert to Number.
126+
pids = pids.map(p => p + 0).join(',');
127+
print(`Running hang_analyzer.py for pids [${pids}]`);
128+
const scriptPath = pathJoin('.', 'buildscripts', 'hang_analyzer.py');
129+
runProgram('python', scriptPath, '-c', '-d', pids);
130+
}
131+
132+
MongoRunner.runHangAnalyzer = runHangAnalyzer;
133+
})();
134+
87135
/**
88136
* Returns an array of version elements from a version string.
89137
*

0 commit comments

Comments
 (0)