We present a general framework for carrying out perturbation analysis in Stochastic Hybrid Systems (SHS) of arbitrary structure. In particular, Infinitesimal Perturbation Analysis (IPA) is used to provide unbiased gradient estimates of performance metrics with respect to various controllable parameters. These can be combined with standard gradient-based algorithms for optimization purposes and implemented on line with little or no distributional information regarding the stochastic processes involved. We generalize an earlier concept of “induced events” for this framework to include system features such as delays in control signals or modeling multiple user classes sharing a resource. We apply this generalized IPA to two SHS with different characteristics. First, we develop a gradient estimator for the performance of a linear switched system with control signal delays and a safety constraint and show that it is independent of the random delay's distributional characteristics. Second, we derive closed-form unbiased IPA estimators for a Stochastic Flow Model (SFM) of systems executing tasks subject to either hard or soft real-time constraints. These estimators are incorporated in a gradient-based algorithm to optimize performance by controlling a task admission threshold parameter. Simulation results are included to illustrate this optimization approach.