In my testing, these small changes affected the "aa-logprof" measured
from the running of the command until the interactive options appear,
made it take 10-17% less time.

Here's a short test that takes 17% less time (I think this log was
around 50 MB). I also did a much huger log which was also around 13%.
And then after my previous patches, I tested again and got 10%. I'm not
sure if it affects more than the start up.


before:
    real    0m9.704s
    user    0m9.474s
    sys     0m0.224s

    real    0m9.949s
    user    0m9.770s
    sys     0m0.179s
   
    real    0m9.951s
    user    0m9.763s
    sys     0m0.187s
   
    real    0m9.848s
    user    0m9.650s
    sys     0m0.198s
   
after:
    real    0m8.075s
    user    0m7.954s
    sys     0m0.122s

    real    0m8.310s
    user    0m8.196s
    sys     0m0.114s

    real    0m8.260s
    user    0m8.075s
    sys     0m0.173s

    real    0m8.109s
    user    0m7.958s
    sys     0m0.151s

scale=10
o=(9.484+9.77+9.76+9.65)
p1=(7.954+8.196+8.075+7.958)
p1/o
.8323763707


I was going to test the 2 separately to see if p1b is necessary, but
cboltz seems to like its readability and prefers it anyway, so here it is.
diff -ur orig/aa.py p1a/aa.py
--- orig/aa.py	2014-10-16 22:03:42.000000000 +0200
+++ p1a/aa.py	2014-11-24 22:55:56.522927379 +0100
@@ -147,29 +147,27 @@
     sys.exit(1)
 
 def check_for_apparmor():
-    """Finds and returns the mointpoint for apparmor None otherwise"""
+    """Finds and returns the mountpoint for apparmor None otherwise"""
     filesystem = '/proc/filesystems'
     mounts = '/proc/mounts'
     support_securityfs = False
     aa_mountpoint = None
-    regex_securityfs = re.compile('^\S+\s+(\S+)\s+securityfs\s')
     if valid_path(filesystem):
         with open_file_read(filesystem) as f_in:
             for line in f_in:
                 if 'securityfs' in line:
                     support_securityfs = True
-    if valid_path(mounts):
-        with open_file_read(mounts) as f_in:
-            for line in f_in:
-                if support_securityfs:
-                    match = regex_securityfs.search(line)
-                    if match:
-                        mountpoint = match.groups()[0] + '/apparmor'
-                        if valid_path(mountpoint):
+                    break
+        if support_securityfs:
+            with open_file_read(mounts) as f_in:
+                for line in f_in:
+                    split = line.split()
+                    if len(split) > 2 and split[2] == 'securityfs':
+                        mountpoint = split[1] + '/apparmor'
+                        # Check if apparmor is actually mounted there
+                        if valid_path(mountpoint) and valid_path(mountpoint + '/profiles'):
                             aa_mountpoint = mountpoint
-    # Check if apparmor is actually mounted there
-    if not valid_path(aa_mountpoint + '/profiles'):
-        aa_mountpoint = None
+                            break
     return aa_mountpoint
 
 def which(file):
diff -ur apparmor.orig/aamode.py apparmor.p1/aamode.py
--- apparmor.orig/aamode.py	2014-07-14 20:56:26.000000000 +0200
+++ apparmor.p1/aamode.py	2014-11-09 22:15:01.875415033 +0100
@@ -68,7 +68,7 @@
              }
 
 LOG_MODE_RE = re.compile('(r|w|l|m|k|a|x|ix|ux|px|pux|cx|nx|pix|cix|Ux|Px|PUx|Cx|Nx|Pix|Cix)')
-MODE_MAP_RE = re.compile('(r|w|l|m|k|a|x|i|u|p|c|n|I|U|P|C|N)')
+MODE_MAP_LIST = ["r", "w", "l", "m", "k", "a", "x", "i", "u", "p", "c", "n", "I", "U", "P", "C", "N"]
 
 def str_to_mode(string):
     if not string:
@@ -87,27 +87,23 @@
 
 def sub_str_to_mode(string):
     mode = set()
-
-    while string:
-        tmp = MODE_MAP_RE.search(string)
-        if not tmp:
+    
+    for mode_char in string:
+        if mode_char not in MODE_MAP_LIST:
             break
-        string = MODE_MAP_RE.sub('', string, 1)
-
-        mode_char = tmp.groups()[0]
         if MODE_HASH.get(mode_char, False):
             mode |= MODE_HASH[mode_char]
-        else:
-            pass
 
     return mode
 
 def split_log_mode(mode):
+    #if the mode has a "::", then the left side is the user mode, and the right side is the other mode
+    #if not, then the mode is both the user and other mode
     user = ''
     other = ''
-    match = re.search('(.*?)::(.*)', mode)
-    if match:
-        user, other = match.groups()
+    
+    if "::" in mode:
+        user, other = mode.split("::")
     else:
         user = mode
         other = mode
-- 
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to