MCPcopy Create free account
hub / github.com/FastLED/FastLED / _generate_profiler

Method _generate_profiler

ci/profile/generate_profile_test.py:95–177  ·  view source on GitHub ↗

Generate C++ profiler code from template

(self, signature: dict[str, Any] | None)

Source from the content-addressed store, hash-verified

93 return None
94
95 def _generate_profiler(self, signature: dict[str, Any] | None) -> str:
96 """Generate C++ profiler code from template"""
97 if signature:
98 target_call = f"{signature['namespace']}::{signature['function_name']}"
99 header_include = f'#include "{signature["header"]}"'
100 else:
101 # Fallback for unknown signatures
102 target_call = self.target
103 header_include = '#include "FastLED.h"'
104
105 return f'''// Auto-generated profiler for {self.target}
106// Generated by: ci/profile/generate_profile_test.py
107
108#include "FastLED.h"
109{header_include}
110#include "fl/stl/cstring.h"
111#include "fl/stl/stdio.h"
112
113using namespace fl;
114
115// Benchmark configuration
116static const int WARMUP_ITERATIONS = 1000;
117static const int PROFILE_ITERATIONS = 100000;
118
119// IMPORTANT: Customize this benchmark for your specific function
120// This is a template - you need to:
121// 1. Define appropriate test inputs
122// 2. Call the target function correctly
123// 3. Ensure volatile prevents optimization
124
125__attribute__((noinline))
126void benchmarkBaseline() {{
127 // TODO: Customize this for {self.target}
128 // Example for a simple function:
129 volatile int result = 0;
130 for (int i = 0; i < PROFILE_ITERATIONS; i++) {{
131 // result = {target_call}(test_input);
132 result += i; // Placeholder - replace with actual call
133 }}
134 (void)result; // Prevent optimization
135}}
136
137int main(int argc, char *argv[]) {{
138 bool do_baseline = true;
139
140 if (argc > 1) {{
141 if (fl::strcmp(argv[1], "baseline") == 0) {{
142 do_baseline = true;
143 }} else if (fl::strcmp(argv[1], "optimized") == 0) {{
144 do_baseline = false;
145 fl::printf("Error: Optimized variant not implemented yet\\n");
146 return 1;
147 }}
148 }}
149
150 // Warmup
151 for (int i = 0; i < WARMUP_ITERATIONS / PROFILE_ITERATIONS; i++) {{
152 benchmarkBaseline();

Callers 1

generateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected