ekm0d
ekm0d

Reputation: 71

Is it possible to run memory_profiler and line_profiler during the same execution?

I have a python program and I am trying to calculate memory usagge and run-time of it. When I run the program with kernprof -l -v I only get the output of memory_profiler. It does say that line_profiler has written the output in an external file but theres no output neither in terminal nor in the file. If I run the program separately with mprof run and then with kernprof -l -v while not importing memory profiler the output is there and I am able to view the time results. Is it possible to make them work throughout the same execution? My code:

@profile
def ARIMA_forecast(series, df):
    X = series.values
    size = int(len(X) * 0.66)
    train, test = X[0:size], X[size:len(X)]
    history = [x for x in train]
    predictions = list()
    for t in range(len(test)):
        model = ARIMA(history, order=(4, 1, 0))
        model_fit = model.fit(disp=0)
        output = model_fit.forecast()
        yhat = output[0]
        predictions.append(yhat)
        obs = test[t]
        history.append(obs)
        print('predicted=%f, expected=%f' % (yhat, obs))
    # evaluate forecasts
    rmse = sqrt(mean_squared_error(test, predictions))
    print('Test RMSE: %.3f' % rmse)
    # plot forecasts against actual outcomes
    plt.plot(series, label='Training data')
    plt.plot(series[size:len(X)].index, predictions, color='blue', label='Predicted Price')
    plt.plot(series[size:len(X)].index, test, color='red', label='Actual Price')
    plt.legend()
    plt.show()

df = pd.read_csv('MSFT.csv', header=0, index_col=0, parse_dates=True)
series = df['Adj Close']

ARIMA_forecast(series, df)

``

Upvotes: 0

Views: 904

Answers (1)

EmeryBerger
EmeryBerger

Reputation: 3966

As far as I am aware, Scalene is the only profiler that simultaneously profiles Python programs for both CPU execution time and memory (among many other things). It's also much faster than memory_profiler. Obligatory disclaimer: I am Scalene's primary author. Let me know how it goes!

Upvotes: 2

Related Questions