| #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( |
| { |
| .configuration_path = config.authz_config_path, |
| .platform_configuration_path = config.authz_platform_config_path, |
| .base_privileges_folder = config.rofs_base_privileges_folder, |
| .pattern_entity_overrides_path = |
| config.pattern_to_entity_overrides_path, |
| .offline_node_entities_path = config.offline_node_entity_path, |
| .google_machine_identity_path = config.gmi_file_path, |
| }, |
| /*oauth_key_path=*/config.oauth_key_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; |
| } |