'Monitor system average load each \'interval\' seconds and recording
process/threads info if system loadavg great than \'load_threshold\'.'

def start(self, test):

    if (self.__get_param('free_mem_before_test', 'no') == 'yes'):
        freemem()
    self.child_pid = os.fork()
    if (not self.child_pid):
        (prev_total, prev_idle) = (0, 0)
        (count, content_size) = (0, 0)
        ps_num = int(self.__get_param('top_ps_num', 15))
        log_mb_size = int(self.params.get('log_mb_size', 5))
        threshold = float(self.__get_param('load_threshold', 0.0))
        cpu_num = open('/proc/cpuinfo', 'r').read().count('process')
        outfile = os.path.join(test.profdir, self.outfile)
        self.fd = open(outfile, 'a+')
        while True:
            count += 1
            title = ((('=' * 30) + ('    Loop    %d    ' % count)) + ('=' * 30))
            lines = [title]
            swap_cached = swapcached()
            (prev_total, prev_idle, cpu_load) = cpuload(cpu_num, prev_total, prev_idle)
            if ((cpu_load > threshold) or (swap_cached > 0)):
                lines.extend(uptime())
                lines.extend(vmstat())
                lines.extend(meminfo())
                lines.extend(iostat())
                orders = ((ps_num and [['pcpu', 'pmem']]) or [['pid']])[0]
                for _ in orders:
                    lines.extend(listps(ps_num, _))
                lines = '\n'.join(lines)
                content_size += len(lines)
                if (content_size > ((log_mb_size * 1024) * 1024)):
                    self.fd.seek(0)
                    self.fd.truncate()
                    content_size = 0
                self.fd.write(('%s\n' % lines))
            time.sleep(self.interval)
