{-# 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.Metric
-- 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.Metric where

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

-- | Details about the metric that the analysis used when it detected the
-- anomaly. The metric what is analyzed to create recommendations. It
-- includes the name of the frame that was analyzed and the type and thread
-- states used to derive the metric value for that frame.
--
-- /See:/ 'newMetric' smart constructor.
data Metric = Metric'
  { -- | The name of the method that appears as a frame in any stack in a
    -- profile.
    Metric -> Text
frameName :: Prelude.Text,
    -- | The list of application runtime thread states that is used to calculate
    -- the metric value for the frame.
    Metric -> [Text]
threadStates :: [Prelude.Text],
    -- | A type 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 occurences of
    -- all frames in a profile.
    Metric -> MetricType
type' :: MetricType
  }
  deriving (Metric -> Metric -> Bool
(Metric -> Metric -> Bool)
-> (Metric -> Metric -> Bool) -> Eq Metric
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Metric -> Metric -> Bool
$c/= :: Metric -> Metric -> Bool
== :: Metric -> Metric -> Bool
$c== :: Metric -> Metric -> Bool
Prelude.Eq, ReadPrec [Metric]
ReadPrec Metric
Int -> ReadS Metric
ReadS [Metric]
(Int -> ReadS Metric)
-> ReadS [Metric]
-> ReadPrec Metric
-> ReadPrec [Metric]
-> Read Metric
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Metric]
$creadListPrec :: ReadPrec [Metric]
readPrec :: ReadPrec Metric
$creadPrec :: ReadPrec Metric
readList :: ReadS [Metric]
$creadList :: ReadS [Metric]
readsPrec :: Int -> ReadS Metric
$creadsPrec :: Int -> ReadS Metric
Prelude.Read, Int -> Metric -> ShowS
[Metric] -> ShowS
Metric -> String
(Int -> Metric -> ShowS)
-> (Metric -> String) -> ([Metric] -> ShowS) -> Show Metric
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Metric] -> ShowS
$cshowList :: [Metric] -> ShowS
show :: Metric -> String
$cshow :: Metric -> String
showsPrec :: Int -> Metric -> ShowS
$cshowsPrec :: Int -> Metric -> ShowS
Prelude.Show, (forall x. Metric -> Rep Metric x)
-> (forall x. Rep Metric x -> Metric) -> Generic Metric
forall x. Rep Metric x -> Metric
forall x. Metric -> Rep Metric x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Metric x -> Metric
$cfrom :: forall x. Metric -> Rep Metric x
Prelude.Generic)

-- |
-- Create a value of 'Metric' 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', 'metric_frameName' - The name of the method that appears as a frame in any stack in a
-- profile.
--
-- 'threadStates', 'metric_threadStates' - The list of application runtime thread states that is used to calculate
-- the metric value for the frame.
--
-- 'type'', 'metric_type' - A type 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 occurences of
-- all frames in a profile.
newMetric ::
  -- | 'frameName'
  Prelude.Text ->
  -- | 'type''
  MetricType ->
  Metric
newMetric :: Text -> MetricType -> Metric
newMetric Text
pFrameName_ MetricType
pType_ =
  Metric' :: Text -> [Text] -> MetricType -> Metric
Metric'
    { $sel:frameName:Metric' :: Text
frameName = Text
pFrameName_,
      $sel:threadStates:Metric' :: [Text]
threadStates = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:type':Metric' :: MetricType
type' = MetricType
pType_
    }

-- | The name of the method that appears as a frame in any stack in a
-- profile.
metric_frameName :: Lens.Lens' Metric Prelude.Text
metric_frameName :: (Text -> f Text) -> Metric -> f Metric
metric_frameName = (Metric -> Text)
-> (Metric -> Text -> Metric) -> Lens Metric Metric Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {Text
frameName :: Text
$sel:frameName:Metric' :: Metric -> Text
frameName} -> Text
frameName) (\s :: Metric
s@Metric' {} Text
a -> Metric
s {$sel:frameName:Metric' :: Text
frameName = Text
a} :: Metric)

-- | The list of application runtime thread states that is used to calculate
-- the metric value for the frame.
metric_threadStates :: Lens.Lens' Metric [Prelude.Text]
metric_threadStates :: ([Text] -> f [Text]) -> Metric -> f Metric
metric_threadStates = (Metric -> [Text])
-> (Metric -> [Text] -> Metric) -> Lens Metric Metric [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {[Text]
threadStates :: [Text]
$sel:threadStates:Metric' :: Metric -> [Text]
threadStates} -> [Text]
threadStates) (\s :: Metric
s@Metric' {} [Text]
a -> Metric
s {$sel:threadStates:Metric' :: [Text]
threadStates = [Text]
a} :: Metric) (([Text] -> f [Text]) -> Metric -> f Metric)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> Metric
-> f Metric
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 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 occurences of
-- all frames in a profile.
metric_type :: Lens.Lens' Metric MetricType
metric_type :: (MetricType -> f MetricType) -> Metric -> f Metric
metric_type = (Metric -> MetricType)
-> (Metric -> MetricType -> Metric)
-> Lens Metric Metric MetricType MetricType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {MetricType
type' :: MetricType
$sel:type':Metric' :: Metric -> MetricType
type'} -> MetricType
type') (\s :: Metric
s@Metric' {} MetricType
a -> Metric
s {$sel:type':Metric' :: MetricType
type' = MetricType
a} :: Metric)

instance Core.FromJSON Metric where
  parseJSON :: Value -> Parser Metric
parseJSON =
    String -> (Object -> Parser Metric) -> Value -> Parser Metric
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Metric"
      ( \Object
x ->
          Text -> [Text] -> MetricType -> Metric
Metric'
            (Text -> [Text] -> MetricType -> Metric)
-> Parser Text -> Parser ([Text] -> MetricType -> Metric)
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 -> Metric)
-> Parser [Text] -> Parser (MetricType -> Metric)
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 -> Metric) -> Parser MetricType -> Parser Metric
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 Metric

instance Prelude.NFData Metric