MCPcopy Create free account
hub / github.com/apache/cloudberry / ShowUsage

Function ShowUsage

src/backend/tcop/postgres.c:6274–6371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6272}
6273
6274void
6275ShowUsage(const char *title)
6276{
6277 StringInfoData str;
6278 struct timeval user,
6279 sys;
6280 struct timeval elapse_t;
6281 struct rusage r;
6282
6283 getrusage(RUSAGE_SELF, &r);
6284 gettimeofday(&elapse_t, NULL);
6285 memcpy((char *) &user, (char *) &r.ru_utime, sizeof(user));
6286 memcpy((char *) &sys, (char *) &r.ru_stime, sizeof(sys));
6287 if (elapse_t.tv_usec < Save_t.tv_usec)
6288 {
6289 elapse_t.tv_sec--;
6290 elapse_t.tv_usec += 1000000;
6291 }
6292 if (r.ru_utime.tv_usec < Save_r.ru_utime.tv_usec)
6293 {
6294 r.ru_utime.tv_sec--;
6295 r.ru_utime.tv_usec += 1000000;
6296 }
6297 if (r.ru_stime.tv_usec < Save_r.ru_stime.tv_usec)
6298 {
6299 r.ru_stime.tv_sec--;
6300 r.ru_stime.tv_usec += 1000000;
6301 }
6302
6303 /*
6304 * The only stats we don't show here are ixrss, idrss, isrss. It takes
6305 * some work to interpret them, and most platforms don't fill them in.
6306 */
6307 initStringInfo(&str);
6308
6309 appendStringInfoString(&str, "! system usage stats:\n");
6310 appendStringInfo(&str,
6311 "!\t%ld.%06ld s user, %ld.%06ld s system, %ld.%06ld s elapsed\n",
6312 (long) (r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec),
6313 (long) (r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec),
6314 (long) (r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec),
6315 (long) (r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec),
6316 (long) (elapse_t.tv_sec - Save_t.tv_sec),
6317 (long) (elapse_t.tv_usec - Save_t.tv_usec));
6318 appendStringInfo(&str,
6319 "!\t[%ld.%06ld s user, %ld.%06ld s system total]\n",
6320 (long) user.tv_sec,
6321 (long) user.tv_usec,
6322 (long) sys.tv_sec,
6323 (long) sys.tv_usec);
6324#if defined(HAVE_GETRUSAGE)
6325 appendStringInfo(&str,
6326 "!\t%ld kB max resident size\n",
6327#if defined(__darwin__)
6328 /* in bytes on macOS */
6329 r.ru_maxrss / 1024
6330#else
6331 /* in kilobytes on most other platforms */

Callers 15

PortalRunFunction · 0.85
PortalRunMultiFunction · 0.85
pg_parse_queryFunction · 0.85
pg_analyze_and_rewriteFunction · 0.85
pg_rewrite_queryFunction · 0.85
pg_plan_queryFunction · 0.85
exec_mpp_queryFunction · 0.85
exec_simple_queryFunction · 0.85
exec_parse_messageFunction · 0.85
exec_bind_messageFunction · 0.85
exec_execute_messageFunction · 0.85

Calls 8

getrusageFunction · 0.85
gettimeofdayFunction · 0.85
initStringInfoFunction · 0.85
appendStringInfoStringFunction · 0.85
appendStringInfoFunction · 0.85
errmsg_internalFunction · 0.50
errdetail_internalFunction · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected