Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiler format should be flexible enough to support recording multiple metric types #16

Open
nolanmar511 opened this issue Apr 5, 2019 · 0 comments

Comments

@nolanmar511
Copy link

The currently proposed profile format works for recording CPU profiles, where a single sample can be correlated to the amount of CPU time. It might be good, though, to add fields which can be used to track specific metrics associated with each sample (like number of samples, or seconds of CPU time).

There are two benefits to modifying the profile to support tracking more specific metrics. First, it would not be necessary for users to check profiler.options.sampleInterval to determine the CPU time associated with each sample, since this information would be a part of the profile. Next, tracking specific metrics could make it easier to extend this profile format so it could be used to record other profile types (for example, for heap profiles one would want to track objects allocated and bytes allocated).

To support this, I’d propose modifications like the following could be made to the proposed profile format:

  1. Add a "metricTypes" field to the profile, to track the type of each recorded metric. This field will be an array of objects which specify the unit and types for each metric.

    • For example, for a CPU profile, the "metricTypes" would be:

      "metricTypes": [
        {
          "metric": "samples",
          "unit": "count"
        },
        {
          "metric": "time",
          "unit": "ms"
        }
      ]
    • If, in the future, this format were used to record heap profiles, the "metricTypes" field would be:

      "metricTypes": [
        {
          "metric": "space",
          "unit": "bytes"
        },
        {
          "metric": "objects",
          "unit": "count"
        }
      ]
  2. Then, in the sample in the "samples" field, there would be an array, "metrics", recording the value for each metric for that sample. The length of the array for "metricTypes" would be the same as the length of the "metrics" array for each sample.

    For example, if "metricTypes" were:

         "metricTypes": [
           {
             "metric": "samples",
             "unit": "count"
           },
           {
             "metric": "time",
             "unit": "ms"
           }
        ]

    The samples might look like for a profile which sampled every 1ms:

          "samples" : [
              {
                  "timestamp" : 1551.73499998637,
                 "stackId": 2,
                 "metric": [2, 2000]
              },
              {
         	 "timestamp" : 1601.12966798137,
                 "stackId": 1,
                 "metric": [5, 5000],
              },
           ]

Full example profile:

{
  "metricTypes": [
    {
      "metric": "samples",
       "unit": "count"
    },
    {
      "metric": "CPU time",
      "unit": "microsecond"
    }
  ],
  "stacks" : [
    {
       "frameId" : 0
    },
    {
      "frameId" : 1,
      "parentId" : 0
    },
    {
      "frameId" : 2,
      "parentId" : 1
    },
  ],
  "samples" : [
    {
      "timestamp" : 1551.73499998637,
      "stackId": 2,
      "metric": [2, 2000],
    },
    {
      "timestamp" : 1601.12966798137,
      "stackId": 1,
      "metric": [5, 5000],
    },
  ],
  "frames" : [
    {
      "name" : "b",
      "uri" : "https://static.xx.fbcdn.net/rsrc.php/v3/yW/r/ZgaPtFDHPeq.js",
      "line" : 23,
      "column" : 169,
    },
    {
      "name" : "l",
      "uri" : "https://static.xx.fbcdn.net/rsrc.php/v3iMKu4/yW/l/en_US-i/gSq3sO3PcU1.js",
      "line" : 313,
      "column" : 468,
    },
    {
      "uri" : "https://static.xx.fbcdn.net/rsrc.php/v3iMKu4/yW/l/en_US-i/gSq3sO3PcU1.js",
      "line" : 313,
      "name" : "a",
      "column" : 1325
    },
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant