| #include <chrono> // NOLINT |
| #include <filesystem> // NOLINT |
| #include <iostream> |
| #include <string> |
| |
| #include "absl/time/time.h" |
| #include "tlbmc/hal/shared_mem/segment_manager.h" |
| #include "tlbmc/hal/shared_mem/server.h" |
| #include "bmcweb_authorizer_singleton.h" |
| #include "server.h" |
| |
| int main() { |
| boost::interprocess::shared_memory_object::remove("TlbmcSharedMemory"); |
| std::filesystem::remove(std::string{milotic_tlbmc::kShareMemInitializedFile}); |
| std::cout << "SharedMemoryServer starts \n"; |
| milotic_tlbmc::SharedMemoryServer::Initialize(); |
| milotic::RedfishServiceConfig config; |
| milotic::authz::BmcWebAuthorizerSingleton::Initialize( |
| config.authz_config_path, config.rofs_base_privileges_folder, |
| config.gmi_file_path, config.oauth_key_path, |
| config.pattern_to_entity_overrides_path, config.offline_node_entity_path); |
| |
| std::chrono::high_resolution_clock::time_point start = |
| std::chrono::high_resolution_clock::now(); |
| constexpr int kIterations = 1000'000; |
| for (int i = 0; i < kIterations; ++i) { |
| milotic_tlbmc::SharedMemoryServer::GetInstance().UpdateMetricsRequestCount( |
| true); |
| } |
| std::chrono::high_resolution_clock::time_point end = |
| std::chrono::high_resolution_clock::now(); |
| std::cout << "latency ns of one UpdateMetricsRequestCount :" |
| << static_cast<double>( |
| std::chrono::duration_cast<std::chrono::nanoseconds>(end - |
| start) |
| .count()) / |
| kIterations |
| << "\n"; |
| start = std::chrono::high_resolution_clock::now(); |
| for (int i = 0; i < kIterations; ++i) { |
| milotic_tlbmc::SharedMemoryServer::GetInstance().UpdateMetricsResponse( |
| absl::Milliseconds(i), 200, "test_resource_url"); |
| } |
| end = std::chrono::high_resolution_clock::now(); |
| std::cout << "latency ns of one UpdateMetricsResponse :" |
| << static_cast<double>( |
| std::chrono::duration_cast<std::chrono::nanoseconds>(end - |
| start) |
| .count()) / |
| kIterations |
| << "\n"; |
| std::cout << "Metrics is " |
| << milotic_tlbmc::SharedMemoryServer::GetInstance() |
| .GetMetrics() |
| ->ToJson() |
| .dump(2) |
| << "\n"; |
| return 0; |
| } |