u* tools: automatically detect the language (#1067)
* cc: bcc function to detect the language of a process
bcc_procutils_language looks into /proc/$pid/cmdline, /proc/$pid/exe,
and /proc/$pid/maps to determine the language.
Python wrapper takes a list of candidate languages; if the detected
language is not part of the list, None is returned.
* u* tools: automatically detect the language
Uses the detect_language bcc helper. -l switch can override the
detected language. In uthreads and ucalls, the language can be
overwritten to 'none' to trace pthreads and syscalls respectively.
All tools use the -l switch to set the language, for consistency.
diff --git a/tests/python/test_utils.py b/tests/python/test_utils.py
index 08862e7..2959482 100755
--- a/tests/python/test_utils.py
+++ b/tests/python/test_utils.py
@@ -2,9 +2,10 @@
# Copyright (c) Catalysts GmbH
# Licensed under the Apache License, Version 2.0 (the "License")
-from bcc.utils import get_online_cpus
+from bcc.utils import get_online_cpus, detect_language
import multiprocessing
import unittest
+import os
class TestUtils(unittest.TestCase):
def test_get_online_cpus(self):
@@ -13,6 +14,10 @@
self.assertEqual(len(online_cpus), num_cores)
+ def test_detect_language(self):
+ candidates = ["java", "ruby", "php", "node", "c", "python"]
+ language = detect_language(candidates, os.getpid())
+ self.assertEqual(language, "python")
if __name__ == "__main__":
unittest.main()