Peak Estimation aims to find the maximum value of a state function achieved by adynamical system. This problem is non-convex when considering standard Barrier andDensity methods for invariant sets, and has been treated heuristically by using auxiliaryfunctions. A convex formulation based on occupation measures is proposed in thispaper to solve peak estimation. This method is dual to the auxiliary function approach.Our method will converge to the optimal solution and can recover trajectories even fromapproximate solutions. This framework is extended to safety analysis by maximizingthe minimum of a set of costs along trajectories.