• 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 18910
  • 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
Parents
  • 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
Reply
  • 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
Children
  • 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
  • Pedro Cardoso
    Pedro Cardoso over 3 years ago in reply to StephenH

    Hi Stephen,
    But how do I tell xrun where to stop and measure the time?

    Please note that I am entering my commands in the console.

    Cheers,

    Pedro

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

    Hi Stephen

    I cannot make this work.

    So, do I have to call xrun as "xrun -status -status3" or as "xrun -status -status 3" ?
    Am I missing something?

    Best regards,

    Pedro

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

    Hi Pedro.

    It's the first one: "xrun -status -status3".

    The "-status" tells it to dump a CPU/memory summary at exit, and "-status3" tells it to dump the more verbose version of the summary, with a break-down for the individual tool components.

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

    Hi,

    Thanks for the answer.

    But how does the simulator know when to dump the summary ? I should have to write some command to tell the simulator that I want to generate the report at that point of the code.

    Otherwise, how xrun would know that the program had ended?

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

    Hi Stephen,

    Can you please give me your inputs on my last question? I would really appreciate it.

    Best regards,

    Pedro

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

    The summary is dumped when you exit the simulator.

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

    This is the output I have 

    Aggregate audit (2:30:10 PM, Fri Dec 10, 2021):
    Time used: CPU = 47.9 ks (13h 18m 36s), elapsed = 13 ks (3h 36m 17s), util. = 369%.
    Time spent in licensing: elapsed = 20.6 s.
    Peak memory used = 2.33 Gbytes.
    Simulation started at: 10:53:53 AM, Fri Dec 10, 2021, ended at: 2:30:10 PM, Fri Dec 10, 2021, with elapsed time (wall clock): 13 ks (3h 36m 17s).
    spectre completes with 0 errors, 89 warnings, and 22 notices.
    xmsim: Memory Usage - Final: 1289.0M, Peak: 1345.3M, Peak virtual: 1734.9M
    xmsim: CPU Usage - 3314.5s system + 46984.3s user = 50298.8s total (14821.7s, 100.0% cpu) (myhost)
    xrun: Time - 15071.8s
    TOOL: xrun(64) 20.05-t004-20201018: Exiting on Dec 10, 2021 at 14:43:02 CET (total: 04:11:12)

    Do I have to divide the time, returned by the simulator, by the number of cpus I've used? Otherwise, the result doesn't make sense.

    15071 seconds is 4.18h, which is more than the "wall clock" value.

    • 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