aboutsummaryrefslogtreecommitdiffstats
path: root/run/executable/ftcat.py
blob: 5da8fa7e484d474dda8be6ef09524796865f9643 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import stat

from executable import Executable

class FTcat(Executable):
    '''Used to wrap the ftcat binary in the Experiment object.'''

    def __init__(self, ft_cat_bin, stdout_file, stderr_file, dev, events, cpu=None):
        '''Extends the Executable initializer method with ftcat attributes.'''

        # hack to run FTCat at higher priority
        chrt_bin = '/usr/bin/chrt'

        super(FTcat, self).__init__(chrt_bin)
        self.stdout_file = stdout_file
        self.stderr_file = stderr_file

        mode = os.stat(dev)[stat.ST_MODE]
        if not mode & stat.S_IFCHR:
            raise Exception("%s is not a character device" % dev)

        if events is None:
            raise Exception('No events!')

        # hack to run FTCat at higher priority
        self.extra_args = ['-f', '40']
        if cpu is not None:
            # and bind it to a CPU
            self.extra_args.extend(['/usr/bin/taskset', '-c', str(cpu)])
        events_str_arr = map(str, events)
        self.extra_args.extend([ft_cat_bin, dev] + events_str_arr)