Reuse -m for memory compression mode 38/280038/2
authorMichal Bloch <m.bloch@samsung.com>
Mon, 22 Aug 2022 10:56:14 +0000 (12:56 +0200)
committerMichal Bloch <m.bloch@partner.samsung.com>
Wed, 24 Aug 2022 16:08:24 +0000 (16:08 +0000)
Previously known as --compress.
Monitor mode is now done via --monitor.

Change-Id: If88daa7da4e9a222c8c674beb4f79c03c5a3bff0
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/libdlogutil/fdi_pipe.c
src/logutil/logutil.c
src/logutil/logutil_doc.h
src/shared/util_parser.c
src/tests/fdi_pipe_neg.c
src/tests/fdi_pipe_pos.c
tests/dlog_test.in

index c18efb5..b002e96 100644 (file)
@@ -151,11 +151,11 @@ static int send_logger_request(struct log_filter *filters, int dump, bool monito
        assert(sock_fd >= 0);
        assert(!dump || !monitor);
 
-       static const char compress_opt_str[] = " --compress ";
+       static const char compress_opt_str[] = " -m ";
        size_t request_string_len = get_filter_size(filters) +
                (compress ? (strlen(compress) + sizeof compress_opt_str - 1) : 0) +
-               (dump ? 3 : 0) + // " -d"
-               (monitor ? 3 : 0); // " -m"
+               (dump ? (sizeof " -d" - 1) : 0) +
+               (monitor ? (sizeof " --monitor" - 1) : 0);
 
        if (MAX_LOGGER_REQUEST_LEN <= request_string_len)
                return -E2BIG;
@@ -173,7 +173,7 @@ static int send_logger_request(struct log_filter *filters, int dump, bool monito
                strncat(request_string, dump_str, request_string_len - len);
                len += sizeof dump_str - 1;
        } else if (monitor) {
-               static const char monitor_str[] = " -m";
+               static const char monitor_str[] = " --monitor";
                strncat(request_string, monitor_str, request_string_len - len);
                len += sizeof monitor_str - 1;
        }
index c4d87c5..bbfddbd 100644 (file)
@@ -313,7 +313,7 @@ int main(int argc, char **argv)
 
        if (pr.compression != NULL && pr.enabled_buffers != 0) {
                /* This is dlogutil-specific; in daemon we actually use the -b value. */
-               ERR("Error: -b and --compression can not be used together\n");
+               ERR("Error: -b and -m can not be used together\n");
                return EXIT_FAILURE;
        }
 
@@ -385,7 +385,7 @@ int main(int argc, char **argv)
         * backend would usually have. RECV_REAL should be universal. */
        if (pr.compression) {
                if (pr.action != ACTION_PRINT) {
-                       ERR("--compress and -g/-c currently unsupported\n");
+                       ERR("-m and -g/-c currently unsupported\n");
                        return EXIT_FAILURE;
                }
 
index b3d4d5d..1b6c3e1 100644 (file)
@@ -43,12 +43,13 @@ static void show_help(const char *cmd, bool requested_by_user)
                "  -s                Set default filter to silent.\n"
                "                    Like specifying filterspec '*:s'\n"
                "  -f <filename>     Log to file. Default to stdout\n"
+               "  -m <memory area>  Log to named memory area\n"
                "  -r [<kbytes>]     Rotate log every kB (defaults to: " STRINGIFY(DEFAULT_ROTATE_SIZE_KB) "kB). Requires -f and -n > 0, else no rotation\n"
                "  -n <count>        Sets max number of rotated logs to <count> (defaults to: " STRINGIFY(DEFAULT_ROTATE_NUM_FILES) "). Requires -f and -r > 0, else no rotation\n"
                "  -c                clear (flush) the entire log and exit without printing logs\n"
-               "  -d                dump the log and then exit (don't block unless also -m)\n"
-               "  -m                only monitor the log (don't dump existing logs unless also -d)\n"
-               "  -t <count>        print only the most recent <count> lines (implies -d but doesn't work with -m)\n"
+               "  -d                dump the log and then exit (don't block unless also --monitor)\n"
+               "  -t <count>        print only the most recent <count> lines (implies -d but doesn't work with --monitor)\n"
+               "  --monitor         only monitor the log (don't dump existing logs unless also -d)\n"
                "  -g                get the size of the log's ring buffer and exit\n"
                "  -b <buffer>       request alternate ring buffers (can use multiple)\n"
                "                    ('main', 'radio', 'system', 'apps', 'kmsg', 'syslog')\n"
index b34c8f5..e87fe1c 100644 (file)
@@ -46,11 +46,11 @@ struct parse_result parse_options(int argc, char **argv)
                        {"version" ,       no_argument, NULL,   2},
                        {"color"   , required_argument, NULL,   3},
                        {"sort-by" , required_argument, NULL,   4},
-                       {"compress", required_argument, NULL,   5},
+                       {"monitor" ,       no_argument, NULL,   5},
                        {"help"    ,       no_argument, NULL, 'h'},
                        {0}
                };
-               int option = getopt_long(argc, argv, "cdmt:gsf:r:n:v:b:u:e:h", long_options, NULL);
+               int option = getopt_long(argc, argv, "cdm:t:gsf:r:n:v:b:u:e:h", long_options, NULL);
 
                if (option < 0)
                        break;
@@ -112,14 +112,14 @@ struct parse_result parse_options(int argc, char **argv)
                        }
                        break;
                case 5: /* memory compression */
-                       mode = DLOGUTIL_MODE_COMPRESSED_MEMORY_DUMP;
-                       compression = optarg;
+                       mode = DLOGUTIL_MODE_MONITOR;
                        break;
                case 'd':
                        mode = DLOGUTIL_MODE_DUMP;
                        break;
                case 'm':
-                       mode = DLOGUTIL_MODE_MONITOR;
+                       mode = DLOGUTIL_MODE_COMPRESSED_MEMORY_DUMP;
+                       compression = optarg;
                        break;
                case 't':
                        mode = DLOGUTIL_MODE_DUMP;
index 624dff7..8d7422a 100644 (file)
@@ -68,7 +68,7 @@ int main(void)
        assert(ops_pipe.prepare_print(&info, false, false, filter, NULL) == -1);
 
        correct_request = DLOG_REQ_HANDLE_COMPRESSED_LOGUTIL;
-       correct_send_data = "dlogutil -d --compress membackup --pid 456 --tid 123 filter1:V filter0:V *:S";
+       correct_send_data = "dlogutil -d -m membackup --pid 456 --tid 123 filter1:V filter0:V *:S";
        correct_send_datalen = strlen(correct_send_data) + 1;
        assert(ops_pipe.prepare_print(&info, false, false, filter, (char *) "membackup") == -1);
 
index cc42dba..6f7d7f7 100644 (file)
@@ -148,7 +148,7 @@ int main(void)
        assert(info.fd == 2);
 
        correct_request = DLOG_REQ_HANDLE_COMPRESSED_LOGUTIL;
-       correct_send_data = "dlogutil -d --compress membackup --pid 456 --tid 123 filter1:V filter0:V *:S";
+       correct_send_data = "dlogutil -d -m membackup --pid 456 --tid 123 filter1:V filter0:V *:S";
        correct_send_datalen = strlen(correct_send_data) + 1;
        assert(ops_pipe.prepare_print(&info, false, false, filter, (char *) "membackup") == 0);
        assert(info.fd == 3);
index 146d38f..317cc9e 100644 (file)
@@ -462,7 +462,7 @@ if [ "$quick" -ne 1 ]; then
        [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_continuous2_file)" -eq 11 ] && ok || fail
 
        LOG_DETAILS="testing if the monitor mode works as expected (1/2)"
-       dlogutil -mb main -f $TESTDIR/dlog_monitor1_file &
+       dlogutil --monitor -b main -f $TESTDIR/dlog_monitor1_file &
        UTIL_PID=$!
        sleep 1
        kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
@@ -470,7 +470,7 @@ if [ "$quick" -ne 1 ]; then
        [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor1_file)" -eq 0 ] && ok || fail
 
        LOG_DETAILS="testing if the monitor mode works as expected (2/2)"
-       dlogutil -mb main -f $TESTDIR/dlog_monitor2_file &
+       dlogutil --monitor -b main -f $TESTDIR/dlog_monitor2_file &
        UTIL_PID=$!
        sleep 1
        dlogsend -b main "Hi!"