aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/time.pl
blob: 6f10170b3b683889e6f3c7d266e1185a5489650c (plain)
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
57
58
59
60
61
62
63
64
65
#!/usr/bin/env perl

use strict;
use warnings;
use Config;

if (@ARGV < 2) {
	die "Usage: $0 <prefix> <command...>\n";
}

sub gettime {
	my ($sec, $usec);

	eval {
		require Time::HiRes;
		($sec, $usec) = Time::HiRes::gettimeofday();
	};

	unless (defined($sec) && defined($usec)) {
		my $tv_t = ($Config{'longsize'} == 8) ? 'qq' : 'll';
		my $tv = pack $tv_t, 0, 0;

		eval {
			require 'syscall.ph';
			syscall(SYS_gettimeofday(), $tv, 0);
		};

		($sec, $usec) = unpack $tv_t, $tv;
	}

	return ($sec, $usec);
}

my ($prefix, @cmd) = @ARGV;
my ($sec, $usec) = gettime();
my $pid = fork();

if (!defined($pid)) {
	die "$0: Failure to fork(): $!\n";
}
elsif ($pid == 0) {
	exec(@cmd);
	die "$0: Failure to exec(): $!\n";
}
else {
	$SIG{'INT'} = 'IGNORE';
	$SIG{'QUIT'} = 'IGNORE';

	if (waitpid($pid, 0) == -1) {
		die "$0: Failure to waitpid(): $!\n";
	}

	my $exitcode = $? >> 8;
	my ($sec2, $usec2) = gettime();
	my (undef, undef, $cuser, $csystem) = times();

	printf STDOUT "%s#%.2f#%.2f#%.2f\n",
		$prefix, $cuser, $csystem,
		($sec2 - $sec) + ($usec2 - $usec) / 1000000;

	$SIG{'INT'} = 'DEFAULT';
	$SIG{'QUIT'} = 'DEFAULT';

	exit $exitcode;
}
pan class="n">GHDLSYNTH_ADA_WRAPPER_WD(get_next_sub_module, Module, Module); GHDLSYNTH_ADA_WRAPPER_DW(get_id, Module_Id, Module); GHDLSYNTH_ADA_WRAPPER_DW(get_nbr_outputs, unsigned int, Module); GHDLSYNTH_ADA_WRAPPER_DW(get_nbr_inputs, unsigned int, Module); struct Net { unsigned int id; }; GHDLSYNTH_ADA_WRAPPER_DW(get_width, Width, Net); struct Instance { unsigned int id; }; inline bool is_valid(Instance inst) { return inst.id != 0; } GHDLSYNTH_ADA_WRAPPER_WD(get_self_instance, Instance, Module); GHDLSYNTH_ADA_WRAPPER_WD(get_first_instance, Instance, Module); GHDLSYNTH_ADA_WRAPPER_WD(get_next_instance, Instance, Instance); GHDLSYNTH_ADA_WRAPPER_WD(get_instance_name, Sname, Instance); GHDLSYNTH_ADA_WRAPPER_WD(get_module, Module, Instance); GHDLSYNTH_ADA_WRAPPER_WD(get_net_parent, Instance, Net); GHDLSYNTH_ADA_WRAPPER_DWD(get_param_uns32, unsigned int, Instance, Port_Idx); struct Input { unsigned int id; }; GHDLSYNTH_ADA_WRAPPER_WWD(get_input, Input, Instance, Port_Idx); GHDLSYNTH_ADA_WRAPPER_WWD(get_output, Net, Instance, Port_Idx); GHDLSYNTH_ADA_WRAPPER_WD(get_driver, Net, Input); // Utils #undef GHDLSYNTH_ADA_PREFIX #define GHDLSYNTH_ADA_PREFIX(N) netlists__utils__##N GHDLSYNTH_ADA_WRAPPER_DW(get_id, Module_Id, Instance); GHDLSYNTH_ADA_WRAPPER_WWD(get_input_name, Sname, Module, Port_Idx); GHDLSYNTH_ADA_WRAPPER_WWD(get_output_name, Sname, Module, Port_Idx); GHDLSYNTH_ADA_WRAPPER_BW(has_one_connection, Net); extern "C" unsigned int libghdlsynth__synth(int argc, const char **argv); inline Module ghdl_synth(int argc, const char **argv) { Module res; res.id = libghdlsynth__synth(argc, argv); return res; } // Disp ghdl configuration. extern "C" void ghdlcomp__disp_config (void); // Initialize and finalize the whole library. extern "C" void libghdlsynth_init (void); extern "C" void libghdlsynth_final (void); };