# ProfilerModuleViewController(ProfilerWindow)

> Initializes and returns an instance of ProfilerModuleViewController.

## Definition

* **Type:** Constructor
* **Namespace:** [Unity.Profiling.Editor](/engine/6000.6/script-reference/unity/profiling/editor.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
protected ProfilerModuleViewController(ProfilerWindow profilerWindow)
```

### Parameters

**** (\[ProfilerWindow]\(/engine/6000.6/script-reference/unityeditor/profilerwindow)): The Profiler window that the view controller and its Profiler module belong to.

### Remarks

You must invoke the base [ProfilerModuleViewController](/engine/6000.6/script-reference/unity/profiling/editor/profilermoduleviewcontroller.md) constructor from a derived view controller’s constructor.

```csharp
using Unity.Profiling.Editor;
using UnityEditor;
using UnityEngine.UIElements;

public class SingleCounterViewController : ProfilerModuleViewController
{
    ProfilerCounterDescriptor m_Counter;
    Label m_CounterLabel;

    public SingleCounterViewController(ProfilerWindow profilerWindow, ProfilerCounterDescriptor counter) : base(profilerWindow)
    {
        m_Counter = counter;
    }

    protected override VisualElement CreateView()
    {
        // Create a simple view with a single label.
        var view = new VisualElement();
        m_CounterLabel = new Label();
        view.Add(m_CounterLabel);

        // Subscribe to Profiler window SelectedFrameIndexChanged event.
        ProfilerWindow.SelectedFrameIndexChanged += OnSelectedFrameIndexChanged;

        // Populate label with counter value in selected frame.
        ReloadData();

        return view;
    }

    protected override void Dispose(bool disposing)
    {
        if (!disposing)
            return;

        // Unsubscribe from Profiler window SelectedFrameIndexChanged event.
        ProfilerWindow.SelectedFrameIndexChanged -= OnSelectedFrameIndexChanged;

        base.Dispose(disposing);
    }

    void OnSelectedFrameIndexChanged(long selectedFrame)
    {
        // Update label with counter value in selected frame.
        ReloadData();
    }

    void ReloadData()
    {
        // Update label text with formatted counter value in selected frame.
        var selectedFrameIndexInt32 = System.Convert.ToInt32(ProfilerWindow.selectedFrameIndex);
        var formattedCounterValue = UnityEditorInternal.ProfilerDriver.GetFormattedCounterValue(selectedFrameIndexInt32, m_Counter.CategoryName, m_Counter.Name);
        m_CounterLabel.text = $"{m_Counter}: {formattedCounterValue}";
    }
}
```

Additional Resources: [ProfilerWindow.SelectedFrameIndexChanged](/engine/6000.6/script-reference/unityeditor/profilerwindow/selectedframeindexchanged.md), [ProfilerModule](/engine/6000.6/script-reference/unity/profiling/editor/profilermodule.md), [ProfilerCounterDescriptor](/engine/6000.6/script-reference/unity/profiling/editor/profilercounterdescriptor.md).
