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

Function evaluateSleep

src/bin/pgbench/pgbench.c:3094–3133  ·  view source on GitHub ↗

* Parse the argument to a \sleep command, and return the requested amount * of delay, in microseconds. Returns true on success, false on error. */

Source from the content-addressed store, hash-verified

3092 * of delay, in microseconds. Returns true on success, false on error.
3093 */
3094static bool
3095evaluateSleep(CState *st, int argc, char **argv, int *usecs)
3096{
3097 char *var;
3098 int usec;
3099
3100 if (*argv[1] == ':')
3101 {
3102 if ((var = getVariable(st, argv[1] + 1)) == NULL)
3103 {
3104 pg_log_error("%s: undefined variable \"%s\"", argv[0], argv[1] + 1);
3105 return false;
3106 }
3107
3108 usec = atoi(var);
3109
3110 /* Raise an error if the value of a variable is not a number */
3111 if (usec == 0 && !isdigit((unsigned char) *var))
3112 {
3113 pg_log_error("%s: invalid sleep time \"%s\" for variable \"%s\"",
3114 argv[0], var, argv[1] + 1);
3115 return false;
3116 }
3117 }
3118 else
3119 usec = atoi(argv[1]);
3120
3121 if (argc > 2)
3122 {
3123 if (pg_strcasecmp(argv[2], "ms") == 0)
3124 usec *= 1000;
3125 else if (pg_strcasecmp(argv[2], "s") == 0)
3126 usec *= 1000000;
3127 }
3128 else
3129 usec *= 1000000;
3130
3131 *usecs = usec;
3132 return true;
3133}
3134
3135/*
3136 * Advance the state machine of a connection.

Callers 1

executeMetaCommandFunction · 0.85

Calls 2

getVariableFunction · 0.85
pg_strcasecmpFunction · 0.85

Tested by

no test coverage detected