(evidence, tool, path, label, environment, root, unavailable=False)
| 445 | |
| 446 | |
| 447 | def _convert(evidence, tool, path, label, environment, root, unavailable=False): |
| 448 | try: |
| 449 | raw = _read(path, evidence.args.max_profile_bytes) |
| 450 | except OSError as error: |
| 451 | if unavailable and error.errno in (errno.EACCES, errno.EPERM, errno.ENOENT): |
| 452 | evidence.uncertainty.append({"path": path, "reason": "profile_unreadable"}) |
| 453 | return None |
| 454 | raise |
| 455 | snapshot = evidence.write("evidence/" + label + ".profraw", raw) |
| 456 | raw_digest = hashlib.sha256(raw).hexdigest() |
| 457 | record, text = _run(evidence, label, [tool, "merge", "--instr", "--text", "--failure-mode=any", |
| 458 | "--num-threads=1", "--output=-", snapshot], |
| 459 | environment, evidence.args.conversion_timeout, root) |
| 460 | record["input"] = {"path": path, "snapshot": snapshot, "sha256": raw_digest, |
| 461 | "bytes": len(raw)} |
| 462 | _required(record) |
| 463 | if hashlib.sha256(_read(snapshot, evidence.args.max_profile_bytes)).hexdigest() != raw_digest: |
| 464 | _error("identity", "conversion input changed") |
| 465 | evidence.converted_bytes += len(text) |
| 466 | if evidence.converted_bytes > evidence.args.max_total_profile_bytes: |
| 467 | _error("resource_limit", "aggregate converted byte limit exceeded") |
| 468 | # Reject malformed transport, even though the pure producer can represent |
| 469 | # unavailable/malformed observations conservatively. Unknown identities and |
| 470 | # counter-shape incompatibilities are rejected by the producer's full join. |
| 471 | deadline = time.monotonic() + evidence.args.reduction_timeout |
| 472 | parse_profile_text(text, ParseLimits(evidence.args.max_output_bytes, RECORD_CAP, |
| 473 | COUNTER_CAP, NAME_CAP), |
| 474 | cancel=lambda _: time.monotonic() >= deadline) |
| 475 | return text |
| 476 | |
| 477 | |
| 478 | def _scope(registry, requested, available): |
no test coverage detected