diff --git a/cmake/Agent.cmake b/cmake/Agent.cmake index 57af63c0e5c7a..ab86ef6592bcb 100644 --- a/cmake/Agent.cmake +++ b/cmake/Agent.cmake @@ -293,6 +293,7 @@ set(core_libs l2learn_event_observer agent_fsdb_sync_manager fboss_event_base + phy_snapshot_manager ) target_link_libraries(core ${core_libs}) diff --git a/cmake/LibPhy.cmake b/cmake/LibPhy.cmake index b1eac19b7e61b..ae0fd52075271 100644 --- a/cmake/LibPhy.cmake +++ b/cmake/LibPhy.cmake @@ -26,6 +26,7 @@ target_link_libraries(phy_management_base Folly::folly io_stats_cpp2 fb303::fb303 + phy_snapshot_manager ) add_library(phy_utils diff --git a/cmake/LibPhySnapshotManager.cmake b/cmake/LibPhySnapshotManager.cmake new file mode 100644 index 0000000000000..44f17b6fef970 --- /dev/null +++ b/cmake/LibPhySnapshotManager.cmake @@ -0,0 +1,14 @@ +# CMake to build libraries and binaries from fboss/agent/PhySnapshotManager + +# In general, libraries and binaries in fboss/foo/bar are built by +# cmake/FooBar.cmake + +add_library(phy_snapshot_manager + fboss/agent/PhySnapshotManager.cpp +) + +target_link_libraries(phy_snapshot_manager + phy_cpp2 + snapshot_manager + state +) diff --git a/fboss/agent/BUCK b/fboss/agent/BUCK index 389a2e0d04885..0e4c514db8f75 100644 --- a/fboss/agent/BUCK +++ b/fboss/agent/BUCK @@ -596,9 +596,9 @@ cpp_library( cpp_library( name = "phy_snapshot_lib", + srcs = ["PhySnapshotManager.cpp"], headers = [ "PhySnapshotManager.h", - "PhySnapshotManager-defs.h", ], exported_deps = [ "//fboss/agent/state:state", @@ -788,7 +788,6 @@ cpp_library( "//fboss/lib:radix_tree", "//fboss/lib:thread_heartbeat", "//fboss/lib/config:fboss_config_utils", - "//fboss/lib/link_snapshots:snapshot_manager", "//fboss/lib/phy:phy-cpp2-types", "//fboss/lib/phy:prbs-cpp2-types", "//fboss/lib/platforms:product-info", diff --git a/fboss/agent/PhySnapshotManager-defs.h b/fboss/agent/PhySnapshotManager.cpp similarity index 70% rename from fboss/agent/PhySnapshotManager-defs.h rename to fboss/agent/PhySnapshotManager.cpp index 1ee9de7ae79f4..1d0b33d944051 100644 --- a/fboss/agent/PhySnapshotManager-defs.h +++ b/fboss/agent/PhySnapshotManager.cpp @@ -1,14 +1,10 @@ // (c) Facebook, Inc. and its affiliates. Confidential and proprietary. -#pragma once - #include "fboss/agent/PhySnapshotManager.h" -#include "fboss/agent/state/Port.h" namespace facebook::fboss { -template -void PhySnapshotManager::updatePhyInfoLocked( +void PhySnapshotManager::updatePhyInfoLocked( const SnapshotMapWLockedPtr& lockedSnapshotMap, PortID portID, const phy::PhyInfo& phyInfo) { @@ -18,22 +14,22 @@ void PhySnapshotManager::updatePhyInfoLocked( CHECK(!phyInfo.state()->get_name().empty()); auto result = lockedSnapshotMap->try_emplace( - portID, std::set({phyInfo.state()->get_name()})); + portID, + std::set({phyInfo.state()->get_name()}), + intervalSeconds_); auto iter = result.first; auto& value = iter->second; value.addSnapshot(snapshot); } -template -void PhySnapshotManager::updatePhyInfo( +void PhySnapshotManager::updatePhyInfo( PortID portID, const phy::PhyInfo& phyInfo) { auto lockedSnapshotMap = snapshots_.wlock(); updatePhyInfoLocked(lockedSnapshotMap, portID, phyInfo); } -template -void PhySnapshotManager::updatePhyInfos( +void PhySnapshotManager::updatePhyInfos( const std::map& phyInfos) { auto lockedSnapshotMap = snapshots_.wlock(); for (const auto& [portID, phyInfo] : phyInfos) { @@ -41,9 +37,7 @@ void PhySnapshotManager::updatePhyInfos( } } -template -std::optional -PhySnapshotManager::getPhyInfoLocked( +std::optional PhySnapshotManager::getPhyInfoLocked( const SnapshotMapRLockedPtr& lockedSnapshotMap, PortID portID) const { std::optional phyInfo; @@ -59,16 +53,13 @@ PhySnapshotManager::getPhyInfoLocked( return phyInfo; } -template -std::optional PhySnapshotManager::getPhyInfo( +std::optional PhySnapshotManager::getPhyInfo( PortID portID) const { const auto& lockedSnapshotMap = snapshots_.rlock(); return getPhyInfoLocked(lockedSnapshotMap, portID); } -template -std::map -PhySnapshotManager::getPhyInfos( +std::map PhySnapshotManager::getPhyInfos( const std::vector& portIDs) const { std::map infoMap; auto lockedSnapshotMap = snapshots_.rlock(); @@ -81,9 +72,8 @@ PhySnapshotManager::getPhyInfos( return infoMap; } -template -std::map -PhySnapshotManager::getAllPhyInfos() const { +std::map PhySnapshotManager::getAllPhyInfos() + const { std::map infoMap; auto lockedSnapshotMap = snapshots_.rlock(); for (auto it = lockedSnapshotMap->begin(); it != lockedSnapshotMap->end(); @@ -96,8 +86,7 @@ PhySnapshotManager::getAllPhyInfos() const { return infoMap; } -template -void PhySnapshotManager::publishSnapshots(PortID port) { +void PhySnapshotManager::publishSnapshots(PortID port) { auto lockedSnapshotMap = snapshots_.wlock(); if (auto it = lockedSnapshotMap->find(port); it != lockedSnapshotMap->end()) { it->second.publishAllSnapshots(); diff --git a/fboss/agent/PhySnapshotManager.h b/fboss/agent/PhySnapshotManager.h index f383540bc60aa..c346b105940ac 100644 --- a/fboss/agent/PhySnapshotManager.h +++ b/fboss/agent/PhySnapshotManager.h @@ -3,21 +3,20 @@ #pragma once #include "fboss/agent/state/Port.h" -#include "fboss/lib/link_snapshots/SnapshotManager-defs.h" +#include "fboss/lib/link_snapshots/SnapshotManager.h" #include "fboss/lib/phy/gen-cpp2/phy_types.h" namespace facebook::fboss { -// intervalSeconds is the interval between Phy stat collections -template class PhySnapshotManager { - using PhySnapshotCache = SnapshotManager; using SnapshotMapRLockedPtr = typename folly::Synchronized< - std::map>::ConstRLockedPtr; + std::map>::ConstRLockedPtr; using SnapshotMapWLockedPtr = typename folly::Synchronized< - std::map>::WLockedPtr; + std::map>::WLockedPtr; public: + explicit PhySnapshotManager(size_t intervalSeconds) + : intervalSeconds_(intervalSeconds) {} void updatePhyInfo(PortID portID, const phy::PhyInfo& phyInfo); void updatePhyInfos(const std::map& phyInfo); std::optional getPhyInfo(PortID portID) const; @@ -36,7 +35,8 @@ class PhySnapshotManager { PortID portID) const; // Map of portID to last few phy diagnostic snapshots - folly::Synchronized> snapshots_; + folly::Synchronized> snapshots_; + size_t intervalSeconds_; }; } // namespace facebook::fboss diff --git a/fboss/agent/SwAgentInitializer.cpp b/fboss/agent/SwAgentInitializer.cpp index ffb0afbd598d2..7d222a283ebf5 100644 --- a/fboss/agent/SwAgentInitializer.cpp +++ b/fboss/agent/SwAgentInitializer.cpp @@ -115,7 +115,7 @@ void SwSwitchInitializer::initThread( void SwSwitchInitializer::init( HwSwitchCallback* hwSwitchCallback, const HwWriteBehavior& hwWriteBehavior) { - auto startTime = steady_clock::now(); + auto startTime = std::chrono::steady_clock::now(); std::lock_guard g(initLock_); initImpl(hwSwitchCallback, hwWriteBehavior); sw_->applyConfig("apply initial config"); diff --git a/fboss/agent/SwSwitch.cpp b/fboss/agent/SwSwitch.cpp index 4dd3bc56e865c..0d5dd187ca602 100644 --- a/fboss/agent/SwSwitch.cpp +++ b/fboss/agent/SwSwitch.cpp @@ -53,7 +53,7 @@ #include "fboss/agent/NeighborUpdater.h" #include "fboss/agent/PacketLogger.h" #include "fboss/agent/PacketObserver.h" -#include "fboss/agent/PhySnapshotManager-defs.h" +#include "fboss/agent/PhySnapshotManager.h" #include "fboss/agent/PortStats.h" #include "fboss/agent/PortUpdateHandler.h" #include "fboss/agent/ResolvedNexthopMonitor.h" @@ -387,8 +387,7 @@ SwSwitch::SwSwitch( lookupClassRouteUpdater_(new LookupClassRouteUpdater(this)), staticL2ForNeighborObserver_(new StaticL2ForNeighborObserver(this)), macTableManager_(new MacTableManager(this)), - phySnapshotManager_( - new PhySnapshotManager()), + phySnapshotManager_(new PhySnapshotManager(kIphySnapshotIntervalSeconds)), aclNexthopHandler_(new AclNexthopHandler(this)), teFlowNextHopHandler_(new TeFlowNexthopHandler(this)), dsfSubscriber_(new DsfSubscriber(this)), diff --git a/fboss/agent/SwSwitch.h b/fboss/agent/SwSwitch.h index 3e1420777686a..11a6aebf591fa 100644 --- a/fboss/agent/SwSwitch.h +++ b/fboss/agent/SwSwitch.h @@ -30,7 +30,6 @@ #include "fboss/agent/types.h" #include "fboss/lib/HwWriteBehavior.h" #include "fboss/lib/ThreadHeartbeat.h" -#include "fboss/lib/link_snapshots/SnapshotManager-defs.h" #include "fboss/lib/phy/gen-cpp2/phy_types.h" #include @@ -75,7 +74,6 @@ class RouteUpdateLogger; class StateObserver; class TunManager; class MirrorManager; -template class PhySnapshotManager; class AclNexthopHandler; class LookupClassUpdater; @@ -1224,8 +1222,7 @@ class SwSwitch : public HwSwitchCallback { static constexpr auto kIphySnapshotIntervalSeconds = 1; - std::unique_ptr> - phySnapshotManager_; + std::unique_ptr phySnapshotManager_; std::unique_ptr aclNexthopHandler_; folly::Synchronized> fsdbSyncer_; std::unique_ptr teFlowNextHopHandler_; diff --git a/fboss/agent/mnpu/SplitSwAgentInitializer.cpp b/fboss/agent/mnpu/SplitSwAgentInitializer.cpp index b1f975461c4fe..d233796c751fe 100644 --- a/fboss/agent/mnpu/SplitSwAgentInitializer.cpp +++ b/fboss/agent/mnpu/SplitSwAgentInitializer.cpp @@ -14,6 +14,8 @@ #endif #endif +using namespace std::chrono; + namespace facebook::fboss { void SplitSwSwitchInitializer::initImpl( diff --git a/fboss/agent/test/MKAServiceManagerTest.cpp b/fboss/agent/test/MKAServiceManagerTest.cpp index fd90bbe5b5c80..ab055f8801b44 100644 --- a/fboss/agent/test/MKAServiceManagerTest.cpp +++ b/fboss/agent/test/MKAServiceManagerTest.cpp @@ -26,6 +26,7 @@ using ::testing::_; using ::testing::AtLeast; using namespace facebook::fboss; +using namespace std::chrono; namespace { #if FOLLY_HAS_COROUTINES diff --git a/fboss/agent/test/MultiNodeLacpTests.cpp b/fboss/agent/test/MultiNodeLacpTests.cpp index a7015099b6537..33ef76694195b 100644 --- a/fboss/agent/test/MultiNodeLacpTests.cpp +++ b/fboss/agent/test/MultiNodeLacpTests.cpp @@ -36,6 +36,7 @@ #include "folly/MacAddress.h" using namespace facebook::fboss; +using namespace std::chrono; DECLARE_bool(enable_lacp); diff --git a/fboss/agent/test/MultiNodeMacsecTests.cpp b/fboss/agent/test/MultiNodeMacsecTests.cpp index 3c6f2b2598c27..9844add31bb37 100644 --- a/fboss/agent/test/MultiNodeMacsecTests.cpp +++ b/fboss/agent/test/MultiNodeMacsecTests.cpp @@ -21,6 +21,7 @@ #include "fboss/mka_service/if/facebook/gen-cpp2/mka_config_types.h" using namespace facebook::fboss; +using namespace std::chrono; using mka::Cak; using mka::MACSecCapability; diff --git a/fboss/agent/test/MultiNodeOpenrTests.cpp b/fboss/agent/test/MultiNodeOpenrTests.cpp index fe7b4a7681de4..98a5201a5a2ff 100644 --- a/fboss/agent/test/MultiNodeOpenrTests.cpp +++ b/fboss/agent/test/MultiNodeOpenrTests.cpp @@ -28,6 +28,7 @@ #include "fboss/agent/RouteUpdateWrapper.h" using namespace facebook::fboss; +using namespace std::chrono; static constexpr int kOpenrThriftPort{2018}; diff --git a/fboss/agent/test/agent_hw_tests/AgentPacketSendTests.cpp b/fboss/agent/test/agent_hw_tests/AgentPacketSendTests.cpp index 97328204fd304..ce1a336e2bfc4 100644 --- a/fboss/agent/test/agent_hw_tests/AgentPacketSendTests.cpp +++ b/fboss/agent/test/agent_hw_tests/AgentPacketSendTests.cpp @@ -13,6 +13,8 @@ #include +using namespace std::chrono; + namespace { constexpr int kAggId{500}; } // unnamed namespace diff --git a/fboss/agent/test/integration_tests/AgentBgpIntegrationTests.cpp b/fboss/agent/test/integration_tests/AgentBgpIntegrationTests.cpp index 06b6b441dec66..04d79d2a3a637 100644 --- a/fboss/agent/test/integration_tests/AgentBgpIntegrationTests.cpp +++ b/fboss/agent/test/integration_tests/AgentBgpIntegrationTests.cpp @@ -40,6 +40,7 @@ auto constexpr kTestPrefixLength = 120; using namespace facebook::neteng::fboss::bgp::thrift; using namespace facebook::neteng::fboss::bgp_attr; +using namespace std::chrono; using StateUpdateFn = facebook::fboss::SwSwitch::StateUpdateFn; diff --git a/fboss/agent/test/integration_tests/TeAgentIntegrationTests.cpp b/fboss/agent/test/integration_tests/TeAgentIntegrationTests.cpp index 0280e9eef9df5..758222645e773 100644 --- a/fboss/agent/test/integration_tests/TeAgentIntegrationTests.cpp +++ b/fboss/agent/test/integration_tests/TeAgentIntegrationTests.cpp @@ -41,6 +41,7 @@ static int kTeFlowEntries(9000); } // namespace using namespace facebook::neteng::ai; +using namespace std::chrono; using StateUpdateFn = facebook::fboss::SwSwitch::StateUpdateFn; diff --git a/fboss/agent/test/soak_tests/SoakTest.cpp b/fboss/agent/test/soak_tests/SoakTest.cpp index a3baeed245bcd..dee3fdf9cf4a1 100644 --- a/fboss/agent/test/soak_tests/SoakTest.cpp +++ b/fboss/agent/test/soak_tests/SoakTest.cpp @@ -11,6 +11,8 @@ DEFINE_string( "1s", "Total time to run soak test, <\\d+>[smhd], s-sec, m-min, h-hour, d-day"); +using namespace std::chrono; + namespace facebook::fboss { uint64_t SoakTest::SoakTimeStrToSeconds(std::string timeStr) { diff --git a/fboss/lib/link_snapshots/BUCK b/fboss/lib/link_snapshots/BUCK index a4aa1306fbe7d..32e3e0d356059 100644 --- a/fboss/lib/link_snapshots/BUCK +++ b/fboss/lib/link_snapshots/BUCK @@ -22,7 +22,6 @@ cpp_library( ], headers = [ "SnapshotManager.h", - "SnapshotManager-defs.h", ], exported_deps = [ ":ring_buffer", diff --git a/fboss/lib/link_snapshots/RingBuffer-defs.h b/fboss/lib/link_snapshots/RingBuffer-defs.h index 5b3f1d88f0f24..45c56863c1924 100644 --- a/fboss/lib/link_snapshots/RingBuffer-defs.h +++ b/fboss/lib/link_snapshots/RingBuffer-defs.h @@ -14,57 +14,55 @@ namespace facebook::fboss { -template -void RingBuffer::write(T val) { - if (buf.size() == length) { +template +void RingBuffer::write(T val) { + if (buf.size() == maxLength_) { buf.pop_front(); } buf.push_back(val); } -template -const T RingBuffer::last() const { +template +const T RingBuffer::last() const { if (buf.empty()) { throw FbossError("Attempted to read from empty RingBuffer"); } return buf.back(); } -template -bool RingBuffer::empty() const { +template +bool RingBuffer::empty() const { return buf.empty(); } -template -typename RingBuffer::iterator RingBuffer::begin() { +template +typename RingBuffer::iterator RingBuffer::begin() { return buf.begin(); } -template -typename RingBuffer::iterator RingBuffer::end() { +template +typename RingBuffer::iterator RingBuffer::end() { return buf.end(); } -template -typename RingBuffer::const_iterator RingBuffer::begin() - const { +template +typename RingBuffer::const_iterator RingBuffer::begin() const { return buf.begin(); } -template -typename RingBuffer::const_iterator RingBuffer::end() - const { +template +typename RingBuffer::const_iterator RingBuffer::end() const { return buf.end(); } -template -size_t RingBuffer::size() const { +template +size_t RingBuffer::size() const { return buf.size(); } -template -size_t RingBuffer::maxSize() const { - return length; +template +size_t RingBuffer::maxSize() const { + return maxLength_; } } // namespace facebook::fboss diff --git a/fboss/lib/link_snapshots/RingBuffer.h b/fboss/lib/link_snapshots/RingBuffer.h index 3db725fd54c66..4d600c3ea3751 100644 --- a/fboss/lib/link_snapshots/RingBuffer.h +++ b/fboss/lib/link_snapshots/RingBuffer.h @@ -13,12 +13,14 @@ #include namespace facebook::fboss { -template +template class RingBuffer { public: using iterator = typename std::list::iterator; using const_iterator = typename std::list::const_iterator; + explicit RingBuffer(size_t maxLength) : maxLength_(maxLength) {} + void write(T val); const T last() const; bool empty() const; @@ -31,6 +33,7 @@ class RingBuffer { private: std::list buf; + size_t maxLength_; }; } // namespace facebook::fboss diff --git a/fboss/lib/link_snapshots/SnapshotManager-defs.h b/fboss/lib/link_snapshots/SnapshotManager-defs.h deleted file mode 100644 index 284b373e1c500..0000000000000 --- a/fboss/lib/link_snapshots/SnapshotManager-defs.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2004-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - */ -#pragma once - -#include "fboss/lib/link_snapshots/SnapshotManager.h" - -namespace facebook::fboss { - -using namespace std::chrono; - -template -SnapshotManager::SnapshotManager( - std::set portNames) - : portNames_(portNames) {} - -template -void SnapshotManager::addSnapshot( - phy::LinkSnapshot val) { - auto snapshot = SnapshotWrapper(val); - buf_.write(snapshot); - - if (numSnapshotsToPublish_ > 0) { - snapshot.publish(portNames_); - } - if (numSnapshotsToPublish_ > 0) { - numSnapshotsToPublish_--; - } -} - -template -const RingBuffer< - SnapshotWrapper, - SnapshotManager::length>& -SnapshotManager::getSnapshots() const { - return buf_; -} - -template -void SnapshotManager::publishAllSnapshots() { - for (auto& snapshot : buf_) { - snapshot.publish(portNames_); - } -} - -template -void SnapshotManager::publishFutureSnapshots( - int numToPublish) { - numSnapshotsToPublish_ = numToPublish; -} -} // namespace facebook::fboss diff --git a/fboss/lib/link_snapshots/SnapshotManager.cpp b/fboss/lib/link_snapshots/SnapshotManager.cpp index af9028c0ff01f..c819b5b582f87 100644 --- a/fboss/lib/link_snapshots/SnapshotManager.cpp +++ b/fboss/lib/link_snapshots/SnapshotManager.cpp @@ -28,6 +28,43 @@ constexpr auto kMaxLogLineLength = 12000; } // namespace namespace facebook::fboss { +SnapshotManager::SnapshotManager( + const std::set& portNames, + size_t intervalSeconds, + size_t timespanSeconds) + // Round up the number of snapshots stored (always store at least 1) + : buf_(timespanSeconds / intervalSeconds + 1), portNames_(portNames) {} + +SnapshotManager::SnapshotManager( + const std::set& portNames, + size_t intervalSeconds) + : SnapshotManager(portNames, intervalSeconds, kDefaultTimespanSeconds) {} + +void SnapshotManager::addSnapshot(const phy::LinkSnapshot& val) { + auto snapshot = SnapshotWrapper(val); + buf_.write(snapshot); + + if (numSnapshotsToPublish_ > 0) { + snapshot.publish(portNames_); + } + if (numSnapshotsToPublish_ > 0) { + numSnapshotsToPublish_--; + } +} + +const RingBuffer& SnapshotManager::getSnapshots() const { + return buf_; +} + +void SnapshotManager::publishAllSnapshots() { + for (auto& snapshot : buf_) { + snapshot.publish(portNames_); + } +} + +void SnapshotManager::publishFutureSnapshots(int numToPublish) { + numSnapshotsToPublish_ = numToPublish; +} void SnapshotWrapper::publish(const std::set& portNames) { if (!FLAGS_enable_snapshot_debugs) { @@ -50,5 +87,4 @@ void SnapshotWrapper::publish(const std::set& portNames) { published_ = true; } } - } // namespace facebook::fboss diff --git a/fboss/lib/link_snapshots/SnapshotManager.h b/fboss/lib/link_snapshots/SnapshotManager.h index 7662d97b6e6b6..a85f37ef93c3a 100644 --- a/fboss/lib/link_snapshots/SnapshotManager.h +++ b/fboss/lib/link_snapshots/SnapshotManager.h @@ -37,29 +37,27 @@ class SnapshotWrapper { * We will store timespan//interval + 1 snapshots in memory * */ -// TODO(ccpowers): We may want to move from std::array to std:vector so we -// can use FLAGS_refresh_interval/FLAGS_gearbox_stats_interval instead of -// needing to define separate constants for the intervals. -template < - size_t intervalSeconds, - size_t timespanSeconds = kDefaultTimespanSeconds> class SnapshotManager { public: - static constexpr size_t length = timespanSeconds / intervalSeconds + 1; - - explicit SnapshotManager(std::set portNames); - void addSnapshot(phy::LinkSnapshot val); + explicit SnapshotManager( + const std::set& portNames, + size_t intervalSeconds); + explicit SnapshotManager( + const std::set& portNames, + size_t intervalSeconds, + size_t timespanSeconds); + void addSnapshot(const phy::LinkSnapshot& val); void publishAllSnapshots(); - const RingBuffer& getSnapshots() const; + const RingBuffer& getSnapshots() const; void publishFutureSnapshots(int numToPublish); void publishFutureSnapshots() { - publishFutureSnapshots(length); + publishFutureSnapshots(buf_.maxSize()); } private: void publishIfNecessary(); - RingBuffer buf_; + RingBuffer buf_; int numSnapshotsToPublish_{0}; std::set portNames_; }; diff --git a/fboss/lib/phy/PhyManager.cpp b/fboss/lib/phy/PhyManager.cpp index 6cd86e1ade97a..1cf9034eab0cc 100644 --- a/fboss/lib/phy/PhyManager.cpp +++ b/fboss/lib/phy/PhyManager.cpp @@ -3,7 +3,7 @@ #include "fboss/lib/phy/PhyManager.h" #include "fboss/agent/FbossError.h" -#include "fboss/agent/PhySnapshotManager-defs.h" +#include "fboss/agent/PhySnapshotManager.h" #include "fboss/agent/gen-cpp2/switch_config_types.h" #include "fboss/agent/platforms/common/PlatformMapping.h" #include "fboss/agent/types.h" @@ -73,8 +73,7 @@ PhyManager::PhyManager(const PlatformMapping* platformMapping) portToCacheInfo_(setupPortToCacheInfo(platformMapping)), portToStatsInfo_(setupPortToStatsInfo(platformMapping)), xphySnapshotManager_( - std::make_unique< - PhySnapshotManager>()) {} + std::make_unique(kXphySnapshotIntervalSeconds)) {} PhyManager::~PhyManager() {} PhyManager::PortToCacheInfo PhyManager::setupPortToCacheInfo( diff --git a/fboss/lib/phy/PhyManager.h b/fboss/lib/phy/PhyManager.h index 2b67b96c9234e..57d42d37ce725 100644 --- a/fboss/lib/phy/PhyManager.h +++ b/fboss/lib/phy/PhyManager.h @@ -28,7 +28,6 @@ class MultiPimPlatformSystemContainer; class MultiPimPlatformPimContainer; class PlatformMapping; class TransceiverInfo; -template class PhySnapshotManager; class PhyManager { @@ -421,8 +420,7 @@ class PhyManager { const PortToStatsInfo portToStatsInfo_; static constexpr auto kXphySnapshotIntervalSeconds = 60; - std::unique_ptr> - xphySnapshotManager_; + std::unique_ptr xphySnapshotManager_; PublishPhyCb publishPhyCb_; }; diff --git a/fboss/qsfp_service/module/QsfpModule.cpp b/fboss/qsfp_service/module/QsfpModule.cpp index 638cb703181e3..f9092c8df1fba 100644 --- a/fboss/qsfp_service/module/QsfpModule.cpp +++ b/fboss/qsfp_service/module/QsfpModule.cpp @@ -93,7 +93,7 @@ QsfpModule::QsfpModule( TransceiverImpl* qsfpImpl) : Transceiver(), qsfpImpl_(qsfpImpl), - snapshots_(TransceiverSnapshotCache(portNames)) { + snapshots_(SnapshotManager(portNames, kSnapshotIntervalSeconds)) { CHECK(!portNames.empty()) << "No portNames attached to this transceiver in platform mapping"; StatsPublisher::initPerPortFb303Stats(portNames); diff --git a/fboss/qsfp_service/module/QsfpModule.h b/fboss/qsfp_service/module/QsfpModule.h index 4e50a0dbc32bc..b290acf997d9a 100644 --- a/fboss/qsfp_service/module/QsfpModule.h +++ b/fboss/qsfp_service/module/QsfpModule.h @@ -20,7 +20,7 @@ #include "fboss/agent/gen-cpp2/switch_config_types.h" #include "fboss/lib/firmware_storage/FbossFirmware.h" -#include "fboss/lib/link_snapshots/SnapshotManager-defs.h" +#include "fboss/lib/link_snapshots/SnapshotManager.h" #include "fboss/lib/phy/gen-cpp2/phy_types.h" #include "fboss/lib/phy/gen-cpp2/prbs_types.h" #include "fboss/qsfp_service/if/gen-cpp2/qsfp_service_config_types.h" @@ -78,7 +78,6 @@ class QsfpModule : public Transceiver { static constexpr auto kSnapshotIntervalSeconds = 10; // Miniphoton module part number static constexpr auto kMiniphotonPartNumber = "LUX1626C4AD"; - using TransceiverSnapshotCache = SnapshotManager; using LengthAndGauge = std::pair; explicit QsfpModule( @@ -221,7 +220,7 @@ class QsfpModule : public Transceiver { void clearTransceiverPrbsStats(phy::Side side) override; - TransceiverSnapshotCache getTransceiverSnapshots() const { + SnapshotManager getTransceiverSnapshots() const { // return a copy to avoid needing a lock in the caller return snapshots_.copy(); } @@ -335,7 +334,7 @@ class QsfpModule : public Transceiver { */ uint64_t numRemediation_{0}; - folly::Synchronized snapshots_; + folly::Synchronized snapshots_; folly::Synchronized> info_; /* * qsfpModuleMutex_ is held around all the read and writes to the qsfpModule diff --git a/fboss/util/wedge_qsfp_util.cpp b/fboss/util/wedge_qsfp_util.cpp index a4a17b0bd1c64..ad43af8b210ac 100644 --- a/fboss/util/wedge_qsfp_util.cpp +++ b/fboss/util/wedge_qsfp_util.cpp @@ -1070,8 +1070,8 @@ int doBatchOps( } // Print high resolution current time with command - std::chrono::microseconds ms = duration_cast( - high_resolution_clock::now().time_since_epoch()); + std::chrono::microseconds ms = duration_cast( + std::chrono::high_resolution_clock::now().time_since_epoch()); std::time_t t = duration_cast(ms).count(); int fractional_seconds = ms.count() % 1000000; auto tm = std::tm{};