Skip to content

tracer_context

TracerContext dataclass

This context will be used by tracer to store any data that is needed after the tracer has exited. This will hold reference to any internal dicts that are used outside the tracer and its session.

Source code in lineapy/instrumentation/tracer_context.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@dataclass
class TracerContext:
    """
    This context will be used by tracer to store any data that is needed after the tracer has exited.
    This will hold reference to any internal dicts that are used outside the tracer and its session.
    """

    db: RelationalLineaDB
    session_context: SessionContext

    @classmethod
    def reload_session(
        cls, db: RelationalLineaDB, session_id: LineaID
    ) -> "TracerContext":
        session_context = db.get_session_context(session_id)
        return cls(db, session_context)

    def get_session_id(self) -> LineaID:
        return self.session_context.id

    @property
    def graph(self) -> Graph:
        """
        Creates a graph by fetching all the nodes about this session from the DB.
        """
        nodes = self.db.get_nodes_for_session(self.get_session_id())
        return Graph(nodes, self.session_context)

    def session_artifacts(self) -> List[ArtifactORM]:
        return self.db.get_artifacts_for_session(self.get_session_id())

    @property
    def artifacts(self) -> Dict[str, str]:
        """
        Returns a mapping of artifact names to their sliced code.
        """

        return {
            artifact.name: str(
                get_program_slice(self.graph, [artifact.node_id])
            )
            for artifact in self.session_artifacts()
            if artifact.name is not None
        }

    def slice(self, name: str) -> str:
        artifact = self.db.get_artifactorm_by_name(name)
        return str(get_program_slice(self.graph, [artifact.node_id]))

artifacts: Dict[str, str] property

Returns a mapping of artifact names to their sliced code.

graph: Graph property

Creates a graph by fetching all the nodes about this session from the DB.


Was this helpful?

Help us improve docs with your feedback!