• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Reading simulation time to a variable

Stats

  • Locked Locked
  • Replies 17
  • Subscribers 65
  • Views 18880
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reading simulation time to a variable

Pedro Cardoso
Pedro Cardoso over 3 years ago

Hello,

Does anyone know if it is possible to read the running time and, then store it into a variable using TCL? 

Imagine that a simulation is running. Every time it is simulating the time moves, when it's not the time doesn't. With this, I would like to retrieve the real simulation time.

Thanks in advance.

Kind regards,

Pedro

  • Cancel
  • StephenH
    StephenH over 3 years ago

    Hi Pedro.

    The "time" command lets you report the current time, as well as doing math operations on time values. Refer to the Xcelium Tcl docs.

    xcelium> time

    0 FS

    xcelium> time ns

    0 NS

    xcelium> set now [time ns]

    0 NS

    xcelium> puts $now

    0 NS

    xcelium> 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Pedro Cardoso
    Pedro Cardoso over 3 years ago in reply to StephenH

    Is there a way to read the time value while the script is running using interruptions?

    Imagine that I want to use the command time and clock every 10seconds. Is that possible?

    Pedro

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 3 years ago in reply to Pedro Cardoso

    There's no built-in way to set a real-time breakpoint, but it could be done by writing some C code to set an OS timer interrupt and some VPI code to get the timestamp and print it.

    Alternatively just set a breakpoint that stops the simulation every N time units of simulated time and use the Tcl "clock" command to print the current time, would that help?

    stop -create -time -relative 10ns -continue -execute { set now [time ns]; clock format [clock seconds] -format "TICK: $now == %T"; }

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Pedro Cardoso
    Pedro Cardoso over 3 years ago in reply to StephenH

    Thanks for your reply.
    I tried the command above the following way:

    1 - entered the "stop" command

    2 - entered "after 5000"

    I was expecting to have interruptions during the execution of the command "after 5000", but that doesn't happen.

    Pedro

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 3 years ago in reply to Pedro Cardoso

    The "stop" command doesn't accept a "after" argument so I don't understand what you did here (nor what you mean by "after 5000").

    The time-related brakpoint options are: 

    -time time_spec  [-absolute]  [-relative]  [-start time_spec ]  [-modulo time_spec]

    please check the docs that I linked to in my first reply, everything you need is in there. Slight smile

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Pedro Cardoso
    Pedro Cardoso over 3 years ago in reply to StephenH

    The "time" that the stop command will generate is the CPU time. I would like to stop every 10 seconds (human time).

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 3 years ago in reply to Pedro Cardoso

    As I mentioned before, there is no built-in way to stop based on real time, only simulated time can be specified with the stop command. What are you actually trying to achieve? If you can explain that, maybe I can propose a way to do it based on what is supported int eh simulator...

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Pedro Cardoso
    Pedro Cardoso over 3 years ago in reply to StephenH

    I am trying to measure the time a simulation takes to run, but without taking into account the time the simulator is doing nothing.

    So if I run a piece of code that takes 10 minutes and go for lunch for an hour and then run another piece of code that takes 10 minutes more, I would like the reported duration of the sim to be 20 minutes and not 1h:20m.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 3 years ago in reply to Pedro Cardoso

    OK, thanks for clarifying your request. If you just need this time measurement as a summary for the entire simulation, why not just add "-status -status3" to the xrun command line? This will result in a couple of lines at the end of the simulation log, including the actual CPU time spent:

    xmsim: CPU Usage - 26.2s system + 31.0s user = 57.2s total (86.4s, 66.2% cpu) (myhost)
    xrun: Time - 87.0s

    Here you can see that the simulation used 87.0s of CPU time - this is not the wall-clock time but the time used actually doing work.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Pedro Cardoso
    Pedro Cardoso over 3 years ago in reply to StephenH

    Thank you very much. I will try this.

    Pedro

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
>

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information