PostgreSQL Source Code: src/backend/utils/activity/wait_event.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

24

25#include "storage/lmgr.h"

29

30

37

38

41

42#define WAIT_EVENT_CLASS_MASK 0xFF000000

43#define WAIT_EVENT_ID_MASK 0x0000FFFF

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

65

66#define WAIT_EVENT_CUSTOM_HASH_INIT_SIZE 16

67#define WAIT_EVENT_CUSTOM_HASH_MAX_SIZE 128

68

69

71{

75

77{

81

82

83

85{

86 int nextId;

87 slock_t mutex;

89

90

92

93

94#define WAIT_EVENT_CUSTOM_INITIAL_ID 1

95

98

99

100

101

104{

106

112 return sz;

113}

114

115

116

117

118void

120{

121 bool found;

123

127

128 if (!found)

129 {

130

133 }

134

135

139 ShmemInitHash("WaitEventCustom hash by wait event information",

142 &info,

144

145

152 &info,

154}

155

156

157

158

159

160

161

164{

166}

167

170{

172}

173

176{

178 bool found;

181 uint32 wait_event_info;

182

183

184 if (strlen(wait_event_name) >= NAMEDATALEN)

186 "cannot use custom wait event string longer than %u characters",

188

189

190

191

192

198 if (found)

199 {

201

203 if (oldClassId != classId)

206 errmsg("wait event \"%s\" already exists in type \"%s\"",

207 wait_event_name,

210 }

211

212

213

214

215

216

217

222 if (found)

223 {

225

228 if (oldClassId != classId)

231 errmsg("wait event \"%s\" already exists in type \"%s\"",

232 wait_event_name,

235 }

236

237

239

241 {

244 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

245 errmsg("too many custom wait events"));

246 }

247

249

251

252

253 wait_event_info = classId | eventId;

260

266

268

269 return wait_event_info;

270}

271

272

273

274

275static const char *

277{

278 bool found;

280

281

283 return "Extension";

284

285

291

292 if (!entry)

294 "could not find custom name for wait event information %u",

295 wait_event_info);

296

298}

299

300

301

302

303

304

305char **

307{

308 char **waiteventnames;

312 int els;

313

315

316

318

319

320 waiteventnames = palloc(els * sizeof(char *));

321

322

324

327 {

329 continue;

332 }

333

335

336 *nwaitevents = index;

337 return waiteventnames;

338}

339

340

341

342

343

344

345

346

347

348void

350{

352}

353

354

355

356

357

358

359

360void

362{

364}

365

366

367

368

369

370

371

372const char *

374{

376 const char *event_type;

377

378

379 if (wait_event_info == 0)

380 return NULL;

381

383

384 switch (classId)

385 {

387 event_type = "LWLock";

388 break;

390 event_type = "Lock";

391 break;

393 event_type = "BufferPin";

394 break;

396 event_type = "Activity";

397 break;

399 event_type = "Client";

400 break;

402 event_type = "Extension";

403 break;

405 event_type = "IPC";

406 break;

408 event_type = "Timeout";

409 break;

411 event_type = "IO";

412 break;

414 event_type = "InjectionPoint";

415 break;

416 default:

417 event_type = "???";

418 break;

419 }

420

421 return event_type;

422}

423

424

425

426

427

428

429

430const char *

432{

435 const char *event_name;

436

437

438 if (wait_event_info == 0)

439 return NULL;

440

443

444 switch (classId)

445 {

448 break;

451 break;

455 break;

457 {

458 WaitEventBufferPin w = (WaitEventBufferPin) wait_event_info;

459

461 break;

462 }

464 {

465 WaitEventActivity w = (WaitEventActivity) wait_event_info;

466

468 break;

469 }

471 {

472 WaitEventClient w = (WaitEventClient) wait_event_info;

473

475 break;

476 }

478 {

479 WaitEventIPC w = (WaitEventIPC) wait_event_info;

480

482 break;

483 }

485 {

486 WaitEventTimeout w = (WaitEventTimeout) wait_event_info;

487

489 break;

490 }

492 {

493 WaitEventIO w = (WaitEventIO) wait_event_info;

494

496 break;

497 }

498 default:

499 event_name = "unknown wait event";

500 break;

501 }

502

503 return event_name;

504}

505

506#include "pgstat_wait_event.c"

void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)

void * hash_seq_search(HASH_SEQ_STATUS *status)

long hash_get_num_entries(HTAB *hashp)

Size hash_estimate_size(long num_entries, Size entrysize)

void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

Assert(PointerIsAligned(start, uint64))

const char * GetLockNameFromTagType(uint16 locktag_type)

bool LWLockAcquire(LWLock *lock, LWLockMode mode)

void LWLockRelease(LWLock *lock)

const char * GetLWLockIdentifier(uint32 classId, uint16 eventId)

char * pstrdup(const char *in)

size_t strlcpy(char *dst, const char *src, size_t siz)

HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)

Size add_size(Size s1, Size s2)

void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)

#define SpinLockInit(lock)

#define SpinLockRelease(lock)

#define SpinLockAcquire(lock)

#define ERRCODE_DUPLICATE_OBJECT

char wait_event_name[NAMEDATALEN]

char wait_event_name[NAMEDATALEN]

#define PG_WAIT_INJECTIONPOINT

#define PG_WAIT_BUFFERPIN

#define PG_WAIT_EXTENSION

#define WAIT_EVENT_CUSTOM_HASH_MAX_SIZE

struct WaitEventCustomEntryByName WaitEventCustomEntryByName

Size WaitEventCustomShmemSize(void)

static const char * pgstat_get_wait_timeout(WaitEventTimeout w)

char ** GetWaitEventCustomNames(uint32 classId, int *nwaitevents)

#define WAIT_EVENT_CUSTOM_HASH_INIT_SIZE

static WaitEventCustomCounterData * WaitEventCustomCounter

static const char * pgstat_get_wait_activity(WaitEventActivity w)

const char * pgstat_get_wait_event_type(uint32 wait_event_info)

static const char * pgstat_get_wait_io(WaitEventIO w)

void pgstat_set_wait_event_storage(uint32 *wait_event_info)

const char * pgstat_get_wait_event(uint32 wait_event_info)

static const char * GetWaitEventCustomIdentifier(uint32 wait_event_info)

static uint32 local_my_wait_event_info

static const char * pgstat_get_wait_bufferpin(WaitEventBufferPin w)

uint32 WaitEventInjectionPointNew(const char *wait_event_name)

static HTAB * WaitEventCustomHashByName

static const char * pgstat_get_wait_client(WaitEventClient w)

struct WaitEventCustomEntryByInfo WaitEventCustomEntryByInfo

static const char * pgstat_get_wait_ipc(WaitEventIPC w)

void pgstat_reset_wait_event_storage(void)

struct WaitEventCustomCounterData WaitEventCustomCounterData

#define WAIT_EVENT_ID_MASK

static HTAB * WaitEventCustomHashByInfo

#define WAIT_EVENT_CLASS_MASK

uint32 WaitEventExtensionNew(const char *wait_event_name)

void WaitEventCustomShmemInit(void)

static uint32 WaitEventCustomNew(uint32 classId, const char *wait_event_name)

uint32 * my_wait_event_info

#define WAIT_EVENT_CUSTOM_INITIAL_ID