Fossil SCM
New version of tmstmpvfs.c that names log files using ISO8601 names instead of hexadecimal milliseconds since 1970.
Commit
eb9f1c6d5a9089bbe35c36f16fe1779920f78134a68b311577cb2560ed8998b2
Parent
8fd8c9e6f68f40f…
1 file changed
+44
-10
+44
-10
| --- extsrc/tmstmpvfs.c | ||
| +++ extsrc/tmstmpvfs.c | ||
| @@ -19,14 +19,14 @@ | ||
| 19 | 19 | ** The VFS also tries to generate log-files with names of the form: |
| 20 | 20 | ** |
| 21 | 21 | ** $(DATABASE)-tmstmp/$(TIME)-$(PID)-$(ID) |
| 22 | 22 | ** |
| 23 | 23 | ** Log files are only generated if directory $(DATABASE)-tmstmp exists. |
| 24 | -** The name of each log file is the current unix-epoch time in millisecond, | |
| 24 | +** The name of each log file is the current ISO8601 time in milliseconds, | |
| 25 | 25 | ** the process ID, and a random 32-bit value (to disambiguate multiple |
| 26 | -** connections from the same process) separated by spaces. The log file | |
| 27 | -** contains one 16-byte record for various events, such as opening or close | |
| 26 | +** connections from the same process) separated by dashes. The log file | |
| 27 | +** contains 16-bytes records for various events, such as opening or close | |
| 28 | 28 | ** of the database or WAL file, writes to the WAL file, checkpoints, and |
| 29 | 29 | ** similar. The logfile is only generated if the connection attempts to |
| 30 | 30 | ** modify the database. There is a separate log file for each open database |
| 31 | 31 | ** connection. |
| 32 | 32 | ** |
| @@ -131,13 +131,13 @@ | ||
| 131 | 131 | ** will create a log file if a directory name $(DATABASE)-tmstmp exists. |
| 132 | 132 | ** The name of the log file is: |
| 133 | 133 | ** |
| 134 | 134 | ** $(TIME)-$(PID)-$(RANDOM) |
| 135 | 135 | ** |
| 136 | -** Where TIME is the number of milliseconds since 1970, PID is the process | |
| 137 | -** ID, and RANDOM is a 32-bit random number. All values are expressed | |
| 138 | -** in hexadecimal. | |
| 136 | +** Where TIME is an ISO 8601 date in milliseconds with no punctuation, | |
| 137 | +** PID is the process ID, and RANDOM is a 32-bit random number expressed | |
| 138 | +** as hexadecimal. | |
| 139 | 139 | ** |
| 140 | 140 | ** The log consists of 16-byte records. Each record consists of five |
| 141 | 141 | ** unsigned integers: |
| 142 | 142 | ** |
| 143 | 143 | ** 1 1 6 4 4 <--- bytes |
| @@ -759,15 +759,31 @@ | ||
| 759 | 759 | if( pDb!=0 ){ |
| 760 | 760 | p->isWal = 1; |
| 761 | 761 | p->pPartner = pDb; |
| 762 | 762 | pDb->pPartner = p; |
| 763 | 763 | }else{ |
| 764 | - sqlite3_uint64 r1; | |
| 765 | 764 | u32 r2; |
| 766 | 765 | u32 pid; |
| 767 | 766 | TmstmpLog *pLog; |
| 768 | - | |
| 767 | + sqlite3_uint64 r1; /* Milliseconds since 1970-01-01 */ | |
| 768 | + sqlite3_uint64 days; /* Days since 1970-01-01 */ | |
| 769 | + sqlite3_uint64 sod; /* Start of date specified by ms */ | |
| 770 | + sqlite3_uint64 z; /* Days since 0000-03-01 */ | |
| 771 | + sqlite3_uint64 era; /* 400-year era */ | |
| 772 | + int h; /* hour */ | |
| 773 | + int m; /* minute */ | |
| 774 | + int s; /* second */ | |
| 775 | + int f; /* millisecond */ | |
| 776 | + int Y; /* year */ | |
| 777 | + int M; /* month */ | |
| 778 | + int D; /* day */ | |
| 779 | + int y; /* year assuming March is first month */ | |
| 780 | + unsigned int doe; /* day of 400-year era */ | |
| 781 | + unsigned int yoe; /* year of 400-year era */ | |
| 782 | + unsigned int doy; /* day of year */ | |
| 783 | + unsigned int mp; /* month with March==0 */ | |
| 784 | + | |
| 769 | 785 | p->isDb = 1; |
| 770 | 786 | r1 = 0; |
| 771 | 787 | pLog = sqlite3_malloc64( sizeof(TmstmpLog) ); |
| 772 | 788 | if( pLog==0 ){ |
| 773 | 789 | return SQLITE_NOMEM; |
| @@ -774,14 +790,32 @@ | ||
| 774 | 790 | } |
| 775 | 791 | memset(pLog, 0, sizeof(pLog[0])); |
| 776 | 792 | p->pLog = pLog; |
| 777 | 793 | p->pSubVfs->xCurrentTimeInt64(p->pSubVfs, (sqlite3_int64*)&r1); |
| 778 | 794 | r1 -= 210866760000000LL; |
| 795 | + days = r1/86400000; | |
| 796 | + sod = (r1%86400000)/1000; | |
| 797 | + f = (int)(r1%1000); | |
| 798 | + | |
| 799 | + h = sod/3600; | |
| 800 | + m = (sod%3600)/60; | |
| 801 | + s = sod%60; | |
| 802 | + z = days + 719468; | |
| 803 | + era = z/147097; | |
| 804 | + doe = (unsigned)(z - era*146097); | |
| 805 | + yoe = (doe - doe/1460 + doe/36524 - doe/146096)/365; | |
| 806 | + y = (int)yoe + era*400; | |
| 807 | + doy = doe - (365*yoe + yoe/4 - yoe/100); | |
| 808 | + mp = (5*doy + 2)/153; | |
| 809 | + D = doy - (153*mp + 2)/5 + 1; | |
| 810 | + M = mp + (mp<10 ? 3 : -9); | |
| 811 | + Y = y + (M <=2); | |
| 779 | 812 | sqlite3_randomness(sizeof(r2), &r2); |
| 780 | 813 | pid = GETPID; |
| 781 | - pLog->zLogname = sqlite3_mprintf("%s-tmstmp/%llx-%08x-%08x", | |
| 782 | - zName, r1, pid, r2); | |
| 814 | + pLog->zLogname = sqlite3_mprintf( | |
| 815 | + "%s-tmstmp/%04d%02d%02dT%02d%02d%02d%03d-%08d-%08x", | |
| 816 | + zName, Y, M, D, h, m, s, f, pid, r2); | |
| 783 | 817 | } |
| 784 | 818 | tmstmpEvent(p, p->isWal ? ELOG_OPEN_WAL : ELOG_OPEN_DB, 0, GETPID, 0); |
| 785 | 819 | |
| 786 | 820 | tmstmp_open_done: |
| 787 | 821 | if( rc ) pFile->pMethods = 0; |
| 788 | 822 |
| --- extsrc/tmstmpvfs.c | |
| +++ extsrc/tmstmpvfs.c | |
| @@ -19,14 +19,14 @@ | |
| 19 | ** The VFS also tries to generate log-files with names of the form: |
| 20 | ** |
| 21 | ** $(DATABASE)-tmstmp/$(TIME)-$(PID)-$(ID) |
| 22 | ** |
| 23 | ** Log files are only generated if directory $(DATABASE)-tmstmp exists. |
| 24 | ** The name of each log file is the current unix-epoch time in millisecond, |
| 25 | ** the process ID, and a random 32-bit value (to disambiguate multiple |
| 26 | ** connections from the same process) separated by spaces. The log file |
| 27 | ** contains one 16-byte record for various events, such as opening or close |
| 28 | ** of the database or WAL file, writes to the WAL file, checkpoints, and |
| 29 | ** similar. The logfile is only generated if the connection attempts to |
| 30 | ** modify the database. There is a separate log file for each open database |
| 31 | ** connection. |
| 32 | ** |
| @@ -131,13 +131,13 @@ | |
| 131 | ** will create a log file if a directory name $(DATABASE)-tmstmp exists. |
| 132 | ** The name of the log file is: |
| 133 | ** |
| 134 | ** $(TIME)-$(PID)-$(RANDOM) |
| 135 | ** |
| 136 | ** Where TIME is the number of milliseconds since 1970, PID is the process |
| 137 | ** ID, and RANDOM is a 32-bit random number. All values are expressed |
| 138 | ** in hexadecimal. |
| 139 | ** |
| 140 | ** The log consists of 16-byte records. Each record consists of five |
| 141 | ** unsigned integers: |
| 142 | ** |
| 143 | ** 1 1 6 4 4 <--- bytes |
| @@ -759,15 +759,31 @@ | |
| 759 | if( pDb!=0 ){ |
| 760 | p->isWal = 1; |
| 761 | p->pPartner = pDb; |
| 762 | pDb->pPartner = p; |
| 763 | }else{ |
| 764 | sqlite3_uint64 r1; |
| 765 | u32 r2; |
| 766 | u32 pid; |
| 767 | TmstmpLog *pLog; |
| 768 | |
| 769 | p->isDb = 1; |
| 770 | r1 = 0; |
| 771 | pLog = sqlite3_malloc64( sizeof(TmstmpLog) ); |
| 772 | if( pLog==0 ){ |
| 773 | return SQLITE_NOMEM; |
| @@ -774,14 +790,32 @@ | |
| 774 | } |
| 775 | memset(pLog, 0, sizeof(pLog[0])); |
| 776 | p->pLog = pLog; |
| 777 | p->pSubVfs->xCurrentTimeInt64(p->pSubVfs, (sqlite3_int64*)&r1); |
| 778 | r1 -= 210866760000000LL; |
| 779 | sqlite3_randomness(sizeof(r2), &r2); |
| 780 | pid = GETPID; |
| 781 | pLog->zLogname = sqlite3_mprintf("%s-tmstmp/%llx-%08x-%08x", |
| 782 | zName, r1, pid, r2); |
| 783 | } |
| 784 | tmstmpEvent(p, p->isWal ? ELOG_OPEN_WAL : ELOG_OPEN_DB, 0, GETPID, 0); |
| 785 | |
| 786 | tmstmp_open_done: |
| 787 | if( rc ) pFile->pMethods = 0; |
| 788 |
| --- extsrc/tmstmpvfs.c | |
| +++ extsrc/tmstmpvfs.c | |
| @@ -19,14 +19,14 @@ | |
| 19 | ** The VFS also tries to generate log-files with names of the form: |
| 20 | ** |
| 21 | ** $(DATABASE)-tmstmp/$(TIME)-$(PID)-$(ID) |
| 22 | ** |
| 23 | ** Log files are only generated if directory $(DATABASE)-tmstmp exists. |
| 24 | ** The name of each log file is the current ISO8601 time in milliseconds, |
| 25 | ** the process ID, and a random 32-bit value (to disambiguate multiple |
| 26 | ** connections from the same process) separated by dashes. The log file |
| 27 | ** contains 16-bytes records for various events, such as opening or close |
| 28 | ** of the database or WAL file, writes to the WAL file, checkpoints, and |
| 29 | ** similar. The logfile is only generated if the connection attempts to |
| 30 | ** modify the database. There is a separate log file for each open database |
| 31 | ** connection. |
| 32 | ** |
| @@ -131,13 +131,13 @@ | |
| 131 | ** will create a log file if a directory name $(DATABASE)-tmstmp exists. |
| 132 | ** The name of the log file is: |
| 133 | ** |
| 134 | ** $(TIME)-$(PID)-$(RANDOM) |
| 135 | ** |
| 136 | ** Where TIME is an ISO 8601 date in milliseconds with no punctuation, |
| 137 | ** PID is the process ID, and RANDOM is a 32-bit random number expressed |
| 138 | ** as hexadecimal. |
| 139 | ** |
| 140 | ** The log consists of 16-byte records. Each record consists of five |
| 141 | ** unsigned integers: |
| 142 | ** |
| 143 | ** 1 1 6 4 4 <--- bytes |
| @@ -759,15 +759,31 @@ | |
| 759 | if( pDb!=0 ){ |
| 760 | p->isWal = 1; |
| 761 | p->pPartner = pDb; |
| 762 | pDb->pPartner = p; |
| 763 | }else{ |
| 764 | u32 r2; |
| 765 | u32 pid; |
| 766 | TmstmpLog *pLog; |
| 767 | sqlite3_uint64 r1; /* Milliseconds since 1970-01-01 */ |
| 768 | sqlite3_uint64 days; /* Days since 1970-01-01 */ |
| 769 | sqlite3_uint64 sod; /* Start of date specified by ms */ |
| 770 | sqlite3_uint64 z; /* Days since 0000-03-01 */ |
| 771 | sqlite3_uint64 era; /* 400-year era */ |
| 772 | int h; /* hour */ |
| 773 | int m; /* minute */ |
| 774 | int s; /* second */ |
| 775 | int f; /* millisecond */ |
| 776 | int Y; /* year */ |
| 777 | int M; /* month */ |
| 778 | int D; /* day */ |
| 779 | int y; /* year assuming March is first month */ |
| 780 | unsigned int doe; /* day of 400-year era */ |
| 781 | unsigned int yoe; /* year of 400-year era */ |
| 782 | unsigned int doy; /* day of year */ |
| 783 | unsigned int mp; /* month with March==0 */ |
| 784 | |
| 785 | p->isDb = 1; |
| 786 | r1 = 0; |
| 787 | pLog = sqlite3_malloc64( sizeof(TmstmpLog) ); |
| 788 | if( pLog==0 ){ |
| 789 | return SQLITE_NOMEM; |
| @@ -774,14 +790,32 @@ | |
| 790 | } |
| 791 | memset(pLog, 0, sizeof(pLog[0])); |
| 792 | p->pLog = pLog; |
| 793 | p->pSubVfs->xCurrentTimeInt64(p->pSubVfs, (sqlite3_int64*)&r1); |
| 794 | r1 -= 210866760000000LL; |
| 795 | days = r1/86400000; |
| 796 | sod = (r1%86400000)/1000; |
| 797 | f = (int)(r1%1000); |
| 798 | |
| 799 | h = sod/3600; |
| 800 | m = (sod%3600)/60; |
| 801 | s = sod%60; |
| 802 | z = days + 719468; |
| 803 | era = z/147097; |
| 804 | doe = (unsigned)(z - era*146097); |
| 805 | yoe = (doe - doe/1460 + doe/36524 - doe/146096)/365; |
| 806 | y = (int)yoe + era*400; |
| 807 | doy = doe - (365*yoe + yoe/4 - yoe/100); |
| 808 | mp = (5*doy + 2)/153; |
| 809 | D = doy - (153*mp + 2)/5 + 1; |
| 810 | M = mp + (mp<10 ? 3 : -9); |
| 811 | Y = y + (M <=2); |
| 812 | sqlite3_randomness(sizeof(r2), &r2); |
| 813 | pid = GETPID; |
| 814 | pLog->zLogname = sqlite3_mprintf( |
| 815 | "%s-tmstmp/%04d%02d%02dT%02d%02d%02d%03d-%08d-%08x", |
| 816 | zName, Y, M, D, h, m, s, f, pid, r2); |
| 817 | } |
| 818 | tmstmpEvent(p, p->isWal ? ELOG_OPEN_WAL : ELOG_OPEN_DB, 0, GETPID, 0); |
| 819 | |
| 820 | tmstmp_open_done: |
| 821 | if( rc ) pFile->pMethods = 0; |
| 822 |