(args: Args)
| 34 | |
| 35 | |
| 36 | def run_python_copy(args: Args): |
| 37 | reader = SequentialReader() |
| 38 | reader.open(StorageOptions(uri=args.input_uri, storage_id=args.storage_id), |
| 39 | ConverterOptions(input_serialization_format=args.serialization, output_serialization_format=args.serialization)) |
| 40 | writer = SequentialWriter() |
| 41 | writer.open(StorageOptions(uri=args.output_uri_py, storage_id=args.storage_id), |
| 42 | ConverterOptions(input_serialization_format=args.serialization, output_serialization_format=args.serialization)) |
| 43 | |
| 44 | try: |
| 45 | topics = reader.get_all_topics_and_types() |
| 46 | except AttributeError: |
| 47 | topics = reader.get_topics_and_types() |
| 48 | |
| 49 | for t in topics: |
| 50 | writer.create_topic(TopicMetadata( |
| 51 | id=0, |
| 52 | name=t.name, |
| 53 | type=t.type, |
| 54 | serialization_format=args.serialization |
| 55 | )) |
| 56 | |
| 57 | has_next = reader.has_next |
| 58 | read_next = reader.read_next |
| 59 | write = writer.write |
| 60 | |
| 61 | gc_was_enabled = gc.isenabled() |
| 62 | if gc_was_enabled: |
| 63 | gc.disable() |
| 64 | try: |
| 65 | t0 = time.time() |
| 66 | count = 0 |
| 67 | while has_next(): |
| 68 | topic, data, ts = read_next() |
| 69 | write(topic, data, ts) |
| 70 | count += 1 |
| 71 | t1 = time.time() |
| 72 | finally: |
| 73 | if gc_was_enabled: |
| 74 | gc.enable() |
| 75 | gc.collect() |
| 76 | return t1 - t0, count |
| 77 | |
| 78 | |
| 79 | def run_cxx_copy(args: Args): |
no test coverage detected