| 6453 | } |
| 6454 | |
| 6455 | static int RedisGearsPy_ProfileStats(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){ |
| 6456 | if (argc < 0 || argc > 2){ |
| 6457 | return RedisModule_WrongArity(ctx); |
| 6458 | } |
| 6459 | |
| 6460 | const char* strId = RedisModule_StringPtrLen(argv[0], NULL); |
| 6461 | const char* order = "tottime"; |
| 6462 | if (argc == 3) { |
| 6463 | order = RedisModule_StringPtrLen(argv[1], NULL); |
| 6464 | } |
| 6465 | |
| 6466 | PythonSessionCtx* s = PythonSessionCtx_Get(strId); |
| 6467 | if (!s) { |
| 6468 | RedisModule_ReplyWithError(ctx, "session does not exists"); |
| 6469 | return REDISMODULE_OK; |
| 6470 | } |
| 6471 | |
| 6472 | PythonExecutionCtx pectx = PythonExecutionCtx_New(s, NULL); |
| 6473 | RedisGearsPy_Lock(&pectx); |
| 6474 | |
| 6475 | PyObject* res = PyObject_CallFunction(profileGetInfoFunction, "Os", s->profiler, order); |
| 6476 | if (!res) { |
| 6477 | char* error = getPyError(); |
| 6478 | if (!error) { |
| 6479 | error = RG_STRDUP("Failed getting profile information"); |
| 6480 | } |
| 6481 | RedisModule_ReplyWithError(ctx, error); |
| 6482 | RG_FREE(error); |
| 6483 | RedisGearsPy_Unlock(&pectx); |
| 6484 | PythonSessionCtx_Free(s); |
| 6485 | return REDISMODULE_OK; |
| 6486 | } |
| 6487 | PyObject* statsPyStr = PyObject_Str(res); |
| 6488 | size_t len; |
| 6489 | const char* statsCStr = PyUnicode_AsUTF8AndSize(statsPyStr, &len); |
| 6490 | RedisModule_ReplyWithStringBuffer(ctx, statsCStr, len); |
| 6491 | GearsPyDecRef(statsPyStr); |
| 6492 | GearsPyDecRef(res); |
| 6493 | |
| 6494 | RedisGearsPy_Unlock(&pectx); |
| 6495 | PythonSessionCtx_Free(s); |
| 6496 | |
| 6497 | return REDISMODULE_OK; |
| 6498 | } |
| 6499 | |
| 6500 | static int RedisGearsPy_Profile(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){ |
| 6501 | if (argc < 2) { |
no test coverage detected