本文整理汇总了C++中pgstat_fetch_stat_beentry函数的典型用法代码示例。如果您正苦于以下问题:C++ pgstat_fetch_stat_beentry函数的具体用法?C++ pgstat_fetch_stat_beentry怎么用?C++ pgstat_fetch_stat_beentry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pgstat_fetch_stat_beentry函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pg_stat_get_backend_activity_start
Datum
pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
{
PgStat_StatBeEntry *beentry;
int32 beid;
AbsoluteTime sec;
int usec;
TimestampTz result;
beid = PG_GETARG_INT32(0);
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
if (!superuser() && beentry->userid != GetUserId())
PG_RETURN_NULL();
sec = beentry->activity_start_sec;
usec = beentry->activity_start_usec;
/*
* No time recorded for start of current query -- this is the case if
* the user hasn't enabled query-level stats collection.
*/
if (sec == 0 && usec == 0)
PG_RETURN_NULL();
result = AbsoluteTimeUsecToTimestampTz(sec, usec);
PG_RETURN_TIMESTAMPTZ(result);
}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:31,代码来源:pgstatfuncs.c
示例2: pg_stat_get_backend_activity
Datum
pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
text *result;
PgBackendStatus *beentry;
int len;
const char *activity;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
activity = "<backend information not available>";
else if (!superuser() && beentry->st_userid != GetUserId())
activity = "<insufficient privilege>";
else if (*(beentry->st_activity) == '\0')
activity = "<command string not enabled>";
else
activity = beentry->st_activity;
len = strlen(activity);
result = palloc(VARHDRSZ + len);
VARATT_SIZEP(result) = VARHDRSZ + len;
memcpy(VARDATA(result), activity, len);
PG_RETURN_TEXT_P(result);
}
开发者ID:rtzassociates,项目名称:postgresql-8.2.23,代码行数:25,代码来源:pgstatfuncs.c
示例3: pg_stat_get_backend_userid
Datum
pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
PG_RETURN_OID(beentry->st_userid);
}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:11,代码来源:pgstatfuncs.c
示例4: pg_stat_get_backend_userid
Datum
pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
{
PgStat_StatBeEntry *beentry;
int32 beid;
beid = PG_GETARG_INT32(0);
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
PG_RETURN_INT32(beentry->userid);
}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:13,代码来源:pgstatfuncs.c
示例5: pg_stat_get_backend_client_port
Datum
pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
SockAddr zero_clientaddr;
char remote_port[NI_MAXSERV];
int ret;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
if (!superuser() && beentry->st_userid != GetUserId())
PG_RETURN_NULL();
/* A zeroed client addr means we don't know */
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr) == 0))
PG_RETURN_NULL();
switch (beentry->st_clientaddr.addr.ss_family)
{
case AF_INET:
#ifdef HAVE_IPV6
case AF_INET6:
#endif
break;
case AF_UNIX:
PG_RETURN_INT32(-1);
default:
PG_RETURN_NULL();
}
remote_port[0] = '\0';
ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
beentry->st_clientaddr.salen,
NULL, 0,
remote_port, sizeof(remote_port),
NI_NUMERICHOST | NI_NUMERICSERV);
if (ret)
PG_RETURN_NULL();
PG_RETURN_DATUM(DirectFunctionCall1(int4in,
CStringGetDatum(remote_port)));
}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:46,代码来源:pgstatfuncs.c
示例6: pg_stat_get_backend_client_addr
Datum
pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
SockAddr zero_clientaddr;
char remote_host[NI_MAXHOST];
int ret;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
if (!has_privs_of_role(GetUserId(), beentry->st_userid))
PG_RETURN_NULL();
/* A zeroed client addr means we don't know */
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr)) == 0)
PG_RETURN_NULL();
switch (beentry->st_clientaddr.addr.ss_family)
{
case AF_INET:
#ifdef HAVE_IPV6
case AF_INET6:
#endif
break;
default:
PG_RETURN_NULL();
}
remote_host[0] = '\0';
ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
beentry->st_clientaddr.salen,
remote_host, sizeof(remote_host),
NULL, 0,
NI_NUMERICHOST | NI_NUMERICSERV);
if (ret != 0)
PG_RETURN_NULL();
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
PG_RETURN_INET_P(DirectFunctionCall1(inet_in,
CStringGetDatum(remote_host)));
}
开发者ID:EccentricLoggers,项目名称:peloton,代码行数:46,代码来源:pgstatfuncs.cpp
示例7: pg_stat_get_backend_waiting
Datum
pg_stat_get_backend_waiting(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
bool result;
PgBackendStatus *beentry;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
if (!superuser() && beentry->st_userid != GetUserId())
PG_RETURN_NULL();
result = beentry->st_waiting;
PG_RETURN_BOOL(result);
}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:17,代码来源:pgstatfuncs.c
示例8: pg_stat_get_backend_activity
Datum
pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
const char *activity;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
activity = "<backend information not available>";
else if (!superuser() && beentry->st_userid != GetUserId())
activity = "<insufficient privilege>";
else if (*(beentry->st_activity) == '\0')
activity = "<command string not enabled>";
else
activity = beentry->st_activity;
PG_RETURN_TEXT_P(cstring_to_text(activity));
}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:18,代码来源:pgstatfuncs.c
示例9: pg_stat_get_db_numbackends
Datum
pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int32 result;
int tot_backends = pgstat_fetch_stat_numbackends();
int beid;
result = 0;
for (beid = 1; beid <= tot_backends; beid++)
{
PgBackendStatus *beentry = pgstat_fetch_stat_beentry(beid);
if (beentry && beentry->st_databaseid == dbid)
result++;
}
PG_RETURN_INT32(result);
}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:19,代码来源:pgstatfuncs.c
示例10: pg_stat_get_backend_start
Datum
pg_stat_get_backend_start(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
TimestampTz result;
PgBackendStatus *beentry;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
if (!superuser() && beentry->st_userid != GetUserId())
PG_RETURN_NULL();
result = beentry->st_proc_start_timestamp;
if (result == 0) /* probably can't happen? */
PG_RETURN_NULL();
PG_RETURN_TIMESTAMPTZ(result);
}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:20,代码来源:pgstatfuncs.c
示例11: pg_stat_get_backend_xact_start
Datum
pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
TimestampTz result;
PgBackendStatus *beentry;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
if (!has_privs_of_role(GetUserId(), beentry->st_userid))
PG_RETURN_NULL();
result = beentry->st_xact_start_timestamp;
if (result == 0) /* not in a transaction */
PG_RETURN_NULL();
PG_RETURN_TIMESTAMPTZ(result);
}
开发者ID:EccentricLoggers,项目名称:peloton,代码行数:20,代码来源:pgstatfuncs.cpp
示例12: pg_stat_get_backend_waiting_reason
Datum
pg_stat_get_backend_waiting_reason(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
char *result;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
if (!superuser() && beentry->st_userid != GetUserId())
PG_RETURN_NULL();
result = pgstat_waiting_string(beentry->st_waiting);
/* waiting for nothing */
if (result == NULL)
PG_RETURN_NULL();
PG_RETURN_DATUM(CStringGetTextDatum(result));
}
开发者ID:50wu,项目名称:gpdb,代码行数:21,代码来源:pgstatfuncs.c
示例13: pg_stat_get_backend_wait_event_type
Datum
pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
PGPROC *proc;
const char *wait_event_type;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
wait_event_type = "<backend information not available>";
else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
wait_event_type = "<insufficient privilege>";
else
{
proc = BackendPidGetProc(beentry->st_procpid);
wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
}
if (!wait_event_type)
PG_RETURN_NULL();
PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
}
开发者ID:BenjaminYu,项目名称:postgres,代码行数:23,代码来源:pgstatfuncs.c
示例14: pg_stat_get_backend_activity
Datum
pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
{
PgStat_StatBeEntry *beentry;
int32 beid;
int len;
text *result;
beid = PG_GETARG_INT32(0);
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
if (!superuser() && beentry->userid != GetUserId())
PG_RETURN_NULL();
len = strlen(beentry->activity);
result = palloc(VARHDRSZ + len);
VARATT_SIZEP(result) = VARHDRSZ + len;
memcpy(VARDATA(result), beentry->activity, len);
PG_RETURN_TEXT_P(result);
}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:23,代码来源:pgstatfuncs.c
示例15: pg_stat_get_backend_activity_start
Datum
pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
TimestampTz result;
PgBackendStatus *beentry;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
PG_RETURN_NULL();
if (!superuser() && beentry->st_userid != GetUserId())
PG_RETURN_NULL();
result = beentry->st_activity_start_timestamp;
/*
* No time recorded for start of current query -- this is the case if the
* user hasn't enabled query-level stats collection.
*/
if (result == 0)
PG_RETURN_NULL();
PG_RETURN_TIMESTAMPTZ(result);
}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:24,代码来源:pgstatfuncs.c
示例16: pg_stat_get_activity
Datum
pg_stat_get_activity(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
if (SRF_IS_FIRSTCALL())
{
MemoryContext oldcontext;
TupleDesc tupdesc;
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
tupdesc = CreateTemplateTupleDesc(13, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "datid", OIDOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "procpid", INT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "usesysid", OIDOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "application_name", TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "current_query", TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 6, "waiting", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "act_start", TIMESTAMPTZOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "query_start", TIMESTAMPTZOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "backend_start", TIMESTAMPTZOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "client_addr", INETOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 11, "client_port", INT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 12, "sess_id", INT4OID, -1, 0); /* GPDB */
TupleDescInitEntry(tupdesc, (AttrNumber) 13, "waiting_resource", BOOLOID, -1, 0);
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
funcctx->user_fctx = palloc0(sizeof(int));
if (PG_ARGISNULL(0))
{
/* Get all backends */
funcctx->max_calls = pgstat_fetch_stat_numbackends();
}
else
{
/*
* Get one backend - locate by pid.
*
* We lookup the backend early, so we can return zero rows if it
* doesn't exist, instead of returning a single row full of NULLs.
*/
int pid = PG_GETARG_INT32(0);
int i;
int n = pgstat_fetch_stat_numbackends();
for (i = 1; i <= n; i++)
{
PgBackendStatus *be = pgstat_fetch_stat_beentry(i);
if (be)
{
if (be->st_procpid == pid)
{
*(int *) (funcctx->user_fctx) = i;
break;
}
}
}
if (*(int *) (funcctx->user_fctx) == 0)
/* Pid not found, return zero rows */
funcctx->max_calls = 0;
else
funcctx->max_calls = 1;
}
MemoryContextSwitchTo(oldcontext);
}
/* stuff done on every call of the function */
funcctx = SRF_PERCALL_SETUP();
if (funcctx->call_cntr < funcctx->max_calls)
{
/* for each row */
Datum values[13];
bool nulls[13];
HeapTuple tuple;
PgBackendStatus *beentry;
SockAddr zero_clientaddr;
MemSet(values, 0, sizeof(values));
MemSet(nulls, 0, sizeof(nulls));
if (*(int *) (funcctx->user_fctx) > 0)
{
/* Get specific pid slot */
beentry = pgstat_fetch_stat_beentry(*(int *) (funcctx->user_fctx));
}
else
{
/* Get the next one in the list */
beentry = pgstat_fetch_stat_beentry(funcctx->call_cntr + 1); /* 1-based index */
}
if (!beentry)
{
//.........这里部分代码省略.........
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:101,代码来源:pgstatfuncs.c
示例17: pg_stat_get_activity
/*
* Returns activity of PG backends.
*/
Datum
pg_stat_get_activity(PG_FUNCTION_ARGS)
{
#define PG_STAT_GET_ACTIVITY_COLS 22
int num_backends = pgstat_fetch_stat_numbackends();
int curr_backend;
int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
TupleDesc tupdesc;
Tuplestorestate *tupstore;
MemoryContext per_query_ctx;
MemoryContext oldcontext;
/* check to see if caller supports us returning a tuplestore */
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("set-valued function called in context that cannot accept a set")));
if (!(rsinfo->allowedModes & SFRM_Materialize))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("materialize mode required, but it is not " \
"allowed in this context")));
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
oldcontext = MemoryContextSwitchTo(per_query_ctx);
tupstore = tuplestore_begin_heap(true, false, work_mem);
rsinfo->returnMode = SFRM_Materialize;
rsinfo->setResult = tupstore;
rsinfo->setDesc = tupdesc;
MemoryContextSwitchTo(oldcontext);
/* 1-based index */
for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
{
/* for each row */
Datum values[PG_STAT_GET_ACTIVITY_COLS];
bool nulls[PG_STAT_GET_ACTIVITY_COLS];
LocalPgBackendStatus *local_beentry;
PgBackendStatus *beentry;
MemSet(values, 0, sizeof(values));
MemSet(nulls, 0, sizeof(nulls));
if (pid != -1)
{
/* Skip any which are not the one we're looking for. */
PgBackendStatus *be = pgstat_fetch_stat_beentry(curr_backend);
if (!be || be->st_procpid != pid)
continue;
}
/* Get the next one in the list */
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
if (!local_beentry)
continue;
beentry = &local_beentry->backendStatus;
if (!beentry)
{
int i;
for (i = 0; i < sizeof(nulls) / sizeof(nulls[0]); i++)
nulls[i] = true;
nulls[5] = false;
values[5] = CStringGetTextDatum("<backend information not available>");
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
continue;
}
/* Values available to all callers */
values[0] = ObjectIdGetDatum(beentry->st_databaseid);
values[1] = Int32GetDatum(beentry->st_procpid);
values[2] = ObjectIdGetDatum(beentry->st_userid);
if (beentry->st_appname)
values[3] = CStringGetTextDatum(beentry->st_appname);
else
nulls[3] = true;
if (TransactionIdIsValid(local_beentry->backend_xid))
values[14] = TransactionIdGetDatum(local_beentry->backend_xid);
else
nulls[14] = true;
if (TransactionIdIsValid(local_beentry->backend_xmin))
values[15] = TransactionIdGetDatum(local_beentry->backend_xmin);
else
//.........这里部分代码省略.........
开发者ID:EccentricLoggers,项目名称:peloton,代码行数:101,代码来源:pgstatfuncs.cpp
注:本文中的pgstat_fetch_stat_beentry函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论