# Profiles

A profile is a collection of settings and rules, which govern agents. It tells agents what data and metrics should be collected. Each profile needs to be activated to be eligible for deployment to agents. Which profile goes to which agent is determined by assigning applications to the profiles. There is a one-to-one correspondence between profiles and applications. In other words, the agents are not assigned to profiles directly.

## Profile State Machine

Every profile can be in one of three states: <mark style="color:blue;">`draft`</mark>, <mark style="color:orange;">`ready`</mark> or <mark style="color:green;">`deployed`</mark>.&#x20;

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FyHcMrbIOeBpeNqEesK1V%2Fpsm.svg?alt=media&#x26;token=92ad44e5-1ae7-452c-bd07-046759a14cd8" alt=""><figcaption><p>Profile State Machine</p></figcaption></figure>

State-to-state connections refer to operations that are allowed on the states they originate from.

## Managing Profiles

Profiles are managed on the <mark style="color:blue;">`Profiles`</mark> page.

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FjOsYd5yhYokXxr8AY4yS%2Fprofiles.png?alt=media&#x26;token=49a990af-fdc8-4a78-b207-00035a7c4ec4" alt=""><figcaption><p>Profiles View</p></figcaption></figure>

To add a new profile, you must select the <mark style="color:blue;">`New`</mark> item from the <mark style="color:blue;">`Options`</mark> menu, specify a name for the profile and press the <mark style="color:blue;">`Save`</mark> button. Next, you can click the profile name in the list to view its [details](#profile-details). To refresh the profiles list, just select the <mark style="color:blue;">`Refresh`</mark> item from the <mark style="color:blue;">`Options`</mark> menu.

{% hint style="info" %}
A profile can be deleted only in the profile details page.
{% endhint %}

## Profile

The profile details page contains a selected profile detailed information, such as its settings, instrumentation rules and JMX list of MBeans.

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FCAsmrdqFTWLL762NlrtB%2Fprofile.png?alt=media&#x26;token=2130d157-3ac8-4373-a244-77dbce185c21" alt=""><figcaption><p>Profile details view</p></figcaption></figure>

### Profile Settings

Each profile has some settings, which are either instrumentation or JMX related. The instrumentation settings are:

* **`CPU Time`** this option enables/disables CPU time metric,
* **`Automatic tuning`** this option sets one of the three available automatic tuning modes: `light`, `moderate` or `aggressive`. Automatic tuning is a feature which drops irrelevant method invocation reports automatically. If you want the automatic tuning algorithm to pass more methods invocation data from agents, just select the `light` mode. If you want to have less data, select higher modes like `moderate` or `aggressive`.
* **`JMX Period`** this option sets the time interval at which JMX data is collected.

### Instrumentation Rules

In order to make a profile deployable, you must define some instrumentation rules. You can do this in the <mark style="color:blue;">`Instrumentation rules`</mark> tab.

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FiroAfkoEmQpQBpIhFEUq%2Firules_add.png?alt=media&#x26;token=618cfd14-2763-41b2-aa9b-e921fae10213" alt=""><figcaption><p>Empty Instrumentation Rules View</p></figcaption></figure>

Here, you can define your rules which can be either inclusive or exclusive (see [Rules](https://docs.flopsar.com/5.1/user-guide/instrumentation#rules) for details).

#### Inclusive Rules

Inclusive rules are the ones that precisely define what classes and methods should be instrumented. To add such a rule, just press the <mark style="color:blue;">`Inclusive Rule`</mark> button. A dialog window, with the rules wizard, should open then.

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2F5P8VxF4zgZA2EsIaST7j%2Finclude_wizard.png?alt=media&#x26;token=5c716b85-0980-4554-a979-5d8ea458fe35" alt=""><figcaption><p>Inclusion Rule Wizard</p></figcaption></figure>

The wizard is composed of three steps. In the first step, you need to specify what classes should be taken. The following options are available for the <mark style="color:blue;">`Class level pattern`</mark>:

* **`Package`** the pattern is a name of a package that classes should belong to, e.g. `com.foo.bar`
* **`Classname`** the pattern is a fully qualified class name. Only those classes will be taken into account whose name matches the specified pattern, e.g. `com.foo.bar.MyClass`
* **`Superclass`** the pattern is a fully qualified name of a class that classes should inherit from. Only those classes will be taken into account which inherit from the specified class directly, e.g. `com.foo.bar.MyClass`
* **`Interface`** the pattern is a fully qualified name of an interface that classes should implement directly. Only those classes will be taken into account which implement the specified interface, e.g. `com.foo.bar.MyInterface`

In the second step, you need to specify which methods should be instrumented.&#x20;

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FBfHnGxi2nxKa3pFGrIRi%2Finclude_wizard2.png?alt=media&#x26;token=36334165-f5e0-4db8-8f74-77b9ec2226ae" alt=""><figcaption><p>Inclusion Rule Wizard</p></figcaption></figure>

There are three ways you can choose from to specify the filter for methods for the <mark style="color:blue;">`Pattern type`</mark>:

* **`Access Modifiers`** use this pattern to select only those methods whose access modifier is at least one of the chosen modifiers&#x20;
* **`Name`** use this pattern to select only those methods whose name matches the specified value in the <mark style="color:blue;">`Pattern`</mark> field
* **`Name & Signature`** use this pattern to select only those methods whose name and signature matches the specified value exactly in the <mark style="color:blue;">`Name and Signature`</mark> field.

{% hint style="info" %}
For **`Name & Signature`** option you must specify the value in the same way you would do it in your source code, except you must specify fully qualified names for classes here.
{% endhint %}

In the last step, you need to specify what kind of action should be performed when the instrumented method is to be executed.

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FUKyiksMlgiMOn5yiuxWR%2Finclude_wizard3.png?alt=media&#x26;token=cbb93f8e-6571-4c97-aa91-c50676554c79" alt=""><figcaption><p>Inclusion Rule WIzard</p></figcaption></figure>

#### Actions

Suppose you have a class defined below and the method `someMethod` is instrumented. You must select one action handler for your rule.&#x20;

{% code title="SampleClass.java" overflow="wrap" lineNumbers="true" %}

```java
public class SampleClass {

    public int someField;    
    private long someField2;
    private Foo someField3;
    
    public void someMethod(String arg1, int arg2, Bar arg3) {
        /* method block */ 
    }
}
```

{% endcode %}

{% hint style="info" %}
Not all actions are available since their availability depends on the selected <mark style="color:blue;">`Pattern type`</mark> in the previous step.
{% endhint %}

What you get depends on the selected action handler. You have five choices at your disposal for the <mark style="color:blue;">`Action handler`</mark>:

<mark style="color:blue;">**Basic**</mark>

This action will report only the fact that a method has been called along with some basic information like duration, timestamp etc.&#x20;

<mark style="color:blue;">**Standard**</mark>&#x20;

This action will report the same data as the above action and method arguments additionally. The method arguments will be presented as a result of executing `String.valueOf` function on each one of them. In the case of the sample class you will get:

```java
// SomeClass instance
String.valueOf(this)
// someMethod arguments
arg1 
arg2 
String.valueOf(arg3)
```

<mark style="color:blue;">**Finer Standard**</mark>&#x20;

This action is an extended version of the action above. Additionally, if the method is an instance method it will report values of the instance object fields. Static fields will not be reported.  In the case of the sample class you will get:

```java
// SomeClass instance fields
someField
someField2
String.valueOf(someField3)
// someMethod arguments
arg1 
arg2 
String.valueOf(arg3)
```

<mark style="color:blue;">**Finest Standard**</mark>&#x20;

This action is similar to the action above but in this case, if an argument is an object, its instance fields will be reported instead of its value. Static fields will not be reported. In the case of the sample class you will get:

```java
// SomeClass instance fields
someField
someField2
String.valueOf(someField3)
// methodSample arguments fields if any
arg1
arg2
// Bar instance fields
barField1
barField2
...
```

<mark style="color:blue;">**Custom**</mark>&#x20;

This action will execute a user defined custom code that is provided by the agent extensions and report its output along with the basic information. In this case, you decide what you get by defining your own [agent extension](https://docs.flopsar.com/5.1/developer-guide/agent-extensions).&#x20;

{% hint style="warning" %}
Please note, <mark style="color:blue;">Finer Standard</mark> and <mark style="color:blue;">Finest Standard</mark> can degrade your code execution performance so use it carefully. <mark style="color:blue;">Custom</mark> handler can do this also if your implementation is poor.&#x20;
{% endhint %}

#### Additional Features

Depending on the selected <mark style="color:blue;">`Action handler`</mark>, there are some additional features you can select in the <mark style="color:blue;">`Features`</mark> section:

* **`Always report`** this feature makes all the instrumented methods ignore the automatic tuning in the profile [settings](#profile-settings)
* **`Instrument on exit`** this feature injects the instrumentation code at the end of the method body

Additionally, if you selected the **`Execute custom code`** option, you will need to specify both a class name and a method name of your custom extension code, the agent is about to inject, in the <mark style="color:blue;">`User-defined extension`</mark> section. A fully qualified name for the <mark style="color:blue;">`Class name`</mark> field is required and a method name for the <mark style="color:blue;">`Method name`</mark> field.

If you are done with the rule, press the <mark style="color:blue;">`Save`</mark> button to add the rule to the instrumentation rules list.

#### Exclusive Rules

By default, those methods are instrumented which fulfill the conditions defined by the inclusive rules. However, sometimes these rules are too wide, i.e. they let too many methods or classes in. In order to exclude some classes and methods from instrumentation, you need to define exclusive rules. You can do it by pressing the <mark style="color:blue;">`Exclusive Rule`</mark> button. A new popup window will appear then.

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FEaWjLQvM3GNr6bvTeA4g%2Fexclude_wizard.png?alt=media&#x26;token=a2aaca2a-adc8-48c6-ace2-647d420b2c71" alt=""><figcaption><p>Exclusion Rule Form</p></figcaption></figure>

To add a new rule, you need to specify both class and method patterns. The following options are available for the <mark style="color:blue;">`Class level pattern`</mark>:

* **`Package`** the pattern is a name of a package that classes should belong to. Only those classes will be excluded from instrumentation which belong to the specified package.
* **`Classname`** the pattern is a fully qualified class name. Only those classes will be excluded from instrumentation whose name matches the specified pattern, e.g. `com.foo.bar.MyClass`
* **`Superclass`** the pattern is a fully qualified name of a class that classes should inherit from. Only those classes will be excluded from instrumentation which inherit from the specified class directly, e.g. `com.foo.bar.MyClass`
* **`Interface`** the pattern is a fully qualified name of an interface that classes should implement directly. Only those classes will be excluded from instrumentation which implement the specified interface, e.g. `com.foo.bar.MyInterface`

For the <mark style="color:blue;">`Method level pattern`</mark> you need to specify one of the following options:

* **`Method name`** those methods will be excluded from instrumentation whose name matches the specified value in the <mark style="color:blue;">`Pattern`</mark> field
* **`Method signature`** those methods will be excluded from instrumentation whose signature matches exactly the one specified in the <mark style="color:blue;">`Pattern`</mark> field

{% hint style="info" %}
If you want to exclude all methods from a class, select the **`Method name`** pattern, put <mark style="color:orange;">`.*`</mark> into the <mark style="color:blue;">`Pattern`</mark> and select the <mark style="color:blue;">`regex`</mark> option.
{% endhint %}

If you are done with the rule, press the <mark style="color:blue;">`Save`</mark> button to add the rule to the instrumentation rules list.

#### List of Rules

When you add new rules, they are presented in a list. The rules are evaluated in the order of their appearance in the list (see [Rules Evaluation Order](https://docs.flopsar.com/5.1/user-guide/instrumentation#rules-evaluation-order) for more details).

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FjRvaDHxByl4R90K9w86b%2Firules.png?alt=media&#x26;token=d0ebda0c-9d60-45b1-a138-85ea21ca75e3" alt=""><figcaption><p>Instrumentation Rules</p></figcaption></figure>

You can click each rule to see its details. Exclusive rules are denoted by red squares, while inclusive ones are denoted by green squares. If you want to edit a rule, just click the pencil icon in the right down corner of the selected rule. If you want to delete a rule, click the trash icon in the right down corner of the selected rule. To clone a rule, click the copy icon in the right down corner of the selected rule. A rule can be in one of the two states: enabled or disabled. You can switch the rule state by clicking the <mark style="color:blue;">`Enable rule`</mark> switch. When a rule is disabled, it will not be deployed to agents. Each rule has also a description, which is self-explanatory.

### JMX

This view enables specifying which MBeans values you want to collect. To add MBeans, you need to retrieve them from agents first. You can do this by pressing the <mark style="color:blue;">`Add ObjectNames`</mark> button.&#x20;

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FXKyFQ1Qf7hPoPKpgQvyQ%2Fjmx.png?alt=media&#x26;token=5303874d-3cd9-42d3-bd1a-d920cdda0260" alt=""><figcaption><p>JMX View</p></figcaption></figure>

This operation will open a new popup window.

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FwgIwrUSg0Ib8F8VYQJyg%2Fjmx2.png?alt=media&#x26;token=9e45ee00-57eb-40a3-8821-7a31378d3372" alt=""><figcaption></figcaption></figure>

Next, press the <mark style="color:blue;">`Refresh`</mark> button to retrieve the MBeans.

{% hint style="info" %}
You must first assign an application to your profile to be able to retrieve MBeans from the connected agents.
{% endhint %}

<figure><img src="https://4184112761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1l0Vb5GSU1RRV2waQeIU%2Fuploads%2FZ54Rgtk5ulQqzB44XgwA%2Fmbeans.png?alt=media&#x26;token=376afb23-47b0-4555-a685-6ad60ded3930" alt=""><figcaption></figcaption></figure>

Now, you can press the <mark style="color:blue;">`Add`</mark> button for any MBean you want to select. When you are done with adding the MBeans either click outside the popup window or press the **`Escape`** button to close the popup window.&#x20;

### Deploying a Profile

To deploy a profile, a few conditions must be fulfilled. The profile must have instrumentation rules defined, must be assigned to an application and be in the <mark style="color:orange;">`ready`</mark> state.
