Skip to content

Add unit test for the new interrupt monitor #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions dynolog/tests/InterruptStatsMonitorTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.

#include "dynolog/src/procfs/parser/InterruptStatsMonitor.h"
#include <gtest/gtest.h>

namespace facebook::dynolog {

namespace {

class MockSystemInfo : public ::testing::Test {};
} // namespace

using namespace ::testing;

class InterruptStatsMonitorTest : public Test {};

/*-- how to check : use this script
* cat dyno/cpp/server/test/root_files/proc/interrupts | \
* awk '{ sum = 0; for(i = 2; i < 32+2; i++) {sum+=$i;}; print $1, sum}'
*/
TEST_F(InterruptStatsMonitorTest, testInterruptsRefresh) {
auto intStats = InterruptStatsMonitor::makeTestClass(std::getenv("TESTROOT"));
intStats.cpuCount_ = 32;
intStats.interruptsRefresh();
// Since implementation relies on integer division by UINT32_MAX
// the exact value is compiler/architecture dependent
EXPECT_NEAR(intStats.stats.tlbshootdowns, 12808065226, 1000000);
EXPECT_NEAR(intStats.stats.tlbshootdownsPrev, 12808065226, 1000000);
EXPECT_NEAR(intStats.stats.eth0Intrps, 13445742397, 1000000);
EXPECT_NEAR(intStats.stats.eth0IntrpsPrev, 13445742397, 1000000);
}

TEST_F(InterruptStatsMonitorTest, testInterruptsRefreshInvalidPath) {
std::string rootPath = std::getenv("TESTROOT");
auto intStats =
InterruptStatsMonitor::makeTestClass(rootPath + "invalid/path");
intStats.cpuCount_ = 32;
intStats.interruptsRefresh();
// expect previous stats
EXPECT_EQ(intStats.stats.tlbshootdowns, 0);
EXPECT_EQ(intStats.stats.tlbshootdownsPrev, 0);
EXPECT_EQ(intStats.stats.eth0Intrps, 0);
EXPECT_EQ(intStats.stats.eth0IntrpsPrev, 0);
}

TEST_F(InterruptStatsMonitorTest, testInterruptsRefreshIncorrectCoreCount) {
auto intStats = InterruptStatsMonitor::makeTestClass(std::getenv("TESTROOT"));
intStats.cpuCount_ = 16; // incorrect #cores
intStats.interruptsRefresh();
EXPECT_EQ(intStats.stats.tlbshootdowns, 0);
EXPECT_EQ(intStats.stats.tlbshootdownsPrev, 0);
EXPECT_EQ(intStats.stats.eth0Intrps, 0);
EXPECT_EQ(intStats.stats.eth0IntrpsPrev, 0);

auto intStats1 =
InterruptStatsMonitor::makeTestClass(std::getenv("TESTROOT"));
intStats1.cpuCount_ = 32; // correct #cores
intStats1.interruptsRefresh();
EXPECT_NEAR(intStats1.stats.tlbshootdowns, 12808065226, 1000000);
EXPECT_NEAR(intStats1.stats.tlbshootdownsPrev, 12808065226, 1000000);
EXPECT_NEAR(intStats1.stats.eth0Intrps, 13445742397, 1000000);
EXPECT_NEAR(intStats1.stats.eth0IntrpsPrev, 13445742397, 1000000);
}

} // namespace facebook::dynolog
37 changes: 37 additions & 0 deletions testing/root/proc/interrupts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CPU0 CPU1 CPU2 CPU3 CPU4 CPU5 CPU6 CPU7 CPU8 CPU9 CPU10 CPU11 CPU12 CPU13 CPU14 CPU15 CPU16 CPU17 CPU18 CPU19 CPU20 CPU21 CPU22 CPU23 CPU24 CPU25 CPU26 CPU27 CPU28 CPU29 CPU30 CPU31
0: 201 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IO-APIC-edge timer
1: 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IO-APIC-edge i8042
8: 5617 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IO-APIC-edge rtc0
9: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IO-APIC-fasteoi acpi
12: 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IO-APIC-edge i8042
16: 288664536 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IO-APIC 16-fasteoi ipmi_si
17: 1741 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IO-APIC 17-fasteoi serial
23: 34 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IO-APIC 23-fasteoi ehci_hcd:usb1
28: 729519748 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge 0000:00:1f.2
30: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge mlx4-comp-0@pci:0000:06:00.0
31: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge mlx4-comp-1@pci:0000:06:00.0
32: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge mlx4-comp-2@pci:0000:06:00.0
33: 56479445 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge mlx4-async@pci:0000:06:00.0
34: 2129866239 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge eth0-0
35: 1 61 0 0 0 0 0 0 2264115365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge eth0-1
36: 1 2080200691 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge eth0-2
37: 1 0 0 1 0 0 0 0 0 2080831446 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge eth0-3
38: 1 0 1244288731 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge eth0-4
39: 1 0 0 0 0 17 0 0 0 0 1178274977 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge eth0-5
40: 1 0 0 1394491880 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge eth0-6
41: 1 0 0 0 0 0 0 13 0 0 0 1073672951 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI-edge eth0-7
NMI: 217356 168114 144090 155055 125662 117430 115048 112419 196545 160570 140296 137756 122009 116191 115118 114963 37812 33941 32844 32796 31522 28155 29784 27318 34621 31858 32653 31718 30769 27522 29374 28264 Non-maskable interrupts
LOC: 146912789 3993750150 3835262546 3791001977 3563293272 3527140978 3505383550 3460901644 3574090835 3447215757 3365737349 3343238328 3112387376 3079957300 3068392569 3087712484 742868484 765730473 758282352 739941385 738075872 717970341 705049691 695210870 696693907 706352978 709739661 704759714 702510511 682336521 675081476 668673849 Local timer interrupts
SPU: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Spurious interrupts
PMI: 217356 168114 144090 155055 125662 117430 115048 112419 196545 160570 140296 137756 122009 116191 115118 114963 37812 33941 32844 32796 31522 28155 29784 27318 34621 31858 32653 31718 30769 27522 29374 28264 Performance monitoring interrupts
IWI: 16193709 16464238 16348462 16240111 8310541 8385521 8448314 8495983 15476708 15452138 15405463 15374827 7430408 7496342 7525540 7543416 1835163 2217840 2134883 2009595 1949743 1863342 1836228 1797742 1821810 1993386 1930760 1867965 1813360 1790408 1773372 1770652 IRQ work interrupts
RTR: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 APIC ICR read retries
RES: 1297455101 506792535 251011237 155816063 109855659 85230072 70920049 65461339 161588795 121238680 105248090 95362192 79646668 68570156 61490020 56566085 31354745 18510707 15683521 14900294 11323352 10615272 10057105 9973688 14485498 13808630 13687679 12876739 10839824 10045491 10296354 10126999 Rescheduling interrupts
CAL: 319283609 88325709 88363731 89601298 89679041 89376926 88369491 88137911 377950958 147660280 149853220 150921332 152852645 153014466 152272383 152018728 18052976 19363332 19993515 21143975 21120380 21346851 21814372 21780744 25082400 26098250 26655762 27086704 27411604 27326301 27669472 30360671 Function call interrupts
TLB: 853470049 861897804 864085223 853196320 811075650 799315940 787731074 776678131 485272490 491738182 496183357 486866130 449580688 441381812 436545197 431674844 219579497 204066417 192770730 181963085 178865879 173906256 170455083 166949026 144451989 134390759 127372726 123197746 119387260 116816217 114326752 112872913 TLB shootdowns
TRM: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Thermal event interrupts
THR: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Threshold APIC interrupts
MCE: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Machine check exceptions
MCP: 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 44894 Machine check polls
ERR: 0
MIS: 0