Repository: mesos Updated Branches: refs/heads/master 46f80f270 -> 9b14ba2e4
Fix PerfTest.ROOT_SampleInit to sample a process known to consume cpu. Review: https://reviews.apache.org/r/32420/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9b14ba2e Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9b14ba2e Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9b14ba2e Branch: refs/heads/master Commit: 9b14ba2e4aff6b41789fcda75411a4ed60ae7e12 Parents: 46f80f2 Author: Ian Downes <[email protected]> Authored: Mon Mar 23 17:14:52 2015 -0700 Committer: Ian Downes <[email protected]> Committed: Tue Mar 24 15:04:50 2015 -0700 ---------------------------------------------------------------------- src/tests/perf_tests.cpp | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/9b14ba2e/src/tests/perf_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/perf_tests.cpp b/src/tests/perf_tests.cpp index 16f3226..281eed0 100644 --- a/src/tests/perf_tests.cpp +++ b/src/tests/perf_tests.cpp @@ -16,12 +16,15 @@ * limitations under the License. */ +#include <sys/prctl.h> + #include <set> #include <gmock/gmock.h> #include <process/clock.hpp> #include <process/gtest.hpp> +#include <process/reap.hpp> #include <stout/gtest.hpp> #include <stout/stringify.hpp> @@ -122,26 +125,47 @@ TEST_F(PerfTest, Parse) } -TEST_F(PerfTest, ROOT_SampleInit) +TEST_F(PerfTest, ROOT_SamplePid) { + // TODO(idownes): Replace this with a Subprocess when it supports + // DEATHSIG. + // Fork a child which we'll run perf against. + pid_t pid = fork(); + ASSERT_GE(pid, 0); + + if (pid == 0) { + // Kill ourself if the parent dies to prevent leaking the child. + prctl(PR_SET_PDEATHSIG, SIGKILL); + + // Spin child to consume cpu cycles. + while (true); + } + + // Continue in parent. set<string> events; // Hardware event. events.insert("cycles"); // Software event. events.insert("task-clock"); - // Sample init/launchd/systemd (pid 1). + // Sample the child. + Duration duration = Milliseconds(100); Future<mesos::PerfStatistics> statistics = - perf::sample(events, 1, Seconds(1)); + perf::sample(events, pid, duration); AWAIT_READY(statistics); + // Kill the child and reap it. + Future<Option<int>> status = reap(pid); + kill(pid, SIGKILL); + AWAIT_READY(status); + // Check the sample timestamp is within the last 5 seconds. This is generous // because there's the process reap delay in addition to the sampling // duration. ASSERT_TRUE(statistics.get().has_timestamp()); EXPECT_GT( Seconds(5).secs(), Clock::now().secs() - statistics.get().timestamp()); - EXPECT_EQ(Seconds(1).secs(), statistics.get().duration()); + EXPECT_EQ(duration.secs(), statistics.get().duration()); ASSERT_TRUE(statistics.get().has_cycles()); EXPECT_LT(0u, statistics.get().cycles());
