{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CodeGuruProfiler.Types.FrameMetric
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CodeGuruProfiler.Types.FrameMetric where

import Amazonka.CodeGuruProfiler.Types.MetricType
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | The frame name, metric type, and thread states. These are used to derive
-- the value of the metric for the frame.
--
-- /See:/ 'newFrameMetric' smart constructor.
data FrameMetric = FrameMetric'
  { -- | Name of the method common across the multiple occurrences of a frame in
    -- an application profile.
    FrameMetric -> Text
frameName :: Prelude.Text,
    -- | List of application runtime thread states used to get the counts for a
    -- frame a derive a metric value.
    FrameMetric -> [Text]
threadStates :: [Prelude.Text],
    -- | A type of aggregation that specifies how a metric for a frame is
    -- analyzed. The supported value @AggregatedRelativeTotalTime@ is an
    -- aggregation of the metric value for one frame that is calculated across
    -- the occurrences of all frames in a profile.
    FrameMetric -> MetricType
type' :: MetricType
  }
  deriving (FrameMetric -> FrameMetric -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FrameMetric -> FrameMetric -> Bool
$c/= :: FrameMetric -> FrameMetric -> Bool
== :: FrameMetric -> FrameMetric -> Bool
$c== :: FrameMetric -> FrameMetric -> Bool
Prelude.Eq, ReadPrec [FrameMetric]
ReadPrec FrameMetric
Int -> ReadS FrameMetric
ReadS [FrameMetric]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FrameMetric]
$creadListPrec :: ReadPrec [FrameMetric]
readPrec :: ReadPrec FrameMetric
$creadPrec :: ReadPrec FrameMetric
readList :: ReadS [FrameMetric]
$creadList :: ReadS [FrameMetric]
readsPrec :: Int -> ReadS FrameMetric
$creadsPrec :: Int -> ReadS FrameMetric
Prelude.Read, Int -> FrameMetric -> ShowS
[FrameMetric] -> ShowS
FrameMetric -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FrameMetric] -> ShowS
$cshowList :: [FrameMetric] -> ShowS
show :: FrameMetric -> String
$cshow :: FrameMetric -> String
showsPrec :: Int -> FrameMetric -> ShowS
$cshowsPrec :: Int -> FrameMetric -> ShowS
Prelude.Show, forall x. Rep FrameMetric x -> FrameMetric
forall x. FrameMetric -> Rep FrameMetric x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FrameMetric x -> FrameMetric
$cfrom :: forall x. FrameMetric -> Rep FrameMetric x
Prelude.Generic)

-- |
-- Create a value of 'FrameMetric' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'frameName', 'frameMetric_frameName' - Name of the method common across the multiple occurrences of a frame in
-- an application profile.
--
-- 'threadStates', 'frameMetric_threadStates' - List of application runtime thread states used to get the counts for a
-- frame a derive a metric value.
--
-- 'type'', 'frameMetric_type' - A type of aggregation that specifies how a metric for a frame is
-- analyzed. The supported value @AggregatedRelativeTotalTime@ is an
-- aggregation of the metric value for one frame that is calculated across
-- the occurrences of all frames in a profile.
newFrameMetric ::
  -- | 'frameName'
  Prelude.Text ->
  -- | 'type''
  MetricType ->
  FrameMetric
newFrameMetric :: Text -> MetricType -> FrameMetric
newFrameMetric Text
pFrameName_ MetricType
pType_ =
  FrameMetric'
    { $sel:frameName:FrameMetric' :: Text
frameName = Text
pFrameName_,
      $sel:threadStates:FrameMetric' :: [Text]
threadStates = forall a. Monoid a => a
Prelude.mempty,
      $sel:type':FrameMetric' :: MetricType
type' = MetricType
pType_
    }

-- | Name of the method common across the multiple occurrences of a frame in
-- an application profile.
frameMetric_frameName :: Lens.Lens' FrameMetric Prelude.Text
frameMetric_frameName :: Lens' FrameMetric Text
frameMetric_frameName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FrameMetric' {Text
frameName :: Text
$sel:frameName:FrameMetric' :: FrameMetric -> Text
frameName} -> Text
frameName) (\s :: FrameMetric
s@FrameMetric' {} Text
a -> FrameMetric
s {$sel:frameName:FrameMetric' :: Text
frameName = Text
a} :: FrameMetric)

-- | List of application runtime thread states used to get the counts for a
-- frame a derive a metric value.
frameMetric_threadStates :: Lens.Lens' FrameMetric [Prelude.Text]
frameMetric_threadStates :: Lens' FrameMetric [Text]
frameMetric_threadStates = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FrameMetric' {[Text]
threadStates :: [Text]
$sel:threadStates:FrameMetric' :: FrameMetric -> [Text]
threadStates} -> [Text]
threadStates) (\s :: FrameMetric
s@FrameMetric' {} [Text]
a -> FrameMetric
s {$sel:threadStates:FrameMetric' :: [Text]
threadStates = [Text]
a} :: FrameMetric) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A type of aggregation that specifies how a metric for a frame is
-- analyzed. The supported value @AggregatedRelativeTotalTime@ is an
-- aggregation of the metric value for one frame that is calculated across
-- the occurrences of all frames in a profile.
frameMetric_type :: Lens.Lens' FrameMetric MetricType
frameMetric_type :: Lens' FrameMetric MetricType
frameMetric_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FrameMetric' {MetricType
type' :: MetricType
$sel:type':FrameMetric' :: FrameMetric -> MetricType
type'} -> MetricType
type') (\s :: FrameMetric
s@FrameMetric' {} MetricType
a -> FrameMetric
s {$sel:type':FrameMetric' :: MetricType
type' = MetricType
a} :: FrameMetric)

instance Data.FromJSON FrameMetric where
  parseJSON :: Value -> Parser FrameMetric
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FrameMetric"
      ( \Object
x ->
          Text -> [Text] -> MetricType -> FrameMetric
FrameMetric'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"frameName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"threadStates" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"type")
      )

instance Prelude.Hashable FrameMetric where
  hashWithSalt :: Int -> FrameMetric -> Int
hashWithSalt Int
_salt FrameMetric' {[Text]
Text
MetricType
type' :: MetricType
threadStates :: [Text]
frameName :: Text
$sel:type':FrameMetric' :: FrameMetric -> MetricType
$sel:threadStates:FrameMetric' :: FrameMetric -> [Text]
$sel:frameName:FrameMetric' :: FrameMetric -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
frameName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
threadStates
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` MetricType
type'

instance Prelude.NFData FrameMetric where
  rnf :: FrameMetric -> ()
rnf FrameMetric' {[Text]
Text
MetricType
type' :: MetricType
threadStates :: [Text]
frameName :: Text
$sel:type':FrameMetric' :: FrameMetric -> MetricType
$sel:threadStates:FrameMetric' :: FrameMetric -> [Text]
$sel:frameName:FrameMetric' :: FrameMetric -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
frameName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
threadStates
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf MetricType
type'

instance Data.ToJSON FrameMetric where
  toJSON :: FrameMetric -> Value
toJSON FrameMetric' {[Text]
Text
MetricType
type' :: MetricType
threadStates :: [Text]
frameName :: Text
$sel:type':FrameMetric' :: FrameMetric -> MetricType
$sel:threadStates:FrameMetric' :: FrameMetric -> [Text]
$sel:frameName:FrameMetric' :: FrameMetric -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"frameName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
frameName),
            forall a. a -> Maybe a
Prelude.Just (Key
"threadStates" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
threadStates),
            forall a. a -> Maybe a
Prelude.Just (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= MetricType
type')
          ]
      )