{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- 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.Lens as Lens
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
(FrameMetric -> FrameMetric -> Bool)
-> (FrameMetric -> FrameMetric -> Bool) -> Eq FrameMetric
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]
(Int -> ReadS FrameMetric)
-> ReadS [FrameMetric]
-> ReadPrec FrameMetric
-> ReadPrec [FrameMetric]
-> Read 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
(Int -> FrameMetric -> ShowS)
-> (FrameMetric -> String)
-> ([FrameMetric] -> ShowS)
-> Show FrameMetric
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. FrameMetric -> Rep FrameMetric x)
-> (forall x. Rep FrameMetric x -> FrameMetric)
-> Generic FrameMetric
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' :: Text -> [Text] -> MetricType -> FrameMetric
FrameMetric'
    { $sel:frameName:FrameMetric' :: Text
frameName = Text
pFrameName_,
      $sel:threadStates:FrameMetric' :: [Text]
threadStates = [Text]
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 :: (Text -> f Text) -> FrameMetric -> f FrameMetric
frameMetric_frameName = (FrameMetric -> Text)
-> (FrameMetric -> Text -> FrameMetric)
-> Lens FrameMetric FrameMetric Text Text
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 :: ([Text] -> f [Text]) -> FrameMetric -> f FrameMetric
frameMetric_threadStates = (FrameMetric -> [Text])
-> (FrameMetric -> [Text] -> FrameMetric)
-> Lens FrameMetric FrameMetric [Text] [Text]
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) (([Text] -> f [Text]) -> FrameMetric -> f FrameMetric)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> FrameMetric
-> f FrameMetric
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
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 :: (MetricType -> f MetricType) -> FrameMetric -> f FrameMetric
frameMetric_type = (FrameMetric -> MetricType)
-> (FrameMetric -> MetricType -> FrameMetric)
-> Lens FrameMetric FrameMetric MetricType MetricType
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 Core.FromJSON FrameMetric where
  parseJSON :: Value -> Parser FrameMetric
parseJSON =
    String
-> (Object -> Parser FrameMetric) -> Value -> Parser FrameMetric
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FrameMetric"
      ( \Object
x ->
          Text -> [Text] -> MetricType -> FrameMetric
FrameMetric'
            (Text -> [Text] -> MetricType -> FrameMetric)
-> Parser Text -> Parser ([Text] -> MetricType -> FrameMetric)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"frameName")
            Parser ([Text] -> MetricType -> FrameMetric)
-> Parser [Text] -> Parser (MetricType -> FrameMetric)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"threadStates" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (MetricType -> FrameMetric)
-> Parser MetricType -> Parser FrameMetric
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser MetricType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable FrameMetric

instance Prelude.NFData FrameMetric

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"frameName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
frameName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"threadStates" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
threadStates),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> MetricType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= MetricType
type')
          ]
      )