mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-07-01 04:07:56 +00:00
101 lines
3.0 KiB
Python
101 lines
3.0 KiB
Python
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
"""
|
|
Trace Analysis - Tools for analyzing Clang -ftime-trace build data.
|
|
|
|
This module provides high-performance tools for parsing and analyzing JSON
|
|
trace files generated by Clang's -ftime-trace feature, with support for
|
|
template relationship analysis and build timeline visualization.
|
|
|
|
Key components:
|
|
- TraceParser: Fast JSON parsing with orjson support
|
|
- TraceTransformer: Convert parsed events to pandas DataFrames
|
|
- TemplateParser: Parse C++ template signatures and relationships
|
|
- NinjaLogParser: Parse ninja build logs for timeline analysis
|
|
- TraceFile: Model for trace file metadata
|
|
- Models: Data structures for templates, builds, and statistics
|
|
|
|
Example - Basic Usage:
|
|
from pathlib import Path
|
|
from trace_analysis import TraceFile, TraceParser, TraceTransformer
|
|
|
|
# Parse a single file
|
|
trace_file = TraceFile.from_path(Path("build.json"))
|
|
events = TraceParser.parse(trace_file)
|
|
events_df = TraceTransformer.to_events_dataframe(events)
|
|
|
|
# Analyze template instantiations
|
|
templates_df = TraceTransformer.to_templates_dataframe(events)
|
|
print(f"Total template time: {templates_df['dur'].sum() / 1e6:.2f}s")
|
|
|
|
Example - Enhanced Schema with Template Relationships:
|
|
from trace_analysis import TraceParser, TraceTransformer
|
|
|
|
events = TraceParser.parse(trace_file)
|
|
schema = TraceTransformer.to_enhanced_schema(events, file_id=0)
|
|
|
|
# Access multi-table schema
|
|
templates_df = schema['templates']
|
|
instantiations_df = schema['instantiations']
|
|
template_args_df = schema['template_args']
|
|
|
|
# Find template dependencies
|
|
deps = template_args_df.merge(
|
|
templates_df[['template_id', 'template_name']],
|
|
on='template_id'
|
|
)
|
|
|
|
Example - Build Timeline Analysis:
|
|
from trace_analysis import NinjaLogParser
|
|
|
|
builds = NinjaLogParser.parse(Path('.ninja_log'))
|
|
builds_df = NinjaLogParser.to_dataframe(builds)
|
|
builds_df = NinjaLogParser.assign_workers(builds_df)
|
|
|
|
# Analyze worker utilization
|
|
worker_stats = NinjaLogParser.compute_worker_stats(builds_df)
|
|
"""
|
|
|
|
from .models import (
|
|
TraceFile,
|
|
NinjaBuild,
|
|
CompilationTimeline,
|
|
Template,
|
|
TemplateArgument,
|
|
FileMetadata,
|
|
TemplateInstantiation,
|
|
BuildStatistics,
|
|
)
|
|
from .parser import TraceParser
|
|
from .transformer import TraceTransformer
|
|
from .template_parser import TemplateParser
|
|
from .ninja_parser import NinjaLogParser
|
|
from .chrome_trace import ChromeTraceExporter
|
|
from .utils import find_trace_files
|
|
|
|
__all__ = [
|
|
# Core parsing and transformation
|
|
"TraceFile",
|
|
"TraceParser",
|
|
"TraceTransformer",
|
|
# Template analysis
|
|
"TemplateParser",
|
|
"Template",
|
|
"TemplateArgument",
|
|
"TemplateInstantiation",
|
|
# Build timeline
|
|
"NinjaLogParser",
|
|
"NinjaBuild",
|
|
"CompilationTimeline",
|
|
# Chrome Trace export
|
|
"ChromeTraceExporter",
|
|
# Metadata and statistics
|
|
"FileMetadata",
|
|
"BuildStatistics",
|
|
# Utilities
|
|
"find_trace_files",
|
|
]
|
|
|
|
__version__ = "2.0.0"
|