aboutsummaryrefslogtreecommitdiffstats
path: root/src/3rd/kissfft/test/pstats.c
blob: 5082bdadf5f0b09aca0414b8ef78557143ef55ac (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 *  Copyright (c) 2003-2010, Mark Borgerding. All rights reserved.
 *  This file is part of KISS FFT - https://github.com/mborgerding/kissfft
 *
 *  SPDX-License-Identifier: BSD-3-Clause
 *  See COPYING file for more information.
 */
#include <stdio.h>
#include <stdlib.h>
#include <sys/times.h>
#include <sys/types.h>
#include <unistd.h>

#include "pstats.h"

static struct tms tms_beg;
static struct tms tms_end;
static int has_times = 0;


void pstats_init(void)
{
    has_times = times(&tms_beg) != -1;
}

static void tms_report(void)
{
    double cputime;
    if (! has_times )
        return;
    times(&tms_end);
    cputime = ( ((float)tms_end.tms_utime + tms_end.tms_stime + tms_end.tms_cutime + tms_end.tms_cstime ) -
                ((float)tms_beg.tms_utime + tms_beg.tms_stime + tms_beg.tms_cutime + tms_beg.tms_cstime ) )
               / sysconf(_SC_CLK_TCK);
    fprintf(stderr,"\tcputime=%.3f\n" , cputime);
}

static void ps_report(void)
{
    char buf[1024];
#ifdef __APPLE__ /*  MAC OS X */
    sprintf(buf,"ps -o command,majflt,minflt,rss,pagein,vsz -p %d 1>&2",getpid() );
#else /* GNU/Linux */
    sprintf(buf,"ps -o comm,majflt,minflt,rss,drs,pagein,sz,trs,vsz %d 1>&2",getpid() );
#endif    
    if (system( buf )==-1) {
        perror("system call to ps failed");
    }
}

void pstats_report()
{
    ps_report();
    tms_report();
}