MCPcopy Create free account
hub / github.com/RedisGears/RedisGears / RedisGearsPy_ProfileStats

Function RedisGearsPy_ProfileStats

plugins/python/redisgears_python.c:6455–6498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6453}
6454
6455static 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
6500static int RedisGearsPy_Profile(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){
6501 if (argc < 2) {

Callers 1

RedisGearsPy_ProfileFunction · 0.85

Calls 6

PythonSessionCtx_GetFunction · 0.85
RedisGearsPy_LockFunction · 0.85
getPyErrorFunction · 0.85
RedisGearsPy_UnlockFunction · 0.85
PythonSessionCtx_FreeFunction · 0.85
GearsPyDecRefFunction · 0.85

Tested by

no test coverage detected