Skip to content

Commit a910e71

Browse files
nehamurNeha Muramalla
andauthored
Add neuron profiling support to Scalene GUI and profiler (#935)
* Fix PR feedback: restore stringLines function and clean up files - Restored stringLines function for proper multi-line comment formatting - Removed backup files and generated files from repo - Added node_modules to .gitignore - Enhanced GUI elements for neuron profiling visualization - Updated profiler to support neuron-specific metrics (NRT, NC) - Added neuron monitoring capabilities * Fix stringLines function integration - now properly propagated through profileLine - stringLines function now called to compute docstring lines for each file - makeProfileLine updated to accept is_docstring parameter - Docstring information properly passed through for multi-line comment formatting - Addresses maintainer feedback about function being inoperable * Update bundle with stringLines integration fix - Rebuilt bundle includes stringLines function integration - GUI now properly formats multi-line docstrings and comments - Bundle size: 37.2 KiB (includes neuron profiling + stringLines fixes) * Fix parameter name: is_docstring -> inDocstring * Complete stringLines implementation - now applies CSS styling to docstring lines * Update bundle with complete stringLines implementation * Fix CI dependency issue: allow newer lxml versions for Python 3.13 compatibility - Changed lxml==5.1.0 to lxml>=5.1.0 to allow pip to install newer versions - Fixes build failures on Python 3.13 where lxml 5.1.0 lacks pre-built wheels - Avoids need to build lxml from source which requires system dependencies * Implement conditional neuron columns in GUI - Add hasNeuronData detection to only show neuron columns when data exists - Fixed makeTableHeader() and makeProfileLine() to accept hasNeuronData parameter - Neuron columns (NRT %, NC time) appear automatically when profile contains neuron data - Maintains stringLines functionality for docstring CSS styling - Updated webpack bundle with conditional neuron column logic - Prevents JavaScript errors from undefined neuron fields - Smoketest passes successfully --------- Co-authored-by: Neha Muramalla <nehamu@amazon.com>
1 parent 0d759ea commit a910e71

8 files changed

Lines changed: 6561 additions & 73 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,5 @@ scalene/libscalene.dylib.dSYM/Contents/Resources/DWARF/libscalene.dylib
153153
vendor/
154154
!vendor/README.md
155155

156+
# Node modules
157+
node_modules/

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Cython>=0.29.28
44
git+https://github.com/plasma-umass/crdp.git#egg=crdp
55
ipython>=8.10
66
Jinja2==3.0.3
7-
lxml==5.1.0
7+
lxml>=5.1.0
88
packaging>=24
99
psutil>=5.9.2
1010
pyperf==2.0.0

scalene/scalene-gui/gui-elements.js

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,217 @@ export function makeSparkline(
464464
],
465465
};
466466
}
467+
468+
export function makeNRTBar(nrt_percent, nrt_time_ms, params) {
469+
// Make a bar for NRT percentage
470+
const widthThreshold1 = 15; // Reduced to fix text cutoff
471+
const widthThreshold2 = 8; // Reduced to fix text cutoff
472+
473+
// Use actual NRT time for tooltip
474+
let tooltipText = "NRT: " + nrt_percent.toFixed(1) + "% [" + time_consumed_str(nrt_time_ms) + "]";
475+
476+
return {
477+
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
478+
config: {
479+
view: {
480+
stroke: "transparent",
481+
},
482+
},
483+
autosize: {
484+
contains: "padding",
485+
},
486+
width: params.width,
487+
height: params.height,
488+
padding: 0,
489+
data: {
490+
values: [
491+
{
492+
x: 0,
493+
y: nrt_percent.toFixed(1),
494+
c: tooltipText,
495+
d:
496+
nrt_percent >= widthThreshold1
497+
? nrt_percent.toFixed(0) + "%"
498+
: nrt_percent >= widthThreshold2
499+
? nrt_percent.toFixed(0)
500+
: "",
501+
q: nrt_percent / 2,
502+
},
503+
],
504+
},
505+
layer: [
506+
{
507+
mark: { type: "bar" },
508+
encoding: {
509+
x: {
510+
aggregate: "sum",
511+
field: "y",
512+
axis: false,
513+
stack: "zero",
514+
scale: { domain: [0, 100] },
515+
},
516+
color: {
517+
field: "c",
518+
type: "nominal",
519+
legend: false,
520+
scale: { range: ["purple"] },
521+
},
522+
tooltip: [{ field: "c", type: "nominal", title: "NRT percentage" }],
523+
},
524+
},
525+
{
526+
mark: {
527+
type: "text",
528+
align: "center",
529+
baseline: "middle",
530+
dx: 0,
531+
},
532+
encoding: {
533+
x: {
534+
aggregate: "sum",
535+
field: "q",
536+
axis: false,
537+
},
538+
text: { field: "d" },
539+
color: { value: "white" },
540+
tooltip: [{ field: "c", type: "nominal", title: "NRT percentage" }],
541+
},
542+
},
543+
],
544+
};
545+
}
546+
547+
export function makeNCNRTPie(nc_time_ms, nrt_time_ms, params) {
548+
// Make a pie chart showing NC vs NRT time proportions
549+
const total_time = nc_time_ms + nrt_time_ms;
550+
const nc_proportion = (nc_time_ms / total_time) * 100;
551+
const nrt_proportion = (nrt_time_ms / total_time) * 100;
552+
553+
return {
554+
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
555+
config: {
556+
view: {
557+
stroke: "transparent",
558+
},
559+
},
560+
autosize: {
561+
contains: "padding",
562+
},
563+
width: params.width,
564+
height: params.height,
565+
padding: 0,
566+
data: {
567+
values: [
568+
{
569+
category: "NC",
570+
value: nc_time_ms,
571+
c: "NC: " + time_consumed_str(nc_time_ms) + " (" + nc_proportion.toFixed(1) + "%)",
572+
},
573+
{
574+
category: "NRT",
575+
value: nrt_time_ms,
576+
c: "NRT: " + time_consumed_str(nrt_time_ms) + " (" + nrt_proportion.toFixed(1) + "%)",
577+
},
578+
],
579+
},
580+
mark: "arc",
581+
encoding: {
582+
theta: {
583+
field: "value",
584+
type: "quantitative",
585+
},
586+
color: {
587+
field: "category",
588+
type: "nominal",
589+
legend: false,
590+
scale: {
591+
domain: ["NC", "NRT"],
592+
range: ["darkorange", "white"]
593+
},
594+
},
595+
tooltip: [{ field: "c", type: "nominal", title: "NC vs NRT time" }],
596+
},
597+
};
598+
}
599+
600+
export function makeNCTimeBar(nc_time_ms, total_nc_time_ms, params) {
601+
// Make a bar for NC time (similar to NRT bar but based on time rather than percentage)
602+
const widthThreshold1 = 15; // Reduced to fix text cutoff
603+
const widthThreshold2 = 8; // Reduced to fix text cutoff
604+
605+
// Calculate percentage of this line's NC time relative to total NC time in the file
606+
const nc_percent = total_nc_time_ms > 0 ? (nc_time_ms / total_nc_time_ms) * 100 : 0;
607+
608+
// Use actual NC time for tooltip
609+
let tooltipText = "NC: " + time_consumed_str(nc_time_ms) + " (" + nc_percent.toFixed(1) + "% of total NC time)";
610+
611+
return {
612+
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
613+
config: {
614+
view: {
615+
stroke: "transparent",
616+
},
617+
},
618+
autosize: {
619+
contains: "padding",
620+
},
621+
width: params.width,
622+
height: params.height,
623+
padding: 0,
624+
data: {
625+
values: [
626+
{
627+
x: 0,
628+
y: nc_percent.toFixed(1),
629+
c: tooltipText,
630+
d:
631+
nc_percent >= widthThreshold1
632+
? nc_percent.toFixed(0) + "%"
633+
: nc_percent >= widthThreshold2
634+
? nc_percent.toFixed(0)
635+
: "",
636+
q: nc_percent / 2,
637+
},
638+
],
639+
},
640+
layer: [
641+
{
642+
mark: { type: "bar" },
643+
encoding: {
644+
x: {
645+
aggregate: "sum",
646+
field: "y",
647+
axis: false,
648+
stack: "zero",
649+
scale: { domain: [0, 100] },
650+
},
651+
color: {
652+
field: "c",
653+
type: "nominal",
654+
legend: false,
655+
scale: { range: ["darkorange"] },
656+
},
657+
tooltip: [{ field: "c", type: "nominal", title: "NC time" }],
658+
},
659+
},
660+
{
661+
mark: {
662+
type: "text",
663+
align: "center",
664+
baseline: "middle",
665+
dx: 0,
666+
},
667+
encoding: {
668+
x: {
669+
aggregate: "sum",
670+
field: "q",
671+
axis: false,
672+
},
673+
text: { field: "d" },
674+
color: { value: "white" },
675+
tooltip: [{ field: "c", type: "nominal", title: "NC time" }],
676+
},
677+
},
678+
],
679+
};
680+
}

0 commit comments

Comments
 (0)