Fix invalid fd on PMU counter creation (#17)

* Fix invalid fd on PMU counter creation

The issue was due to the call to emplace creating a temporary
PMU counter. When the temporary object was destroyed, the
corresponding file descriptor was closed.

* Better formatting for errors

* Log failures when initializing counters
diff --git a/vendor/arm/pmu/pmu_counter.cpp b/vendor/arm/pmu/pmu_counter.cpp
index 943bd2a..b82aa5a 100644
--- a/vendor/arm/pmu/pmu_counter.cpp
+++ b/vendor/arm/pmu/pmu_counter.cpp
@@ -74,7 +74,7 @@
 	const int result = ioctl(_fd, PERF_EVENT_IOC_ENABLE, 0);
 	if (result == -1)
 	{
-		throw std::runtime_error("Failed to enable PMU counter: " + std::to_string(errno));
+		throw std::runtime_error("Failed to enable PMU counter: " + std::string(strerror(errno)));
 	}
 }
 
diff --git a/vendor/arm/pmu/pmu_counter.h b/vendor/arm/pmu/pmu_counter.h
index b7c2068..802d23b 100644
--- a/vendor/arm/pmu/pmu_counter.h
+++ b/vendor/arm/pmu/pmu_counter.h
@@ -95,7 +95,7 @@
 
 	if (result == -1)
 	{
-		throw std::runtime_error("Can't get PMU counter value: " + std::to_string(errno));
+		throw std::runtime_error("Can't get PMU counter value: " + std::string(strerror(errno)));
 	}
 
 	return static_cast<T>(value);
diff --git a/vendor/arm/pmu/pmu_profiler.cpp b/vendor/arm/pmu/pmu_profiler.cpp
index b7b689c..410e841 100644
--- a/vendor/arm/pmu/pmu_profiler.cpp
+++ b/vendor/arm/pmu/pmu_profiler.cpp
@@ -48,8 +48,12 @@
 		{
 			try
 			{
-				auto pmu_counter = pmu_counters_.emplace(counter, PmuCounter{pmu_config->second});
-				pmu_counters_[counter].get_value<double>();
+				// Create a PMU counter with the specified configuration
+				auto pmu_counter_res = pmu_counters_.emplace(counter, pmu_config->second);
+
+				// Try reading a value from the counter to check that it opened correctly
+				auto &pmu_counter = pmu_counter_res.first->second;
+				pmu_counter.get_value<double>();
 
 				// PMU counter is created and can retrieve values
 				available_counters_.insert(counter);
@@ -57,6 +61,7 @@
 			catch (const std::runtime_error &e)
 			{
 				// PMU counter initialization failed
+				HWCPIPE_LOG("%s", e.what());
 			}
 		}
 	}