GithubHelp home page GithubHelp logo

westerndigitalcorporation / pyvcd Goto Github PK

View Code? Open in Web Editor NEW
103.0 103.0 39.0 179 KB

Python package for writing Value Change Dump (VCD) files.

Home Page: http://pyvcd.readthedocs.org/

License: MIT License

Python 99.43% Makefile 0.57%

pyvcd's People

Contributors

alandtse avatar anmolsahoo25 avatar elegye avatar jackenmen avatar jpgrayson avatar kown7 avatar moonwave avatar pboettch avatar whitequark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyvcd's Issues

Agreement plot

I'm sorry, to the best I know this VDC library is from R, and has a method called "agreementplot", how can I use it?

Documentation: performance

Using the following yields around 30% better performance on my systems.

fp = io.StringIO()
with VCDWriter(fp, timescale=(10, 'ns'), date='today') as writer:
    counter_var = writer.register_var('a.b.c', 'counter', 'integer',
                                      size=8)
    for i in range(1000, 30000000, 300):
        for timestamp, value in enumerate(range(10, 200, 2)):
            writer.change(counter_var, i + timestamp, value)
with open('test3.vcd', 'w+') as fd:
    fp.seek(0)
    shutil.copyfileobj(fp, fd)
fp.close()

Event variables carry no value, yet exporting only works if a changing value is given

When calling writer.change() on an event variable, the value argument must have a truthy value. This value is ignored when the VCD file is written. In previous versions of pyvcd it was fine to give a constant value such as 1. This no longer works in 0.1.6 - only the first event gets exported:

>>> import sys
>>> from vcd import VCDWriter
>>> with VCDWriter(sys.stdout, timescale='1 ns', date='today') as writer:
...     counter_var = writer.register_var('a.b.c', 'counter', 'event')
...     for timestamp in range(10, 20):
...         writer.change(counter_var, timestamp, 1)
... 
$date today $end
$timescale 1 ns $end
$scope module a $end
$scope module b $end
$scope module c $end
$var event 1 0 counter $end
$upscope $end
$upscope $end
$upscope $end
$enddefinitions $end
#0
$dumpvars
$end
#10
10
>>> 

This seems like the wrong behaviour to me because the information an event carries is the timestamp at which it happened, but this information now gets thrown away.

A workaround is to always supply a value that is different from the previous time or give the timestamp as the value argument.

Feature request: decoupling identifiers from names

I'm using pyvcd in nMigen to great effect--thanks!

One unusual thing nMigen does is create a lot of signals with exactly the same value; this is an artifact of how it treats hierarchy. In VCD it is possible to have multiple $vars with the same ident.

Would it possible to provide this functionality in pyvcd?

After convertion using vcd2fsdb, the width of regs are not shown explictly.

Hi all,

I have used pyvcd in my env. It is very excellent.
Verdi is my waveform tool. So I have to change vcd file to fsdb file. After convertion, in the waveform, the regs for example "a[7:0]" are shown "a". I have to click on "a" to show its width.

I found that the code "var_str = '$var {var_type} {size} {ident} {name} $end'.format(var_type=var_type, size=var_size, ident=ident, name=name)" in "def register_var" of writer if be changed to '$var {var_type} {size} {ident} {name} [h_pos:l_pos] $end'.format(var_type=var_type, size=var_size, ident=ident, name=name, h_pos=h_pos, l_pos=l_pos)" can meet my demand.

Can I change the code?

Error parsing $var declaration where identifier contains square brackets

When parsing a $var directive that both contains a square bracket as part of the identifier AND a bit index declared afterwards, pyvcd will fail to process it properly and raise vcd.reader.VCDParseError: [lineno]:[col]: Expected $end. This can occur in VCDs generated for constructs like reg [31:0] regs [31:0] that are an array of vectors, where the resulting VCD would have the declaration $var wire 32 Q! regs[0] [31:0] $end (I had this occur in a file generated by Verilator).

I had difficulty finding the official IEEE Verilog standard's definition of what an "identifier" is, but it seems to me that in the above example, regs[0] would be considered part of the identifier, and [31:0] would be considered the bit index. If you (the maintainers) think this interpretation is correct, then I already have a fix + test case that does this, which I can file a PR for.

(screenshot of the relevant portion of the spec that I could find):
image

Sample code doesn't execute.

I am trying to execute the sample code in the readme and I get an

*** AttributeError: 'str' object has no attribute 'write'

I am running Python 2.7 in Ubuntu.

A PyPI release

Thanks for the great package!

Can you please make a release on PyPI that includes var_type="string"?

Getting syntax error in sample program

Hello, I have tried program written in quickstart. Please correct me If I am wrong, it will create vcd file by this given sample program. But in that I am getting syntax. I was trying to figure it out from documentation, there is no example for some APIs in that. Following is the code that I am trying to run :

import sys
from vcd import VCDWriter
with VCDWriter(sys.stdout, timescale='1 ns', date='today') as writer:
    counter_var = writer.register_var('a.b.c', 'counter', 'integer', size=8)
    real_var = writer.register_var('a.b.c', 'x', 'real', init=1.23)
    for timestamp, value in enumerate(range(10, 20, 2)):
        writer.change(counter_var, timestamp, value)
        writer.change(real_var, 5, 3.21)

$date today $end
$timescale 1 ns $end
$scope module a $end
$scope module b $end
$scope module c $end
$var integer 8 ! counter $end
$var real 64 " x $end
$upscope $end
$upscope $end
$upscope $end
$enddefinitions $end
#0
$dumpvars
b1010 !
r1.23 "
$end
#1
b1100 !
#2
b1110 !
#3
b10000 !
#4
b10010 !
#5
r3.21 "

In this it is giving an error like following:

image

So can anyone please help me to solve this? Please let me know if anything needed from myside.

-Shraddha

gtkw 'combined' signal

I often use the gtkwave Edit->Combine Down (F4) function to collect related signals (like valid+data) and then apply a process or transaction filter to the resulting vector.

Did I miss a way to do this with the current code?

Looks like it's similar to a trace() except uses a list of signals:

@800029
^<2 gtkf-itag.py
#{cp_i1} cocotb_icarus.c0.iu_lq_i1_completed (0)cocotb_icarus.c0.iu_lq_t0_i1_completed_itag[0:6] (1)cocotb_icarus.c0.iu_lq_t0_i1_completed_itag[0:6] (2)cocotb_icarus.c0.iu_lq_t0_i1_completed_itag[0:6] (3)cocotb_icarus.c0.iu_lq_t0_i1_completed_itag[0:6] (4)cocotb_icarus.c0.iu_lq_t0_i1_completed_itag[0:6] (5)cocotb_icarus.c0.iu_lq_t0_i1_completed_itag[0:6] (6)cocotb_icarus.c0.iu_lq_t0_i1_completed_itag[0:6]
@1001201
-group_end

String variable formatting is unsound

String formatting checks (if check is true) for spaces (ASCII 0x20), but not for other special characters, some of which lead to even worse results:

>>> from vcd import VCDWriter
>>> writer = VCDWriter(open("foo.vcd", "wt"))
>>> var = writer.register_var(scope="", name="test", var_type="string")
>>> writer.change(var,0,"a\nb")
>>> writer.close()

As far as I know, the grammar accepted for string values is not documented, but this mailing list post indicates that spaces "and such" may be escaped as hex or octal escapes, and this function in gtkwave indicates that the complete list of characters implied in "and such" would be \x20, \r, \n, \t, and of course \\.

>>> writer = VCDWriter(open("foo.vcd", "wt"))
>>> var = writer.register_var(scope="", name="test", var_type="string")
>>> writer.change(var,0,r"a\x09b\x20c")
>>> writer.close()

Screenshot_20201206_021617

At least, pyvcd should check for more than just spaces when emitting strings. However, I would strongly prefer if it actually escaped the string appropriately, since it should not be the responsibility of downstream projects to hunt down such obscure, barely documented detail.

Let me know if you'd like me to implement this.

Support escaped identifiers

Vivado outputs a lot of these, here are a couple of example lines:

$var wire 1 ~ \<const0>\ $end
$scope module \gnbram.gnativebmg.native_blk_mem_gen\ $end
$scope module \valid.cstr\ $end
$var wire 1 3! \ram_ena_inferred__0/i__n_0\ $end
$var wire 1 7! \ramloop[1].ram.r_n_0\ $end
$var wire 1 >! \^doutb\ [0:0] $end

3.7.1 Escaped identifiers from IEEE Std 1364-2005 (Revision of IEEE Std 1364-2001) page 14
image

clk signal

Hi, there is a question,
How can I generate the clk signal by vcdWriter.change() which will change from 0 to 1 in a timestamp

Implement vcd parsing

Looking for a way to parse myhdl generated vcd dumps to extract the signals to pass to sigrok-cli for protocol analysis. (sigrok-cli doesn't support signal vectors)

VCDWriter::register_var() low performance when register large number of variables

Thank you for the pyvcd project.
I'm using pyvcd 0.1.4 with anconda3, python 3.7.3.
Recently I found that VCDWriter::register_var() gives low performance when we have large number of variables, say > 5 millions, need to be register.The call becomes very slow,

https://github.com/SanDisk-Open-Source/pyvcd/blob/master/vcd/writer.py

Lines 153 - 155
def register_var(self, scope, name, var_type, size=None, init=None,
                 ident=None):

Line #
153 scope_names = self._scope_var_names.setdefault(scope_tuple, [])
154 if name in scope_names:
155    raise KeyError('Duplicate var {} in scope {}'.format(name, scope))

Specifically line 154 appears perform linear search against scope_names which is a list, 
I did a test, it uses around 18'57" for 500,000 calls at line #154
cumtime1137.97539" (18'57") - writer.register_var step 3 - if name in scope_names: :called500,000  times, where scope_names has 499,426 items in it at the time.

Here is the test log for 500,000 calls
$ grep "500,000" app.log
cumtime 0.51248" - writer.register_var step 0 - check :called 500,000  times
cumtime 0.9799" - writer.register_var step 1 - _get_scope_tuple :called 500,000  times
cumtime 0.56376" - writer.register_var step 2 - _scope_var_names.setdefault :called 500,000  times
cumtime 1137.97539" - writer.register_var step 3 - if name in scope_names: :called 500,000  times
cumtime 0.79809" - writer.register_var step 4 - ident = format(id, 'x') :called 500,000  times
cumtime 1.01963" - writer.register_var step 5 - var_str check :called 500,000  times
cumtime 1.22152" - writer.register_var step 6 - var_str format :called 500,000  times
cumtime 0.85593" - writer.register_var step 7 - *Variable :called 500,000  times
cumtime 1.54725" - writer.register_var step 8 - change :called 500,000  times
cumtime 0.92627" - writer.register_var step 9 - setdefault :called 500,000  times
type(scope_names): <class 'list'>, len(scope_names): 499, 426, 

Please confirm the finding is valid.

register var after time zero

It seems pyvcd does not allow register var after time zero:

  File "/usr/local/lib/python3.8/dist-packages/vcd/writer.py", line 214, in register_var
    raise VCDPhaseError('Cannot register after time 0.')
vcd.writer.VCDPhaseError: Cannot register after time 0.

Is this is VCD file format limitation or a pyvcd implementation limitation?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.