[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UNIKRAFT PATCH v2 2/2] plat/kvm: Change the default directory for the profiling files



Call the __gcov_exit() function in a conditional way (using ifdef guard) in
the function ukplat_terminate(). Thus, the profiling files (*.gcda) are 
generated
within the Unikraft filesystem. Use 9pfs to transfer the *.gcda files from 
Unikraft
to the host system.

Set GCOV_PREFIX and GCOV_PREFIX_STRIP. GCOV_PREFIX is a runtime environment 
variable
that determines the root directory where the gcov output files (*.gcda) are 
written.
GCOV_PREFIX_STRIP=X is also a runtime variable and has the effect of stripping X
elements from the path found in the object files.

Thus, the default path in which the *.gcda files were generated was changed 
with the
help of the two environment variables. Now the files are saved to the path given
exclusively by the GCOV_PREFIX environment variable, GCOV_PREFIX_STRIP being 
large
enough to skip the entire default path.

Signed-off-by: Alice Suiu <alicesuiu17@xxxxxxxxx>
---
 plat/kvm/shutdown.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/plat/kvm/shutdown.c b/plat/kvm/shutdown.c
index cce26b7..ad0cd18 100644
--- a/plat/kvm/shutdown.c
+++ b/plat/kvm/shutdown.c
@@ -27,11 +27,46 @@
 #include <uk/print.h>
 #include <uk/plat/bootstrap.h>
 
+#if CONFIG_OPTIMIZE_PGO_GENERATE
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+
+#define GCOV_GENERATED_DIR     "/gcov_profiling"
+#define GCOV_PREFIX_STRIP_LENGTH       "100"
+
+void set_path_gcov_files()
+{
+       const char *gcov_prefix;
+       const char *gcov_strip;
+
+       gcov_prefix = getenv("GCOV_PREFIX");
+       if (!gcov_prefix)
+               setenv("GCOV_PREFIX", GCOV_GENERATED_DIR, 1);
+
+       gcov_strip = getenv("GCOV_PREFIX_STRIP");
+       if (!gcov_strip)
+               setenv("GCOV_PREFIX_STRIP", GCOV_PREFIX_STRIP_LENGTH, 1);
+
+       DIR* dir = opendir(GCOV_GENERATED_DIR);
+       if (dir)
+               closedir(dir);
+       else if (ENOENT == errno)
+               mkdir(GCOV_GENERATED_DIR, 0777);
+}
+#endif
+
 static void cpu_halt(void) __noreturn;
 
 /* TODO: implement CPU reset */
 void ukplat_terminate(enum ukplat_gstate request __unused)
 {
+
+#if CONFIG_OPTIMIZE_PGO_GENERATE
+       set_path_gcov_files();
+       __gcov_exit();
+#endif
+
        uk_pr_info("Unikraft halted\n");
 
        /* Try to make system off */
-- 
2.17.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.