Get system time in VCS

Is there a way to get system time in VCS / UVM? I am looking for something similar to Perl localtime(time). Is there a way to print the system time for each printed uvm_info?

+4
source share
3 answers

One way is to use $system()any system command, including the date system command, to run.

initial
 begin
    $system("date");
 end

From IEEE 1800 LRM:

$system C(). C , . $system , . , () int. $system , C- system() NULL .

. .

+3

VCS, . $system, IEEE Std 1800-2012 & sect; 20.18.1. , UNIX, :

function string get_localtime();    
  int fd;
  string localtime;
  void'($system("data > localtime")); // temp file
  fd = $fopen("localtime", "r");
  void'($fscanf(fd,"%s",localtime));
  $fclose(fd);
  void'($system("rm localtime")); // delete file
  return localtime;
endfunction

VCS $system, C/++, DPI (. IEEE Std 1800-2012 35). C VCS SystemVerilog. SystemVerilog import, C. , - my_localtime, - , :

import "DPI" function string my_localtime();
+3

In the c file of wallclock.c:

#include <time.h>
wallclock() {
   time_t t;
   t = time(NULL);
   return (ctime(&t));
   //return time(NULL);
}

In the SV file:

import "DPI-C" function string wallclock();

module try;

   //int unsigned   t;
   string t;

   initial begin
      t = wallclock();
      $write("time=%0s\n", t);
   end
endmodule
0
source

All Articles